Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Failover does not work properly when primary and secondary switched #268

@rakusai

Description

@rakusai

Option :
read: master

When master and secondary has been switched (not down), Moped throw the error for 5 minutes (default refresh time) and failover does not work properly.

Throw Moped::Error::QueryFailure not master 

This situation happens:

  1. each replicaset node has priority.
  2. the master went down so secondary became the new primary.
  3. when old master is live again, then old master become master again (mongo switches master and secondary automatically).

I think we can fix this by adding Errors::QueryFailure, reconfiguring_replica_set hook in with_retry (in read_preference/selectable.rb)

      def with_retry(cluster, retries = cluster.max_retries, &block)
        begin
          return block.call
        rescue Errors::ConnectionFailure => e
          raise e unless retries > 0
        rescue Errors::QueryFailure => e
          raise e unless retries > 0 && e.reconfiguring_replica_set?
        end

        Loggable.warn("  MOPED:", "Retrying connection attempt #{retries} more time(s).", "n/a")
        sleep(cluster.retry_interval)
        cluster.refresh
        with_retry(cluster, retries - 1, &block)
      end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions