Sha256: 090e49fb1a278e0866b99c5a4ad03cadb240d564b87616884f8ca4b211f66a2a

Contents?: true

Size: 1.65 KB

Versions: 23

Compression:

Stored size: 1.65 KB

Contents

require 'elasticsearch'
require 'elasticsearch/transport/transport/connections/selector'

if Gem.loaded_specs['elasticsearch-transport'].version < Gem::Version.new("7.2.0")
  # elasticsearch-transport versions prior to 7.2.0 suffered of a race condition on accessing
  # the connection pool. This issue was fixed (in 7.2.0) with
  # https://github.com/elastic/elasticsearch-ruby/commit/15f9d78591a6e8823948494d94b15b0ca38819d1
  #
  # This plugin, at the moment, is using elasticsearch >= 5.0.5
  # When this requirement ceases, this patch could be removed.
  module Elasticsearch
    module Transport
      module Transport
        module Connections
          module Selector

            # "Round-robin" selector strategy (default).
            #
            class RoundRobin
              include Base

              # @option arguments [Connections::Collection] :connections Collection with connections.
              #
              def initialize(arguments = {})
                super
                @mutex = Mutex.new
                @current = nil
              end

              # Returns the next connection from the collection, rotating them in round-robin fashion.
              #
              # @return [Connections::Connection]
              #
              def select(options={})
                @mutex.synchronize do
                  conns = connections
                  if @current && (@current < conns.size-1)
                    @current += 1
                  else
                    @current = 0
                  end
                  conns[@current]
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
logstash-input-elasticsearch-4.20.4 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.20.3 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.20.2 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.20.1 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.20.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.19.1 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.19.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.18.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.17.2 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.17.1 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.17.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.16.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.15.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.14.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.13.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.12.3 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.12.2 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.12.1 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.12.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb
logstash-input-elasticsearch-4.11.0 lib/logstash/inputs/elasticsearch/patches/_elasticsearch_transport_connections_selector.rb