Optimistic Transactions Google Datastore Concurrency Control or Not?

The questions are pretty simple.

Are Datastore Concurrency datastore transactions optimistic or not?

One part of the documentation says:

When a transaction starts, App Engine uses an optimistic Concurrency control by checking the latest update times for the entity groups used in the transaction. After a transaction is committed for entity groups, App Engine again checks the latest update time for the entity groups used in the transaction. If it has changed since our initial check, an exception is thrown. Source

Another piece of documentation indicates that this is not the case:

When a transaction is started, the datastore rejects any other write attempts to this object group until the transaction completes. To illustrate this, let's say you have an entity group made up of two entities, one at the root of the hierarchy and the other immediately below it. If these objects belong to separate groups of entities, they can be updated in parallel. But since they are part of the same entity group, any query trying to update one of the entities will necessarily prevent a concurrent request to update any other entity in the same group until the original request is complete. Source

As I understand it, the first quote tells me that it is ok to start a transaction, read an object, and ignore closing the transaction if I see no reason to update the object.

The second quote tells me that if I start a transaction and read an entity, then I must always remember to close it, otherwise I cannot start a new one in the same entity.

Which part of the documentation is correct?

BTW. In case the correct quote is the second, I use Objectify to handle all of my transactions. Will this not remember all started transactions, although no changes were made?

+3


source to share


1 answer


(Greg's) comment is correct. If you explicitly close a transaction, all transactions are closed by the container at the end of the request. You cannot "leak" transactions (although you can mess up transactions within a single request).

Also, when using the Objectify Transaction API, transactions are automatically opened and closed for you when you execute a block Work

. You do not manage transactions yourself.



To answer your question with a root: Yes, all transactions in the GAE datastore are optimistic. There is no pessimistic lock in the store; you can start as many transactions as you like on the same entity group, but only the first commit will be successful. All subsequent commit attempts will be rolled back with ConcurrentModificationException

.

+4


source







All Articles