Skip to content

Conversation

@petergebala
Copy link
Contributor

Hi,

Code there is quite complex I am not 100% convinced that my solution is correct.

        def fresh_cluster_composition_fetched(composition_lookup_result)
          @log.debug("Fetched cluster composition for database '#{@database_name.description}'. #{composition_lookup_result.cluster_composition}")
          @routing_table.update(composition_lookup_result.cluster_composition)
          @routing_table_registry.remove_aged
          addresses_to_retain = @routing_table_registry.all_servers.map(&:unicast_stream).reduce(&:+)

          composition_lookup_result.resolved_initial_routers&.then do |addresses|
            addresses_to_retain << addresses
          end

          @connection_pool.retain_all(addresses_to_retain)

          @log.debug("Updated routing table for database '#{@database_name.description}'. #{routing_table}")
          @routing_table
        rescue => error
          cluster_composition_lookup_failed(error)
        end

I think problem is with << method here. Looks like both lines:

@routing_table_registry.all_servers.map(&:unicast_stream).reduce(&:+)
composition_lookup_result.resolved_initial_routers

Return a Set:

irb(main):152> composition_lookup_result.resolved_initial_routers
=> #<Set: {#<Neo4j::Driver::Internal::BoltServerAddress:0x00007f39d5a8eb78 @connection_host="XXXXXX", @host="XXXXXX", @port=7687>}>
irb(main):153> ActiveGraph::Base.driver.session_factory.connection_provider.routing_table_registry.all_servers.map(&:unicast_stream).reduce(&:+)
=>
#<Set:
 {#<Neo4j::Driver::Internal::BoltServerAddress:0x00007f39d00503a0 @connection_host="XXXXXX", @host="XXXXXX", @port=7687>,
  #<Neo4j::Driver::Internal::BoltServerAddress:0x00007f39d0050080 @connection_host="XXXXXX", @host="XXXXXX", @port=7687>,
  #<Neo4j::Driver::Internal::BoltServerAddress:0x00007f39d0050710 @connection_host="XXXXXX", @host="XXXXXX", @port=7687>}>

By using << you create nested structure:

irb(main):001> a = Set.new
=> #<Set: {}>
irb(main):002> b = Set.new
=> #<Set: {}>
irb(main):003> a << 1
=> #<Set: {1}>
irb(main):004> b << 2
=> #<Set: {2}>
irb(main):005> a << b
=> #<Set: {1, #<Set: {2}>}>

Where we expect there probably sth more like:

irb(main):001> a = Set.new
=> #<Set: {}>
irb(main):002> b = Set.new
=> #<Set: {}>
irb(main):003> a << 1
=> #<Set: {1}>
irb(main):004> b << 2
=> #<Set: {2}>
irb(main):005> a.merge(b)
=> #<Set: {1, 2}>
irb(main):006> a
=> #<Set: {1, 2}>
irb(main):007> b
=> #<Set: {2}>

Having nested set later fails in comparison in here:

addresses_to_retain.include?(address)

@address_to_pool.each do |address, pool|
unless addresses_to_retain.include?(address)
unless pool.busy?

Which later uses == method:

def ==(other)
attributes == other&.attributes
end

If we have there nested Sets Neo4j Driver throws exceptions like:
image

Should solve issue: #220

@klobuczek
Copy link
Member

Thank you Piotrek. Before we release this we need to fix the failing specs, which I know are not due to your change. Do you have any spare time you could dedicate to open source? I promise it would be extremely educative.

@klobuczek klobuczek merged commit 8c0262a into neo4jrb:4.4 Oct 11, 2024
7 of 34 checks passed
@petergebala
Copy link
Contributor Author

Hi @klobuczek . Sure, I can help. I will have a look at failing specs and try to fix it. If you have anything else that needs attention, please let me know.

@klobuczek
Copy link
Member

@petergebala could you have another look at your PR. I think we all missed the fact that the error might have been resolved but the code is not doing what was intended.
The result of the merge is not used. I think it should be merge! to achieve the intended outcome.
CC: @nsauk @JuliaKovtun

@petergebala
Copy link
Contributor Author

@klobuczek, very likely you are right. I am on PTO till 12th May (don't have access to computer). I will fix it once I return.

@petergebala
Copy link
Contributor Author

I asked a friend to check. Looks like merg works as well:
image

What is more patched version we were using in production for months without any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants