thephpleague / monga

Simple and swift MongoDB abstraction.
MIT License
331 stars 30 forks source link

Retry on master write failure #8

Closed auroraeosrose closed 9 years ago

auroraeosrose commented 9 years ago

Silly github lost the rest!

Recovering failed connections with replicasets and failover is fairly easy to centralize

But there can be some pretty crazy latency with the rediscovery. If the driver connects to a secondary and later tries a write it will fail.

In this case the write should really be retried. Sure you could do this by wrapping monga in another class (sigh) but it would be far more elegant to simply catch MongoCursorExceptions and look for the "not master" failure for inserts/saves and retry

bcrowe commented 9 years ago

Sounds reasonable to me. I can take a look into this later this evening, or feel free to open a PR yourself if you wish.

bcrowe commented 9 years ago

Closed via https://github.com/thephpleague/monga/commit/d6578845d19b0bd26265d2b4108bbe2e6cb07109 and https://github.com/thephpleague/monga/commit/da2bf8254c3a97e6b9163ff616daae1063b5a2ee.

auroraeosrose commented 9 years ago

Awesome! Thanks!