simplybusiness/moped — pull request #2 by dawid-sklodowski (2014-09-09 09:28:18+00:00)
Title: Retry on writes

@simplybusiness/developers

This is our internal pull-request to fix moped failover so we can comment before we make pull-request to upstream repository.

It does couple of things:

* Refactoring: Moves with_retry method to Cluster -- it belongs there as it operates on cluster.
* Introduce retries on write operations -- it makes sense, because:
* Update is idempotent
* Delete is idempotent (deletes rows which are matching query)
* Insert -- in worse case scenario we could end up with duplicated data, however given that moped is used by mongoid, which inserts rows always with _id already present, therefore such duplicated insert will raise unique index on _id violation, which is fine.
* Fixes failover mechanism -- Node#ensure_connected was written in a way that failover didn't take into account messages after doing some operations (insert for example) ( processing of DB replies by callbacks was outside of begin-rescue block), therefore failover mechanism was not exercised in most cases it was meant for.
* Removes ``` Reconfigure ``` failover mechanism -- it was raising exceptions not used anywhere else (and not retrying) -- it should good enough to just retry.
* Refactoring: Move recognition mechanism for some errors from ``` Errors ``` class -- to ``` Reply ``` class, so errors recognition is in one place.
* Fixes refresh mechanism -- if node was successfully refresh it isn't down any more.
* Reorganises Errors class and adds new types of errors
* Some other refactorings.