In what order newly created documents become visible to other processes?

181 views
Skip to first unread message

Ev Kont

unread,
Feb 21, 2011, 3:25:25 AM2/21/11
to mongodb-user
Hey guys, here's a question I'm unable to find an answer for in the
documentation.

Assume I have a document which *always* has "attachment" property,
which is some raw data almost always larger than 4MB therefore it
needs to be stored in GridFS.

Before a document D is created, it creates an attachment file in
GridFS, keeps the file_id, and only then the actual document D is sent
to Mongo.

But what happens is that other process (I have 4 machines with 6
processes on each accessing these) sometimes grabs the document but
can't locate the attachment. How is that possible? Attachments are
sent first!

Here's an example (extracted code): http://paste.ofcode.org/4PbhTnGFzmzztm7xtKv9AG

Kyle Banker

unread,
Feb 21, 2011, 9:18:54 AM2/21/11
to mongod...@googlegroups.com
Are you sure that the attachment is actually being written? Does it
eventually appear?

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Ev Kont

unread,
Feb 21, 2011, 2:35:26 PM2/21/11
to mongodb-user
Almost sure, yes. When this happens (message is unable to load its
attachment) - we kill that message. And the collection of attachments
outgrows the collection of messages, despite that there's 1-to-1
relationship. So yes, those "lost attachments" do show up.

Eliot Horowitz

unread,
Feb 21, 2011, 2:52:32 PM2/21/11
to mongod...@googlegroups.com
If you do writes over the same socket, then reads over the same
socket, its guaranteed to be in serial order.
If they are done over different sockets, then you have to call
getLastError to guarantee its finished.

Eliot Horowitz

unread,
Feb 21, 2011, 5:46:29 PM2/21/11
to mongod...@googlegroups.com
Yes, that is also a possibility.

On Mon, Feb 21, 2011 at 5:45 PM, Andrew Armstrong <phpl...@gmail.com> wrote:
> Writing (which needs to go to the primary) and then trying to read
> from slaves (slaveOk() query) would also have a chance of not picking
> up the recently saved document I would imagine (since the replica
> slave you're reading from may be behind by a few ms and not yet
> received the write from the primary).
>
> So either you need to write and then read from the primary (dont use
> slaveOk()) or perhaps getLastError(w: <amount of slaves + 1>) to
> ensure the document was written on all slaves too, before then trying
> a slaveOk query.
>
> Does that sound right Eliot?

Andrew Armstrong

unread,
Feb 21, 2011, 5:45:44 PM2/21/11
to mongodb-user
Writing (which needs to go to the primary) and then trying to read
from slaves (slaveOk() query) would also have a chance of not picking
up the recently saved document I would imagine (since the replica
slave you're reading from may be behind by a few ms and not yet
received the write from the primary).

So either you need to write and then read from the primary (dont use
slaveOk()) or perhaps getLastError(w: <amount of slaves + 1>) to
ensure the document was written on all slaves too, before then trying
a slaveOk query.

Does that sound right Eliot?

On Feb 22, 6:52 am, Eliot Horowitz <eliothorow...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages