Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to Verify Updates?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike Craig  
View profile  
 More options Oct 9 2012, 6:01 pm
From: Mike Craig <mks...@gmail.com>
Date: Tue, 9 Oct 2012 15:00:28 -0700
Local: Tues, Oct 9 2012 6:00 pm
Subject: How to Verify Updates?

How can I verify that an update call actually updates a document?

So far I've tried using getN on the writeResult, but it sometimes returns 0
when a document was actually updated.

This is a sharded and replicated cluster (3 shards w/ 1 primary and 1
secondary each), and the application is highly parallel with lots of
updates to this collection.

Cheers,
Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jenna deBoisblanc  
View profile  
 More options Oct 10 2012, 3:07 pm
From: Jenna deBoisblanc <jenna.deboisbl...@10gen.com>
Date: Wed, 10 Oct 2012 12:07:20 -0700 (PDT)
Local: Wed, Oct 10 2012 3:07 pm
Subject: Re: How to Verify Updates?

Hello Mike,

How are you confirming that the document was updated when getN() returns 0?
Would it be possible to post one of the update commands in question, and
ideally, the results of getLastError()? Is it possible that multiple
threads are attempting to update the same document?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Craig  
View profile  
 More options Oct 10 2012, 4:08 pm
From: Mike Craig <mks...@gmail.com>
Date: Wed, 10 Oct 2012 13:07:19 -0700
Local: Wed, Oct 10 2012 4:07 pm
Subject: Re: [mongodb-user] Re: How to Verify Updates?

> How are you confirming that the document was updated when getN() returns

0?

The updates include both timestamps and datapoint-specific IDs. So I'll do
an update to DOC_ID with TIMESTAMP and DATA_ID, then get 0 from getN, and
then lookup DOC_ID and see TIMESTAMP and DATA_ID there anyway. I can verify
via our app logs that we're not processing the same DATA_ID multiple times
simultaneously (i.e. this is not a race condition amongst multiple
instances of the same DATA_ID).

> Would it be possible to post one of the update commands in question, and

ideally, the results of getLastError()?

This will require some logging changes.

> Is it possible that multiple threads are attempting to update the same

document?

Yes, that is the point here. Let me elaborate: there are many app threads
finding and then updating documents in the same mongo collection, so we use
a "persisted_at" timestamp to avoid overwrites. It looks something like
this (excuse my pseudocode; the actual app code doesn't lend itself to user
list emails):

    doc = coll.find({"_id":some_id})
    persisted_at = doc.persisted_at

    do_something(doc); // Do some work, update the document in memory
    doc.persisted_at = Time.now()

    result = coll.update({"_id":doc.id, "persisted_at":persisted_at},doc)

    if (result.getN() == 0)
        // Abort and retry because the update condition wasn't found

So in short, I'm trying to use conditional updates and getN() calls to
avoid losing data when two workers are updating a single document
simultaneously.

Mike

On Wed, Oct 10, 2012 at 12:07 PM, Jenna deBoisblanc <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jenna deBoisblanc  
View profile  
 More options Oct 11 2012, 2:40 pm
From: Jenna deBoisblanc <jenna.deboisbl...@10gen.com>
Date: Thu, 11 Oct 2012 11:40:12 -0700 (PDT)
Local: Thurs, Oct 11 2012 2:40 pm
Subject: Re: How to Verify Updates?

Hi Mike,

I want to confirm that I understand your question and observations; please
let me know if I am mistaken-
When you issue an update on a document, the server returns writeResult 0 to
the thread that performed the update. You can confirm that the thread is
responsible for the update because each thread has a unique DATA_ID.  Here
is my understanding of the situation in pseudocode:    

{code}
{_id: x, TIMESTAMP: t0, DATA_ID: d0}

doc = find({_id: x})
time = doc.TIMESTAMP = t0
do_something(doc)
doc = {_id: x, TIMESTAMP: t1, DATA_ID: d1}
result = coll.update({_id:x, TIMESTAMP: t0}, doc)

getN() returns 0
find({_id: x}) -> {_id:x, TIMESTAMP: t1, DATA_ID: d1}
{code}

If my understanding is correct, could you tell us what driver you're using?
Are you using writeResult.safe, or are you calling getLastError() manually?
Can you confirm that there's no way another thread could have been
responsible for this write- any chance the same DATA_ID is being used more
than once? Additional information about the way DATA_ID is generated would
be helpful.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic