Moped won't retry write operations when primary went down (failover)
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.
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
This is fixed in #352