BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
8aa1055f
Commit
8aa1055f
authored
Feb 09, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use threads directly, introduce pool later:
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8987#note_22938402
parent
1d8db665
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
53 deletions
+33
-53
20170206040400_remove_inactive_default_email_services.rb
.../20170206040400_remove_inactive_default_email_services.rb
+33
-5
threaded_connection_pool.rb
lib/gitlab/database/threaded_connection_pool.rb
+0
-48
No files found.
db/post_migrate/20170206040400_remove_inactive_default_email_services.rb
View file @
8aa1055f
...
...
@@ -6,24 +6,52 @@ class RemoveInactiveDefaultEmailServices < ActiveRecord::Migration
disable_ddl_transaction!
def
up
Gitlab
::
Database
::
ThreadedConnectionPool
.
with_pool
(
2
)
do
|
pool
|
pool
.
execute_async
<<-
SQL
.
strip_heredoc
pool
=
create_connection_pool
threads
=
[]
threads
<<
Thread
.
new
do
pool
.
with_connection
do
|
connection
|
connection
.
execute
<<-
SQL
.
strip_heredoc
DELETE FROM services
WHERE type = 'BuildsEmailService'
AND active IS FALSE
AND properties = '{"notify_only_broken_builds":true}';
SQL
SQL
end
end
pool
.
execute_async
<<-
SQL
.
strip_heredoc
threads
<<
Thread
.
new
do
pool
.
with_connection
do
|
connection
|
connection
.
execute
<<-
SQL
.
strip_heredoc
DELETE FROM services
WHERE type = 'PipelinesEmailService'
AND active IS FALSE
AND properties = '{"notify_only_broken_pipelines":true}';
SQL
SQL
end
end
threads
.
each
(
&
:join
)
end
def
down
# Nothing can be done to restore the records
end
private
def
create_connection_pool
# See activerecord-4.2.7.1/lib/active_record/connection_adapters/connection_specification.rb
env
=
Rails
.
env
original_config
=
ActiveRecord
::
Base
.
configurations
env_config
=
original_config
[
env
].
merge
(
'pool'
=>
2
)
config
=
original_config
.
merge
(
env
=>
env_config
)
spec
=
ActiveRecord
::
ConnectionAdapters
::
ConnectionSpecification
::
Resolver
.
new
(
config
).
spec
(
env
.
to_sym
)
ActiveRecord
::
ConnectionAdapters
::
ConnectionPool
.
new
(
spec
)
end
end
lib/gitlab/database/threaded_connection_pool.rb
deleted
100644 → 0
View file @
1d8db665
module
Gitlab
module
Database
class
ThreadedConnectionPool
def
self
.
with_pool
(
pool_size
)
pool
=
new
(
pool_size
)
yield
(
pool
)
ensure
pool
.
join
pool
.
close
end
def
initialize
(
pool_size
)
config
=
ActiveRecord
::
Base
.
configurations
[
Rails
.
env
]
@ar_pool
=
ActiveRecord
::
Base
.
establish_connection
(
config
.
merge
(
pool:
pool_size
))
@workers
=
[]
@mutex
=
Mutex
.
new
end
def
execute_async
(
sql
)
@mutex
.
synchronize
do
@workers
<<
Thread
.
new
do
@ar_pool
.
with_connection
do
|
connection
|
connection
.
execute
(
sql
)
end
end
end
end
def
join
threads
=
nil
@mutex
.
synchronize
do
threads
=
@workers
.
dup
@workers
.
clear
end
threads
.
each
(
&
:join
)
end
def
close
@ar_pool
.
disconnect!
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment