moped icon indicating copy to clipboard operation
moped copied to clipboard

Moped won't retry write operations when primary went down (failover)

Open rakusai opened this issue 11 years ago • 2 comments

I noticed that max_retries or retry_interval will only work with read operations and write operations will not be retried even when primary node is dead. souce

Even when the master went down and other secondary become new primary in the replica set, node info will never be refreshed. Insert, update, remove commands keep throwing error for 5 minutes REFRESH_INTERVAL Is this expected behavior?

Only when the read option is primary, the read will also fail and the node info will be refreshed immediately. To reproduce this bug, read option needs to be primary_preferred, secondary, secondary_preferred, or nearest.

rakusai avatar Mar 19 '14 16:03 rakusai

Here is part of solutions for this issue:

https://github.com/mongoid/moped/blob/master/lib/moped/query.rb#L389

def update(change, flags = nil)
     with_retry(cluster) do # add this to retry write operations when primary is down.
       cluster.with_primary do |node|
        node.update(
          operation.database,
          operation.collection,
          operation.selector["$query"] || operation.selector,
          change,
          write_concern,
          flags: flags
        )
      end
    end
end

rakusai avatar Mar 19 '14 16:03 rakusai

This is fixed in #352

mateusdelbianco avatar Feb 13 '15 19:02 mateusdelbianco