Class: Mongo::Server::ConnectionPool::GenerationManager Private
- Inherits:
-
Object
- Object
- Mongo::Server::ConnectionPool::GenerationManager
- Defined in:
- lib/mongo/server/connection_pool/generation_manager.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #server ⇒ Object readonly private
Instance Method Summary collapse
- #bump(service_id: nil) ⇒ Object private
-
#close_all_pipes ⇒ Object
private
Close all pipes in the generation manager.
- #generation(service_id: nil) ⇒ Object private
- #generation_unlocked(service_id: nil) ⇒ Object private
-
#initialize(server:) ⇒ GenerationManager
constructor
private
A new instance of GenerationManager.
- #pipe_fds(service_id: nil) ⇒ Object private
- #remove_pipe_fds(generation, service_id: nil) ⇒ Object private
Constructor Details
#initialize(server:) ⇒ GenerationManager
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of GenerationManager.
22 23 24 25 26 27 28 |
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 22 def initialize(server:) @map = Hash.new { |hash, key| hash[key] = 1 } @pipe_fds = Hash.new { |hash, key| hash[key] = { 1 => IO.pipe } } @server = server @lock = Mutex.new @scheduled_for_close = [] end |
Instance Attribute Details
#server ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 30 def server @server end |
Instance Method Details
#bump(service_id: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 65 def bump(service_id: nil) @lock.synchronize do close_all_scheduled if service_id gen = @map[service_id] += 1 @pipe_fds[service_id] ||= {} @pipe_fds[service_id][gen] = IO.pipe else # When service id is not supplied, one of two things may be # happening; # # 1. The pool is not to a load balancer, in which case we only # need to increment the generation for the nil service_id. # 2. The pool is to a load balancer, in which case we need to # increment the generation for each service. # # Incrementing everything in the map accomplishes both tasks. @map.each do |k, _v| gen = @map[k] += 1 @pipe_fds[service_id] ||= {} @pipe_fds[service_id][gen] = IO.pipe end end end end |
#close_all_pipes ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Close all pipes in the generation manager.
This method should be called only when the ConnectionPool that owns this GenerationManager is closed, to ensure that all pipes are closed properly.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 96 def close_all_pipes @lock.synchronize do close_all_scheduled @pipe_fds.keys.each do |service_id| generations = @pipe_fds.delete(service_id) generations.values.each do |(r, w)| r.close w.close rescue IOError # Ignore any IOError that occurs when closing the # pipe, as there is nothing we can do about it. end end end end |
#generation(service_id: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 37 38 |
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 32 def generation(service_id: nil) validate_service_id!(service_id) @lock.synchronize do @map[service_id] end end |
#generation_unlocked(service_id: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 |
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 40 def generation_unlocked(service_id: nil) validate_service_id!(service_id) @map[service_id] end |
#pipe_fds(service_id: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 |
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 46 def pipe_fds(service_id: nil) @pipe_fds.dig(service_id, @map[service_id]) end |
#remove_pipe_fds(generation, service_id: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 50 def remove_pipe_fds(generation, service_id: nil) validate_service_id!(service_id) r, w = @pipe_fds[service_id].delete(generation) return unless r && w w.close # Schedule the read end of the pipe to be closed. We cannot close it # immediately since we need to wait for any Kernel#select calls to # notice that part of the pipe is closed, and check the socket. This # all happens when attempting to read from the socket and waiting for # it to become ready again. @scheduled_for_close << r end |