Initialize the hash mapping connections to shards, and turn on logging of connection info unless it has specifically been turned off.
# File lib/sequel/extensions/server_logging.rb, line 30 def self.extended(db) db.instance_exec do @server_connection_map ||= {} self.log_connection_info = true if log_connection_info.nil? end end
When setting up a new connection, associate the connection with the shard.
# File lib/sequel/extensions/server_logging.rb, line 39 def connect(server) conn = super Sequel.synchronize{@server_connection_map[conn] = server} conn end
When disconnecting a connection, remove the related connection from the mapping.
# File lib/sequel/extensions/server_logging.rb, line 46 def disconnect_connection(conn) super ensure Sequel.synchronize{@server_connection_map.delete(conn)} end