123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Server::ConnectionPool::GenerationManager Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/server/connection_pool/generation_manager.rb

Overview

Since:

  • 2.0.0, largely rewritten in 2.9.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#server (readonly)

Since:

  • 2.0.0, largely rewritten in 2.9.0

[ GitHub ]

  
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 33

attr_reader :server

Instance Method Details

#bump(service_id: nil)

Since:

  • 2.0.0, largely rewritten in 2.9.0

[ GitHub ]

  
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 66

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_scheduled (private)

Close all fds scheduled for closing.

Since:

  • 2.0.0, largely rewritten in 2.9.0

[ GitHub ]

  
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 107

def close_all_scheduled
  while pipe = @scheduled_for_close.pop
    pipe.close
  end
end

#generation(service_id: nil)

Since:

  • 2.0.0, largely rewritten in 2.9.0

[ GitHub ]

  
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 35

def generation(service_id: nil)
  validate_service_id!(service_id)

  @lock.synchronize do
    @map[service_id]
  end
end

#generation_unlocked(service_id: nil)

Since:

  • 2.0.0, largely rewritten in 2.9.0

[ GitHub ]

  
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 43

def generation_unlocked(service_id: nil)
  validate_service_id!(service_id)

  @map[service_id]
end

#pipe_fds(service_id: nil)

Since:

  • 2.0.0, largely rewritten in 2.9.0

[ GitHub ]

  
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 49

def pipe_fds(service_id: nil)
  @pipe_fds[service_id][@map[service_id]]
end

#remove_pipe_fds(generation, service_id: nil)

Since:

  • 2.0.0, largely rewritten in 2.9.0

[ GitHub ]

  
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 53

def remove_pipe_fds(generation, service_id: nil)
  validate_service_id!(service_id)

  r, w = @pipe_fds[service_id].delete(generation)
  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

#validate_service_id!(service_id) (private)

Since:

  • 2.0.0, largely rewritten in 2.9.0

[ GitHub ]

  
# File 'lib/mongo/server/connection_pool/generation_manager.rb', line 94

def validate_service_id!(service_id)
  if service_id
    unless server.load_balancer?
      raise ArgumentError, "Generation scoping to services is only available in load-balanced mode, but the server at #{server.address} is not a load balancer"
    end
  else
    if server.load_balancer?
      raise ArgumentError, "The server at #{server.address} is a load balancer and therefore does not have a single global generation"
    end
  end
end