pgpool_no_load_balance 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d372d723de84f85915542bfb4fc837a23605c0029079441e0361e48910df68af
4
+ data.tar.gz: 7dc3328d6936cf6920dd273df573c2e55f88be9159bbc60013eb35a27de3146b
5
+ SHA512:
6
+ metadata.gz: 46423f6a6f8a8b3847d999926e920e24cdc8923194b2d7b3349b0676c08c55ae415d5b3b2b1afe32cc96f05abe898a7db6fbea67479e50392c932cab18e7defd
7
+ data.tar.gz: e624bfe2987b3ee4f3adafb61ee71eb64be5cac9c648afd263b59e44f971e66444b959169c3ae813a9ec12a0fc77b4ac62b03b144fedb24401d1560e0fb34444
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,52 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## [Unreleased] - yyyy-mm-dd
9
+
10
+ Here we write upgrading notes for brands. It's a team effort to make them as
11
+ straightforward as possible.
12
+
13
+ ### Added
14
+ - [PROJECTNAME-XXXX](http://tickets.projectname.com/browse/PROJECTNAME-XXXX)
15
+ MINOR Ticket title goes here.
16
+ - [PROJECTNAME-YYYY](http://tickets.projectname.com/browse/PROJECTNAME-YYYY)
17
+ PATCH Ticket title goes here.
18
+
19
+ ### Changed
20
+
21
+ ### Fixed
22
+
23
+ ### Security
24
+
25
+ ## [1.0.3] - 2020-05-05
26
+
27
+ for RubyGems release.
28
+
29
+ ## [1.0.2] - 2020-05-05
30
+
31
+ Here we write upgrading notes for brands. It's a team effort to make them as
32
+ straightforward as possible.
33
+
34
+ ### Added
35
+ - Adapter check feature. (PostgreSQLAdapterMissing exception is raised if the application is not using the Postgresql adaptor.)
36
+
37
+ ## [1.0.1] - 2020-05-05
38
+
39
+ ### Added
40
+
41
+ ### Changed
42
+
43
+ - change module name.
44
+
45
+ ### Fixed
46
+
47
+ ### Security
48
+
49
+ ## [1.0.0] - 2020-05-05
50
+
51
+ First release!
52
+
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at s.kuroda@infocom-east.co.jp. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pgpool_no_load_balance.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 cn-kuroda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # PgpoolNoLoadBalance
2
+
3
+ This gem exists for you to use [Pgpool-II's load balancing](https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html) feature.
4
+
5
+ If you don't want a query that qualifies for the load balancing to be load balanced by Pgpool-II, you can put arbitrary comment(`/*NO LOAD BALANCE*/` is usually used) before the SELECT statement. This will disable the load balance of the particular query and Pgpool-II will send it to the master node (the primary node in Master Slave mode).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pgpool_no_load_balance'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pgpool_no_load_balance
22
+
23
+ ## Usage
24
+
25
+ ### pgpool_nlb method
26
+
27
+ Using the `pgpool_nlb` method will add a comment to the SQL.
28
+ ```irb
29
+ irb(main):001:0> User.pgpool_nlb.all
30
+ /*NO LOAD BALANCE*/ SELECT "users".* FROM "users" LIMIT $1 [["LIMIT", 11]]
31
+ ```
32
+
33
+ ### unscope
34
+
35
+ Can remove the scope with the unscope method.
36
+ ```irb
37
+ irb(main):001:0> user_relation = User.where(name: 'elengine').pgpool_nlb
38
+ irb(main):002:0> user_relation.count
39
+ /*NO LOAD BALANCE*/ SELECT COUNT(*) FROM "users" WHERE "users"."name" = $1 [["name", "elengine"]]
40
+ irb(main):003:0> user_relation.unscope(:pgpool_nlb).order(:id).limit(3)
41
+ SELECT "users".* FROM "users" WHERE "users"."name" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["name", "elengine"], ["LIMIT", 3]]
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/elengine/pgpool_no_load_balance. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/elengine/pgpool_no_load_balance/blob/master/CODE_OF_CONDUCT.md).
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
52
+
53
+ ## Code of Conduct
54
+
55
+ Everyone interacting in the PgpoolNoLoadBalance project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/elengine/pgpool_no_load_balance/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pgpool_no_load_balance"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ require "pgpool_no_load_balance/active_record/querying"
2
+ require "pgpool_no_load_balance/active_record/relation/query_methods"
3
+ require "pgpool_no_load_balance/arel/select_manager"
4
+ require "pgpool_no_load_balance/active_record/connection_adapters/postgresql_adapter"
5
+ require "pgpool_no_load_balance/active_record/explain_subscriber"
6
+ require "pgpool_no_load_balance/railtie" if defined?(::Rails::Railtie)
7
+ require "pgpool_no_load_balance/version"
8
+
9
+ module PgpoolNoLoadBalance
10
+ NLB_COMMENT = '/*NO LOAD BALANCE*/'
11
+
12
+ class PostgreSQLAdapterMissing < StandardError; end
13
+
14
+ def self.setup!
15
+ unless ::ActiveRecord::Base.respond_to?(:postgresql_connection)
16
+ raise PostgreSQLAdapterMissing, "No postgresql adapter specified by 'config/database.yml', or 'ActiveRecord::Base.establish_connection' method is not called."
17
+ end
18
+ ::ActiveRecord::Base.extend PgpoolNoLoadBalance::ActiveRecord::Querying
19
+ ::ActiveRecord::Relation.prepend PgpoolNoLoadBalance::ActiveRecord::QueryMethods
20
+ ::ActiveRecord::Relation::VALID_UNSCOPING_VALUES << :pgpool_nlb
21
+ ::Arel::SelectManager.include PgpoolNoLoadBalance::Arel::SelectManager
22
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend PgpoolNoLoadBalance::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
23
+ ::ActiveRecord::ExplainSubscriber.prepend PgpoolNoLoadBalance::ActiveRecord::ExplainSubscriber
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module PgpoolNoLoadBalance
2
+ module ActiveRecord
3
+ module ConnectionAdapters
4
+ module PostgreSQLAdapter
5
+
6
+ private
7
+
8
+ def to_sql_and_binds(arel_or_sql_string, binds=[])
9
+ sql, binds = super
10
+ if arel_or_sql_string.respond_to?(:pgpool_nlb?) && arel_or_sql_string.pgpool_nlb?
11
+ sql = "#{NLB_COMMENT} #{sql}"
12
+ end
13
+ [sql.freeze, binds]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module PgpoolNoLoadBalance
2
+ module ActiveRecord
3
+ module ExplainSubscriber
4
+ def ignore_payload?(payload)
5
+ payload_for_check = payload.dup
6
+ payload_for_check[:sql] = payload_for_check[:sql].sub(NLB_COMMENT, '')
7
+ super payload_for_check
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require "active_support"
2
+
3
+ module PgpoolNoLoadBalance
4
+ module ActiveRecord
5
+ module Querying
6
+ delegate :pgpool_nlb, to: :all
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ module PgpoolNoLoadBalance
2
+ module ActiveRecord
3
+ module QueryMethods
4
+ def pgpool_nlb(value = true)
5
+ spawn.pgpool_nlb!(value)
6
+ end
7
+
8
+ def pgpool_nlb!(value = true)
9
+ self.pgpool_nlb_value = value
10
+ self
11
+ end
12
+
13
+ def pgpool_nlb_value
14
+ @values.fetch(:pgpool_nlb, nil)
15
+ end
16
+
17
+ def pgpool_nlb_value=(value)
18
+ assert_mutability!
19
+ @values[:pgpool_nlb] = value
20
+ end
21
+
22
+ private
23
+
24
+ def build_arel(aliases)
25
+ arel = super
26
+ arel.pgpool_nlb(pgpool_nlb_value)
27
+ arel
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ module PgpoolNoLoadBalance
2
+ module Arel
3
+ module SelectManager
4
+ def pgpool_nlb(value = true)
5
+ @pgpool_nlb_flag = !!value
6
+ self
7
+ end
8
+
9
+ def pgpool_nlb?
10
+ @pgpool_nlb_flag
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module PgpoolNoLoadBalance
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ initializer 'pgpool_nlb.initialize', after: 'active_record.initialize_database' do |app|
5
+ ActiveSupport.on_load(:active_record) { PgpoolNoLoadBalance.setup! }
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module PgpoolNoLoadBalance
2
+ VERSION = "1.0.3"
3
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/pgpool_no_load_balance/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "pgpool_no_load_balance"
5
+ spec.version = PgpoolNoLoadBalance::VERSION
6
+ spec.authors = ["elengine"]
7
+ spec.email = ["info.el.engine@gmail.com"]
8
+
9
+ spec.summary = "Disable load balancing by Pgpool-II for Rails apps."
10
+ spec.homepage = "https://github.com/elengine/pgpool_no_load_balance"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.2.2")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "activerecord", ">= 5.2.0"
28
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pgpool_no_load_balance
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - elengine
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ description:
28
+ email:
29
+ - info.el.engine@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - CHANGELOG.md
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - lib/pgpool_no_load_balance.rb
46
+ - lib/pgpool_no_load_balance/active_record/connection_adapters/postgresql_adapter.rb
47
+ - lib/pgpool_no_load_balance/active_record/explain_subscriber.rb
48
+ - lib/pgpool_no_load_balance/active_record/querying.rb
49
+ - lib/pgpool_no_load_balance/active_record/relation/query_methods.rb
50
+ - lib/pgpool_no_load_balance/arel/select_manager.rb
51
+ - lib/pgpool_no_load_balance/railtie.rb
52
+ - lib/pgpool_no_load_balance/version.rb
53
+ - pgpool_no_load_balance.gemspec
54
+ homepage: https://github.com/elengine/pgpool_no_load_balance
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ homepage_uri: https://github.com/elengine/pgpool_no_load_balance
59
+ source_code_uri: https://github.com/elengine/pgpool_no_load_balance
60
+ changelog_uri: https://github.com/elengine/pgpool_no_load_balance/CHANGELOG.md
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.2.2
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.0.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Disable load balancing by Pgpool-II for Rails apps.
80
+ test_files: []