Should I be retrying "Could not get last error from a shard" errors?

42 views
Skip to first unread message

Jon

unread,
Aug 1, 2014, 5:41:55 PM8/1/14
to mongod...@googlegroups.com
We just did a stepDown and one of my writes failed with error "could not get last error from a shard" caused by "DBClientBase::findN: transport error". I unfortunately don't have the insert statement logged to a file so I don't know exactly what the content of the write was. How should I handle these errors? I'm not sure if replaying the database call makes sense because it could insert duplicate rows, but also I don't want to lose data.

Asya Kamsky

unread,
Aug 1, 2014, 6:24:41 PM8/1/14
to mongodb-user
Jon,

This is a common challenge when you are writing things to the database - and that's not limited to MongoDB either, since you can hit a network error or some other "transient" error completing an insert into any backend system.

First thing would be to always catch and exception and do the "appropriate" thing with the document you were inserting.  Now, what is that "thing" - well, it depends on a few things - how safe is it to retry, whether you have ability to surface the error back to the application (and whether it would be able to take correct action at this point), etc.   You should always have unique constraints on the fields that should not be duplicated (that may make it safe to just try to insert again).

In any case, you should probably log a detailed error and write the object you were trying to persist either in the logs or in another location where you can take appropriate action - even if it's just to post-mortem what happened.

Btw, I always assume this is what happens when I get an error from some site or application that says "Success of your <whatever> could not be determined, please check the status <in some other screen> and retry if appropriate" (instead of "Error saving <xyz> please try again later").

Asya




On Fri, Aug 1, 2014 at 5:41 PM, Jon <hyma...@gmail.com> wrote:
We just did a stepDown and one of my writes failed with error "could not get last error from a shard" caused by "DBClientBase::findN: transport error". I unfortunately don't have the insert statement logged to a file so I don't know exactly what the content of the write was. How should I handle these errors? I'm not sure if replaying the database call makes sense because it could insert duplicate rows, but also I don't want to lose data.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/6d72d0d8-d856-4311-90c2-87dd5989db7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages