Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is exactly meant by "fire and forget" write in MongoDB

Tags:

mongodb

MongoDB has a write mechanism of fire and forget. But does this guarantee that my writes will be written to disk eventually? So if i have a statement like this(in pymongo)

collection.insert(doc)     #not passing safe=True

I understand that my write in above statement will not immediately reach the disk but is there a guarantee that it would ever reach the disk(maybe the next day or a week later) or can it get lost and never come back. My application needs dont want the writes to be done synchronously but they want the writes to happen even if its hours later.

like image 360
lovesh Avatar asked Jul 19 '12 15:07

lovesh


2 Answers

AFAIK Fire and Forget has no guarantees - if you need them then use safe [that's what it is there for!]

See How safe is MongoDB's safe mode on inserts?

like image 23
NPSF3000 Avatar answered Oct 13 '22 00:10

NPSF3000


The meaning of "fire and forget" (aka the default writes of MongoDB) is that the driver will not confirm the write with the server. Your write is placed on the network, the driver confirms it reaches the network transport but past that no other checking is performed.

As long as the server & network is up, it is expected the write will succeed. However, this also means you won't find out about issues such as violating a unique index.

Writes initially occur in memory, and are flushed to disk at least every 60 seconds. If you have journalling turned on, the write will get into the journal within 100 ms – this journal can recover in case of a crash upon mongod restarting.

If you want to verify that a write has made it to mongod and successfully been applied in memory, you should set safe=True

like image 102
Brendan W. McAdams Avatar answered Oct 12 '22 23:10

Brendan W. McAdams