Skip to content

Commit

Permalink
Implement reaping for lb
Browse files Browse the repository at this point in the history
  • Loading branch information
comandeo-mongo committed Aug 14, 2024
1 parent 2526fb6 commit 5cc14a1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions gemfiles/standard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def standard_dependencies
gem 'tilt'
# solargraph depends on rbs, which won't build on jruby for some reason
gem 'solargraph', platforms: :mri
gem 'ruby-lsp', platforms: :mri
end

gem 'libmongocrypt-helper', '~> 1.8.0' if ENV['FLE'] == 'helper'
Expand Down
7 changes: 6 additions & 1 deletion lib/mongo/cluster/reapers/cursor_reaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ def kill_cursors
server_api: server.options[:server_api],
connection_global_id: kill_spec.connection_global_id,
}
op.execute(server, context: Operation::Context.new(options: options))
if connection = kill_spec.connection
op.execute_with_connection(connection, context: Operation::Context.new(options: options))
connection.connection_pool.check_in(connection)
else
op.execute(server, context: Operation::Context.new(options: options))
end

if session = kill_spec.session
if session.implicit?
Expand Down
7 changes: 5 additions & 2 deletions lib/mongo/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ def initialize(view, result, server, options = {})
check_in_connection
else
register
ObjectSpace.define_finalizer(self, self.class.finalize(kill_spec(@connection_global_id),
cluster))
ObjectSpace.define_finalizer(
self,
self.class.finalize(kill_spec(@connection_global_id), cluster)
)
end
end

Expand Down Expand Up @@ -406,6 +408,7 @@ def kill_spec(connection_global_id)
connection_global_id: connection_global_id,
server_address: server.address,
session: @session,
connection: @connection
)
end

Expand Down
7 changes: 5 additions & 2 deletions lib/mongo/cursor/kill_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,25 @@ def initialize(
db_name:,
connection_global_id:,
server_address:,
session:
session:,
connection: nil
)
@cursor_id = cursor_id
@coll_name = coll_name
@db_name = db_name
@connection_global_id = connection_global_id
@server_address = server_address
@session = session
@connection = connection
end

attr_reader :cursor_id,
:coll_name,
:db_name,
:connection_global_id,
:server_address,
:session
:session,
:connection

def ==(other)
cursor_id == other.cursor_id &&
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/cursor_reaping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
let(:subscriber) { Mrss::EventSubscriber.new }

let(:client) do
authorized_client.tap do |client|
authorized_client.with(max_pool_size: 10).tap do |client|
client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
end
Expand Down

0 comments on commit 5cc14a1

Please sign in to comment.