makara 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4637805d2e14a9aca08195048ebdd3f60ea0b570
4
- data.tar.gz: 2d58a5e448c5044b90f7342ace6866ecde686ea2
2
+ SHA256:
3
+ metadata.gz: 0dae82f5608272a2e365b3f75561d7e0359a646101a54d769d854eb1437c49ef
4
+ data.tar.gz: b9de62fb9f9ef35029c71b32038ca21c05dd3922a4a6b1ed5ff86578fe5e30ef
5
5
  SHA512:
6
- metadata.gz: 8c8238ca31368212caf4ee4fec672e6451a2a3f35303b4e5278af439534ce792676ee257be9edd8934a0adf2744404814aaa0654cc32448d135cd231d64eb2ad
7
- data.tar.gz: c136a5a1a27b3df093c243412120df9ed4818d9a8b31606dc330f9acd23d5f9a11fe1faf443ca32f43e7a029849face4c853e1fe379190b0efb660bbcad42ea3
6
+ metadata.gz: ba51b69a62b36132cdc4654e2207e2b46c0414386111bd3c9a31d8d7ce9960d51cd662f59b6c4fc2194b677c658c7aaff3d85930a3dbbc4cfe289c261d31311d
7
+ data.tar.gz: c0532643db2b517ce248dcead76a01092b9647350671c8794f6b2c19f257fce681579b278ab2c318735a9a6b7f84ebc9aa59ba897a36641645ebd631f1471868
@@ -0,0 +1,36 @@
1
+ name: Publish Public Gem
2
+
3
+ on:
4
+ release:
5
+ types:
6
+ - published
7
+
8
+ jobs:
9
+ build:
10
+ name: Build + Publish
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: actions/setup-ruby@v1
16
+ - name: Build
17
+ run: |
18
+ gem build *.gemspec
19
+
20
+ - name: Publish to Github
21
+ run: |
22
+ mkdir -p $HOME/.gem
23
+ touch $HOME/.gem/credentials
24
+ chmod 0600 $HOME/.gem/credentials
25
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
26
+ gem push --verbose --key github --host https://rubygems.pkg.github.com/${OWNER} *.gem
27
+ env:
28
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
29
+ OWNER: ${{ github.repository_owner }}
30
+ continue-on-error: true
31
+
32
+ - name: Publish to RubyGems
33
+ run: |
34
+ gem push --verbose *.gem
35
+ env:
36
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_TOKEN}}
@@ -1,12 +1,18 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  cache: bundler
4
- dist: precise
4
+ dist: xenial
5
5
 
6
6
  services:
7
7
  - mysql
8
8
  - postgresql
9
9
 
10
+ addons:
11
+ postgresql: 10
12
+ apt:
13
+ packages:
14
+ - postgresql-10-postgis-2.4
15
+
10
16
  before_install:
11
17
  - gem install bundler
12
18
 
@@ -16,24 +22,28 @@ before_script:
16
22
  - psql -c 'create extension postgis;' -U postgres
17
23
 
18
24
  rvm:
19
- - 2.0
20
- - 2.1
21
- - 2.2
25
+ # - 2.0
26
+ # - 2.1
27
+ # - 2.2
22
28
  - 2.3
23
29
  - 2.4
24
30
  - 2.5.0
31
+ - 2.6.0
32
+ - 2.7.0
25
33
  - ruby-head
26
34
  - jruby
27
35
 
28
36
  gemfile:
29
- - gemfiles/ar30.gemfile
30
- - gemfiles/ar31.gemfile
31
- - gemfiles/ar32.gemfile
32
- - gemfiles/ar40.gemfile
33
- - gemfiles/ar41.gemfile
34
- - gemfiles/ar42.gemfile
37
+ # - gemfiles/ar30.gemfile
38
+ # - gemfiles/ar31.gemfile
39
+ # - gemfiles/ar32.gemfile
40
+ # - gemfiles/ar40.gemfile
41
+ # - gemfiles/ar41.gemfile
42
+ # - gemfiles/ar42.gemfile
35
43
  - gemfiles/ar50.gemfile
36
44
  - gemfiles/ar51.gemfile
45
+ - gemfiles/ar52.gemfile
46
+ - gemfiles/ar60.gemfile
37
47
  - gemfiles/ar-head.gemfile
38
48
 
39
49
  env:
@@ -88,6 +98,22 @@ matrix:
88
98
  rvm: 2.1
89
99
  - gemfile: gemfiles/ar51.gemfile
90
100
  rvm: 2.2
101
+ - gemfile: gemfiles/ar52.gemfile
102
+ rvm: 2.0
103
+ - gemfile: gemfiles/ar52.gemfile
104
+ rvm: 2.1
105
+ - gemfile: gemfiles/ar52.gemfile
106
+ rvm: 2.2
107
+ - gemfile: gemfiles/ar60.gemfile
108
+ rvm: 2.0
109
+ - gemfile: gemfiles/ar60.gemfile
110
+ rvm: 2.1
111
+ - gemfile: gemfiles/ar60.gemfile
112
+ rvm: 2.2
113
+ - gemfile: gemfiles/ar60.gemfile
114
+ rvm: 2.3
115
+ - gemfile: gemfiles/ar60.gemfile
116
+ rvm: 2.4
91
117
  - gemfile: gemfiles/ar-head.gemfile
92
118
  rvm: 2.0
93
119
  - gemfile: gemfiles/ar-head.gemfile
@@ -1,109 +1,122 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## v0.5.0 - 2021-01-08
5
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.4.1...v0.4.2)
6
+ - Replace deprecated URI.unescape with CGI.unescape [#252](https://github.com/instacart/makara/pull/252) Kevin Robatel
7
+ - Override equality operator for ActiveRecord connection wrapper [#269](https://github.com/instacart/makara/pull/269) Praveen Burgu
8
+ - Handle blacklisted connections in master pool while in transaction [#267] (https://github.com/instacart/makara/pull/267) Praveen Burgu
9
+ - Handle ActiveRecord connection pools correctly [#267] (https://github.com/instacart/makara/pull/267) Praveen Burgu
10
+ - Add preliminary support for sharded databases [#267] (https://github.com/instacart/makara/pull/267) Praveen Burgu
11
+ - Fix ActiveRecord connection pool exhaustion [#268] (https://github.com/instacart/makara/pull/268) Praveen Burgu
12
+ - Drop support for Ruby 2.0, 2.1 and 2.2 [#267] (https://github.com/instacart/makara/pull/267) Praveen Burgu
13
+ - Drop support ActiveRecord 3.x and 4.x [#267] (https://github.com/instacart/makara/pull/267) Praveen Burgu
14
+ - Set up automatic publishing to Github and Rubygems [#275](https://github.com/instacart/makara/pull/275) Matt Larraz
15
+
16
+
4
17
  ## v0.4.1 - 2019-03-25
5
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.4.0...v0.4.1)
18
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.4.0...v0.4.1)
6
19
 
7
- - Fix crash by requiring makara in the adapter [#54](https://github.com/taskrabbit/makara/pull/54) Eric Saxby
8
- - Add connection logging in non-Rails enviroments [#223](https://github.com/taskrabbit/makara/pull/223) Andrew Kane
20
+ - Fix crash by requiring makara in the adapter [#54](https://github.com/instacart/makara/pull/54) Eric Saxby
21
+ - Add connection logging in non-Rails enviroments [#223](https://github.com/instacart/makara/pull/223) Andrew Kane
9
22
 
10
23
  ## v0.4.0 - 2018-04-01
11
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.10...v0.4.0)
24
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.10...v0.4.0)
12
25
 
13
26
  This release is a major change to how we remember state between requests. A redis store is no longer needed. Everything is in the cookies.
14
- - Implement stickiness for the duration of `master_ttl` via cookies [#194](https://github.com/taskrabbit/makara/pull/194) Rosa Gutierrez
27
+ - Implement stickiness for the duration of `master_ttl` via cookies [#194](https://github.com/instacart/makara/pull/194) Rosa Gutierrez
15
28
 
16
29
 
17
30
  ## v0.3.10 - 2018-03-20
18
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.9...v0.3.10)
31
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.9...v0.3.10)
19
32
 
20
33
  Fixed
21
- - Send nextval queries to master and show queries to replicas for Postgres [#173](https://github.com/taskrabbit/makara/pull/173) Andrew Kane
22
- - Fixes can't add a new key into hash during iteration error [#174](https://github.com/taskrabbit/makara/pull/174) Andrew Kane
23
- - Fix: an application freezes when a slave is down [#180](https://github.com/taskrabbit/makara/pull/180) Alexey P
24
- - Allow SELECTs that use common table expressions to go to replicas [#184](https://github.com/taskrabbit/makara/pull/184) Andrew Kane
25
- - Send advisory lock requests to the master [#198](https://github.com/taskrabbit/makara/pull/198) George Claghorn
26
- - Postgres exists query [#199](https://github.com/taskrabbit/makara/pull/199) Brian Leonard
34
+ - Send nextval queries to master and show queries to replicas for Postgres [#173](https://github.com/instacart/makara/pull/173) Andrew Kane
35
+ - Fixes can't add a new key into hash during iteration error [#174](https://github.com/instacart/makara/pull/174) Andrew Kane
36
+ - Fix: an application freezes when a slave is down [#180](https://github.com/instacart/makara/pull/180) Alexey P
37
+ - Allow SELECTs that use common table expressions to go to replicas [#184](https://github.com/instacart/makara/pull/184) Andrew Kane
38
+ - Send advisory lock requests to the master [#198](https://github.com/instacart/makara/pull/198) George Claghorn
39
+ - Postgres exists query [#199](https://github.com/instacart/makara/pull/199) Brian Leonard
27
40
 
28
41
  Documentation and Test
29
- - Clarify README's "What goes where" [#187](https://github.com/taskrabbit/makara/pull/187) Jan Sandbrink
30
- - Fix loading fixtures in Rails 5.2 [#192](https://github.com/taskrabbit/makara/pull/192) George Claghorn
31
- - Travis Upgrade [#199](https://github.com/taskrabbit/makara/pull/199) Brian Leonard
42
+ - Clarify README's "What goes where" [#187](https://github.com/instacart/makara/pull/187) Jan Sandbrink
43
+ - Fix loading fixtures in Rails 5.2 [#192](https://github.com/instacart/makara/pull/192) George Claghorn
44
+ - Travis Upgrade [#199](https://github.com/instacart/makara/pull/199) Brian Leonard
32
45
 
33
46
  ## v0.3.9 - 2017-08-14
34
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.8...v0.3.9)
47
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.8...v0.3.9)
35
48
 
36
49
  Changed
37
- - Add postgis support [#118](https://github.com/taskrabbit/makara/pull/118) Kevin Bacha
50
+ - Add postgis support [#118](https://github.com/instacart/makara/pull/118) Kevin Bacha
38
51
 
39
52
  ## v0.3.8 - 2017-07-11
40
53
 
41
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.7...v0.3.8)
54
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.7...v0.3.8)
42
55
 
43
56
  Changed
44
- - Rails 5.1 compatibility [#150](https://github.com/taskrabbit/makara/pull/150) Jeremy Daer
45
- - Minimize redundant context cache requests [#157](https://github.com/taskrabbit/makara/issues/157) Greg Patrick
46
- - thread-local cache for previous context stickiness [#158](https://github.com/taskrabbit/makara/issues/158) Jeremy Daer
47
- - Configurable cookie options [#159](https://github.com/taskrabbit/makara/pull/159) Jeremy Daer
48
- - Test against Rails 5.x and Ruby 2.x [#160](https://github.com/taskrabbit/makara/pull/160) Jeremy Daer
57
+ - Rails 5.1 compatibility [#150](https://github.com/instacart/makara/pull/150) Jeremy Daer
58
+ - Minimize redundant context cache requests [#157](https://github.com/instacart/makara/issues/157) Greg Patrick
59
+ - thread-local cache for previous context stickiness [#158](https://github.com/instacart/makara/issues/158) Jeremy Daer
60
+ - Configurable cookie options [#159](https://github.com/instacart/makara/pull/159) Jeremy Daer
61
+ - Test against Rails 5.x and Ruby 2.x [#160](https://github.com/instacart/makara/pull/160) Jeremy Daer
49
62
 
50
63
  ## v0.3.7 - 2016-09-22
51
64
 
52
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.6...v0.3.7)
65
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.6...v0.3.7)
53
66
 
54
67
  Changed
55
68
 
56
- - Fix the hierarchy of the config file [#116](https://github.com/taskrabbit/makara/pull/116) Kevin Bacha
57
- - "Disable blacklist" parameter [#134](https://github.com/taskrabbit/makara/pull/134) Alex Tonkonozhenko
58
- - Fixes bug in `without_sticking` [#96](https://github.com/taskrabbit/makara/pull/96) Brian Leonard
59
- - Always stick inside transactions [#96](https://github.com/taskrabbit/makara/pull/96) Brian Leonard
60
- - Rails 5 support [#122](https://github.com/taskrabbit/makara/pull/122) Jonny McAllister
69
+ - Fix the hierarchy of the config file [#116](https://github.com/instacart/makara/pull/116) Kevin Bacha
70
+ - "Disable blacklist" parameter [#134](https://github.com/instacart/makara/pull/134) Alex Tonkonozhenko
71
+ - Fixes bug in `without_sticking` [#96](https://github.com/instacart/makara/pull/96) Brian Leonard
72
+ - Always stick inside transactions [#96](https://github.com/instacart/makara/pull/96) Brian Leonard
73
+ - Rails 5 support [#122](https://github.com/instacart/makara/pull/122) Jonny McAllister
61
74
 
62
75
  ## v0.3.6 - 2016-04-21
63
76
 
64
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.5...v0.3.6)
77
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.5...v0.3.6)
65
78
 
66
79
  Changed
67
80
 
68
- - Allow different strategies such as `priority` and `round_robin` for pools [#105](https://github.com/taskrabbit/makara/pull/105) Brian Leonard
81
+ - Allow different strategies such as `priority` and `round_robin` for pools [#105](https://github.com/instacart/makara/pull/105) Brian Leonard
69
82
 
70
83
 
71
84
  ## v0.3.5 - 2016-01-08
72
85
 
73
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.4.rc1...v0.3.5)
86
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.4.rc1...v0.3.5)
74
87
 
75
88
  Changed
76
89
 
77
- - Raise `Makara::Errors::AllConnectionsBlacklisted` on timeout. [#104](https://github.com/taskrabbit/makara/pull/104) Brian Leonard
90
+ - Raise `Makara::Errors::AllConnectionsBlacklisted` on timeout. [#104](https://github.com/instacart/makara/pull/104) Brian Leonard
78
91
 
79
92
  ## v0.3.4.rc1 - 2016-01-06
80
93
 
81
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.3...v0.3.4.rc1)
94
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.3...v0.3.4.rc1)
82
95
 
83
96
  Added
84
97
 
85
- - Add `url` to database connections configurations. [#93](https://github.com/taskrabbit/makara/pull/93) Benjamin Fleischer
98
+ - Add `url` to database connections configurations. [#93](https://github.com/instacart/makara/pull/93) Benjamin Fleischer
86
99
 
87
100
  Changed
88
101
 
89
- - Improve Postgresql compatibility and failover support, also fix [#78](https://github.com/taskrabbit/makara/issues/78), [#79](https://github.com/taskrabbit/makara/issues/79). [#87](https://github.com/taskrabbit/makara/pull/87) Vlad
90
- - Update README: Specify newrelic_rpm gem versions that will have the performance issue. [#95](https://github.com/taskrabbit/makara/pull/95) Benjamin Fleischer
102
+ - Improve Postgresql compatibility and failover support, also fix [#78](https://github.com/instacart/makara/issues/78), [#79](https://github.com/instacart/makara/issues/79). [#87](https://github.com/instacart/makara/pull/87) Vlad
103
+ - Update README: Specify newrelic_rpm gem versions that will have the performance issue. [#95](https://github.com/instacart/makara/pull/95) Benjamin Fleischer
91
104
 
92
105
  ## v0.3.3 - 2015-05-20
93
106
 
94
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.2...v0.3.3)
107
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.2...v0.3.3)
95
108
 
96
109
  Changed
97
110
 
98
- - A context is local to the curent thread of execution. This will allow you to stick to master safely in a single thread in systems such as sidekiq, for instance. Fix [#83](https://github.com/taskrabbit/makara/issues/83). [#84](https://github.com/taskrabbit/makara/pull/84) Matt Camuto
111
+ - A context is local to the curent thread of execution. This will allow you to stick to master safely in a single thread in systems such as sidekiq, for instance. Fix [#83](https://github.com/instacart/makara/issues/83). [#84](https://github.com/instacart/makara/pull/84) Matt Camuto
99
112
 
100
113
  ## v0.3.2 - 2015-05-16
101
114
 
102
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.1...v0.3.2)
115
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.1...v0.3.2)
103
116
 
104
117
  Fixed
105
118
 
106
- - Fix a `ArgumentError: not delegated` error for rails 3. [#82](https://github.com/taskrabbit/makara/pull/82) Eric Saxby
119
+ - Fix a `ArgumentError: not delegated` error for rails 3. [#82](https://github.com/instacart/makara/pull/82) Eric Saxby
107
120
 
108
121
  Changed
109
122
 
@@ -111,7 +124,7 @@ Changed
111
124
 
112
125
  ## v0.3.1 - 2015-05-08
113
126
 
114
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.0...v0.3.1)
127
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.0...v0.3.1)
115
128
 
116
129
  Changed
117
130
 
@@ -121,21 +134,21 @@ Changed
121
134
 
122
135
  ## v0.3.0 - 2015-04-27
123
136
 
124
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.0.rc3...v0.3.0)
137
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.0.rc3...v0.3.0)
125
138
 
126
139
  Changed
127
140
 
128
- - Reduce logging noise by using [the same rules as ActiveRecord uses](https://github.com/rails/rails/blob/b06f64c3480cd389d14618540d62da4978918af0/activerecord/lib/active_record/log_subscriber.rb#L33). [#76](https://github.com/taskrabbit/makara/pull/76) Andrew Kane
141
+ - Reduce logging noise by using [the same rules as ActiveRecord uses](https://github.com/rails/rails/blob/b06f64c3480cd389d14618540d62da4978918af0/activerecord/lib/active_record/log_subscriber.rb#L33). [#76](https://github.com/instacart/makara/pull/76) Andrew Kane
129
142
 
130
143
  Fixed
131
144
 
132
- - Fix an issue for postgres that would route all queries to master. [#72](https://github.com/taskrabbit/makara/pull/72) Kali Donovan
133
- - Fix an edge case which would cause SET operations to send to all connections([#70](https://github.com/taskrabbit/makara/issues/70)). [#80](https://github.com/taskrabbit/makara/pull/80) Michael Amor Righi
134
- - Fix performance regression with certain verions of [newrelic/rpm](https://github.com/newrelic/rpm)([#59](https://github.com/taskrabbit/makara/issues/59)). [#75](https://github.com/taskrabbit/makara/pull/75) Mike Nelson
145
+ - Fix an issue for postgres that would route all queries to master. [#72](https://github.com/instacart/makara/pull/72) Kali Donovan
146
+ - Fix an edge case which would cause SET operations to send to all connections([#70](https://github.com/instacart/makara/issues/70)). [#80](https://github.com/instacart/makara/pull/80) Michael Amor Righi
147
+ - Fix performance regression with certain verions of [newrelic/rpm](https://github.com/newrelic/rpm)([#59](https://github.com/instacart/makara/issues/59)). [#75](https://github.com/instacart/makara/pull/75) Mike Nelson
135
148
 
136
149
  ## 0.3.0.rc3 - 2014-09-02[YANKED]
137
150
 
138
- [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.0.rc2...v0.3.0.rc3)
151
+ [Full Changelog](https://github.com/instacart/makara/compare/v0.3.0.rc2...v0.3.0.rc3)
139
152
 
140
153
  Added
141
154
  - Allow bypassing of stickiness
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ gem 'rspec'
8
8
  gem 'timecop'
9
9
  gem 'byebug', :platform => :ruby
10
10
  gem 'ruby-debug', :platform => :jruby
11
- gem 'rack', '1.6.0'
11
+ gem 'rack', '2.2.3'
12
12
 
13
13
  gem 'mysql2', :platform => :ruby
14
14
  gem 'pg', '0.21.0', :platform => :ruby
data/README.md CHANGED
@@ -6,14 +6,6 @@
6
6
 
7
7
  Makara is generic master/slave proxy. It handles the heavy lifting of managing, choosing, blacklisting, and cycling through connections. It comes with an ActiveRecord database adapter implementation.
8
8
 
9
- #### Warning:
10
-
11
- There is a potential performance issue when used alongside certain versions of
12
- [newrelic/rpm](https://github.com/newrelic/rpm), [Issue #59](https://github.com/taskrabbit/makara/issues/59).
13
-
14
- > Any newrelic_rpm `< 3.11.2` and `>= 3.7.2` will have the regression.
15
- > I'd recommend upgrading newrelic_rpm to avoid the problem.
16
-
17
9
  ## Installation
18
10
 
19
11
  Use the current version of the gem from [rubygems](https://rubygems.org/gems/makara) in your `Gemfile`.
@@ -67,6 +59,12 @@ Makara handles stickiness by keeping track of which proxies are stuck at any giv
67
59
 
68
60
  To handle persistence of context across requests in a Rack app, makara provides a middleware. It lays a cookie named `_mkra_stck` which contains the current context. If the next request is executed before the cookie expires, that given context will be used. If something occurs which naturally requires master on the second request, the context is updated and stored again.
69
61
 
62
+ #### Stickiness Impact
63
+
64
+ When `sticky:true`, once a query as been sent to master, all queries for the rest of the request will also be sent to master. In addition, the cookie described above will be set client side with an expiration defined by time at end of original request + `master_ttl`. As long as the cookie is valid, all requests will send queries to master.
65
+
66
+ When `sticky:false`, only queries that need to go to master will go there. Subsequent read queries in the same request will go to slaves.
67
+
70
68
  #### Releasing stuck connections (clearing context)
71
69
 
72
70
  If you need to clear the current context, releasing any stuck connections, all you have to do is:
@@ -11,7 +11,7 @@ gem 'rack'
11
11
  gem 'timecop'
12
12
  gem 'mysql2', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
- gem 'pg', '0.21.0', :platform => :ruby
14
+ gem 'pg', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
16
 
17
17
 
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in makara.gemspec
4
+ gemspec :path => '../'
5
+
6
+
7
+ gem 'rake'
8
+ gem 'activerecord', '~> 5.2.0'
9
+ gem 'rspec'
10
+ gem 'rack'
11
+ gem 'timecop'
12
+ gem 'mysql2', '~> 0.4.10', :platform => :ruby
13
+ gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
+ gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in makara.gemspec
4
+ gemspec :path => '../'
5
+
6
+
7
+ gem 'rake'
8
+ gem 'activerecord', '~> 6.0.0'
9
+ gem 'rspec'
10
+ gem 'rack'
11
+ gem 'timecop'
12
+ gem 'mysql2', '~> 0.4.10', :platform => :ruby
13
+ gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
+ gem 'pg', '0.21.0', :platform => :ruby
15
+ gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+
17
+
18
+ rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
19
+
20
+ # 2.1 +
21
+ if rmajor > 2 || (rmajor == 2 && rminor >= 1)
22
+ gem 'activerecord-postgis-adapter', :platform => :ruby
23
+ gem 'rgeo', :platform => :ruby
24
+ end
@@ -109,6 +109,10 @@ module ActiveRecord
109
109
  hijack_method :execute, :exec_query, :exec_no_cache, :exec_cache, :transaction
110
110
  send_to_all :connect, :reconnect!, :verify!, :clear_cache!, :reset!
111
111
 
112
+ control_method :close, :steal!, :expire, :lease, :in_use?, :owner, :schema_cache, :pool=, :pool,
113
+ :schema_cache=, :lock, :seconds_idle, :==
114
+
115
+
112
116
  SQL_MASTER_MATCHERS = [/\A\s*select.+for update\Z/i, /select.+lock in share mode\Z/i, /\A\s*select.+(nextval|currval|lastval|get_lock|release_lock|pg_advisory_lock|pg_advisory_unlock)\(/i].map(&:freeze).freeze
113
117
  SQL_SLAVE_MATCHERS = [/\A\s*(select|with.+\)\s*select)\s/i].map(&:freeze).freeze
114
118
  SQL_ALL_MATCHERS = [/\A\s*set\s/i].map(&:freeze).freeze
@@ -137,6 +141,7 @@ module ActiveRecord
137
141
 
138
142
  def initialize(config)
139
143
  @error_handler = ::ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter::ErrorHandler.new
144
+ @control = ActiveRecordPoolControl.new(self)
140
145
  super(config)
141
146
  end
142
147
 
@@ -206,7 +211,107 @@ module ActiveRecord
206
211
  raise NotImplementedError
207
212
  end
208
213
 
214
+ class ActiveRecordPoolControl
215
+ attr_reader :owner
216
+ alias :in_use? :owner
217
+
218
+ def initialize(proxy)
219
+ @proxy = proxy
220
+ @owner = nil
221
+ @pool = nil
222
+ @schema_cache = ActiveRecord::ConnectionAdapters::SchemaCache.new @proxy
223
+ @idle_since = Concurrent.monotonic_time
224
+ @adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(@proxy)
225
+ end
226
+
227
+ def close(*args)
228
+ @pool.checkin @proxy
229
+ end
230
+
231
+ # this method must only be called while holding connection pool's mutex
232
+ def lease(*args)
233
+ if in_use?
234
+ msg = +"Cannot lease connection, "
235
+ if @owner == Thread.current
236
+ msg << "it is already leased by the current thread."
237
+ else
238
+ msg << "it is already in use by a different thread: #{@owner}. " \
239
+ "Current thread: #{Thread.current}."
240
+ end
241
+ raise ActiveRecordError, msg
242
+ end
243
+ @owner = Thread.current
244
+ end
245
+
246
+ # this method must only be called while holding connection pool's mutex
247
+ def expire(*args)
248
+ if in_use?
249
+ if @owner != Thread.current
250
+ raise ActiveRecordError, "Cannot expire connection, " \
251
+ "it is owned by a different thread: #{@owner}. " \
252
+ "Current thread: #{Thread.current}."
253
+ end
254
+
255
+ @idle_since = Concurrent.monotonic_time
256
+ @owner = nil
257
+ else
258
+ raise ActiveRecordError, "Cannot expire connection, it is not currently leased."
259
+ end
260
+ end
261
+
262
+ # Seconds since this connection was returned to the pool
263
+ def seconds_idle(*args)
264
+ return 0 if in_use?
265
+
266
+ Concurrent.monotonic_time - @idle_since
267
+ end
268
+
269
+ # this method must only be called while holding connection pool's mutex (and a desire for segfaults)
270
+ def steal!(*args)
271
+ if in_use?
272
+ if @owner != Thread.current
273
+ @pool.send :remove_connection_from_thread_cache, @proxy, @owner
274
+ @owner = Thread.current
275
+ end
276
+ else
277
+ raise ActiveRecordError, "Cannot steal connection, it is not currently leased."
278
+ end
279
+ end
280
+
281
+ def schema_cache(*args)
282
+ if @pool.respond_to?(:get_schema_cache) # AR6
283
+ @pool.get_schema_cache(@proxy)
284
+ else
285
+ @schema_cache
286
+ end
287
+ end
288
+
289
+ def schema_cache=(*args)
290
+ cache = args[0]
291
+ cache.connection = @proxy
292
+ if @pool.respond_to?(:set_schema_cache) # AR6
293
+ @pool.set_schema_cache(cache)
294
+ else
295
+ @schema_cache = cache
296
+ end
297
+ end
298
+
299
+ def lock(*args)
300
+ @adapter.lock
301
+ end
302
+
303
+ def pool=(*args)
304
+ @pool = args[0]
305
+ end
306
+
307
+ def pool(*args)
308
+ @pool
309
+ end
209
310
 
311
+ def ==(*args)
312
+ @proxy.object_id == args[0].object_id
313
+ end
314
+ end
210
315
  end
211
316
  end
212
317
  end