top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How do I know I need to retry when use mongo C driver API?

+2 votes
64 views

Considering working with a shard replica-set cluster, some emergency such as re-pick primary node will happen and maybe we can retry the command several times for waiting for recover of mongo.

Is there anyone know when use c driver api such as mongoc_collection_update, mongoc_collection_commond, mongoc_collection_insert, which error codes tell me that I can retry command for making the application more robust.

posted Sep 13, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

Generally, you can retry idempotent operations once. Please see my MongoDB World talk on how MongoDB drivers implement high availability and failover:

https://www.mongodb.com/presentations/mongodb-drivers-and-high-availability-deep-dive

The talk applies equally to how mongos implements high availability and failover, which is the relevant question in a sharded cluster. Towards the end of the talk I give a reasonable strategy for implementing retries of queries, inserts, updates, and deletes.

For the C Driver specifically, the MONGOC_ERROR_QUERY and MONGOC_ERROR_COMMAND domains imply a server-side rejection of your operation which cannot be successfully retried. However, since you're connecting through mongos, mongos may experience a network disconnect or an unavailable primary when talking to your replica sets—in this case, the error will appear to you as a QUERY / COMMAND error even though it's really a network error between mongos and mongod. I'll wait for someone from the MongoDB server team to chime in with a strategy for distinguishing those errors.

MONGOC_ERROR_COMMAND with a code of 11000 means a duplicate key error, which you can use to determine if the first try of an insert operation succeeded before a network error.

MONGOC_ERROR_CLIENT means a network error. Idempotent operations can be usefully retried one time after a network error. Starting in version 1.2, MONGOC_ERROR_SERVER_SELECTION will also be retryable.

answer Dec 15, 2015 by Manikandan J
Similar Questions
+2 votes

I use the mongo c driver to operate the mongodb, I just wonder if the driver has the function of auto re-connection? And if I use a mongodb cluster with three shards, how can I connect all of the Mongos? And how can I do to switch to another mongos when i am using one of the mongos to operate the DB?

Any help is welcome.

0 votes

I am trying to figuring out how to use $sample through the driver.
I know that there is the functionality, I just failed to comprehend how to use it...

+1 vote

With the non-blocking asynchronous mongo java/scala driver, it is possible to define a wait time and a wait queue size for operations that cannot be executed directly with a free connection. When settings these values, the mongo driver will make the threads waiting for an available connection.

This behavior is very dangerous for an application written with non-blocking asynchronous IO in mind. These applications use a very limited number of threads (= numbers of cores). Blocking one of these thread can block the whole application.

What would be the recommended way to for this kind of applications? Should we set all these waiting settings to 0 and handle MongoWaitQueueFullException with retries in the application? Should the driver call an application callback when a connection is free?

0 votes

Can we use mongo recommended snapshot i.e LVM snapshot across versions? i.e snapshot taken from v2.4.10 and restore it to v3.0.4.
We have tested the same and this works. Is this recommended by mongo?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...