retry data store operation in case of an exception

154 views
Skip to first unread message

pac

unread,
Jul 18, 2010, 1:54:48 PM7/18/10
to objectify-appengine
Hi,
Do I have to re-try an data store operation in case of some exception?
But looking at this it seems, I dont have to:
http://groups.google.com/group/objectify-appengine/browse_thread/thread/8b6cb7fbbe804006/08f37e0a5167ceb5?lnk=gst&q=retry#08f37e0a5167ceb5

But in one example:
http://code.google.com/intl/pl/appengine/docs/java/datastore/transactions.html#What_Can_Be_Done_In_a_Transaction

Is that only applicable to transaction?

If I am just calling put then do I have to put in for loop? may be
there could be another error where data store is not available? some
thing like this?

for (int i = 0; i < NUM_RETRIES; i++)
{
try
{
objectifyDao.put(user);
break; //come out from loop
}
catch (DatastoreFailureException ex)
{
if (i == ( NUM_RETRIES - 1))
{
throw ex;
}
}
}

Thanks.

Jeff Schnitzer

unread,
Jul 18, 2010, 2:43:21 PM7/18/10
to objectify...@googlegroups.com
The answer to that is a little complicated.

The low-level API will always retry datastore timeout exceptions -
that's the change that was made in 1.3.1 that made the Objectify retry
code superfluous.

There is one other situation in which the datastore will perform
retries - that's when you are performing a put() *outside of a
transaction* and you get a concurrency error. What's actually
happening is that put()s outside of a transaction are actually run in
a separate mini-transaction, and there is a small risk that you will
have an optimistic concurrency failure during that transaction
(basically, someone will sneak a write in). The datastore will retry
this exception automatically until the write occurs. This retrying
will *not* happen when you commit a declared transaction - you will
get the concurrent modification exception (I don't recall offhand
exactly what that exception is, but the google documentation on
transactions spells it out).

AFAIK there are no other cases in which the datastore will retry
failures for you. Any other exception (including concurrency failures
in declared transactions) goes up to your code, and you must retry it
yourself - if it makes sense.

In your example, catching and retrying is not going to help.

Jeff

pac

unread,
Jul 18, 2010, 6:08:02 PM7/18/10
to objectify-appengine
Thanks Jeff, really appreciated the detail feedback.

On Jul 18, 7:43 pm, Jeff Schnitzer <j...@infohazard.org> wrote:
> The answer to that is a little complicated.
>
> The low-level API will always retry datastore timeout exceptions -
> that's the change that was made in 1.3.1 that made the Objectify retry
> code superfluous.
>
> There is one other situation in which the datastore will perform
> retries - that's when you are performing a put() *outside of a
> transaction* and you get a concurrency error.  What's actually
> happening is that put()s outside of a transaction are actually run in
> a separate mini-transaction, and there is a small risk that you will
> have an optimistic concurrency failure during that transaction
> (basically, someone will sneak a write in).  The datastore will retry
> this exception automatically until the write occurs.  This retrying
> will *not* happen when you commit a declared transaction - you will
> get the concurrent modification exception (I don't recall offhand
> exactly what that exception is, but the google documentation on
> transactions spells it out).
>
> AFAIK there are no other cases in which the datastore will retry
> failures for you.  Any other exception (including concurrency failures
> in declared transactions) goes up to your code, and you must retry it
> yourself - if it makes sense.
>
> In your example, catching and retrying is not going to help.
>
> Jeff
>
> On Sun, Jul 18, 2010 at 10:54 AM, pac <parvez.chau...@gmail.com> wrote:
> > Hi,
> > Do I have to re-try an data store operation in case of some exception?
> > But looking at this it seems, I dont have to:
> >http://groups.google.com/group/objectify-appengine/browse_thread/thre...
>
> > But in one example:
> >http://code.google.com/intl/pl/appengine/docs/java/datastore/transact...
Reply all
Reply to author
Forward
0 new messages