Strong transactional consistency in Google Cloud Datastore

Google Cloud Datastore is a non-relational database and is based on the concept of possible consistency . It also provides the means to ensure strong consistency through requests from ancestors and groups of objects . However, I do not get strong consistency when using ancestor queries in transaction .

Consider this:

class Child(ndb.Model): @classmethod def create(cls): child = cls() child.put() print Child.query().fetch() Child.create() 

Since this did not use an entity group, it works with a possible sequence. As expected, we get:

 [] 

Try using it with entity groups and ancestor query:

 class Parent(ndb.Model): pass class Child(ndb.Model): @classmethod def create(cls, parent): child = cls(parent=parent) child.put() print Child.query(ancestor=parent).fetch() parent = Parent().put() Child.create(parent) 

Here we get strong consistency, so the conclusion is:

 [Child(key=Key('Parent', <id>, 'Child', <id>))] 

However, when we translate the transaction into a mix:

 class Parent(ndb.Model): pass class Child(ndb.Model): @classmethod @ndb.transactional def create(cls, parent): child = cls(parent=parent) child.put() print Child.query(ancestor=parent).fetch() parent = Parent().put() Child.create(parent) 

Output:

 [] 

Given that translations are primarily designed to work with ancestral requests (a cross-group flag even exists only to circumvent this requirement), why does a strong consistency get lost inside a transaction?

+5
source share
1 answer

Google Docs here apply your last example:

Unlike most databases, queries and ends up in a cloud-based data warehouse transactions do not see the results of previous records within a transaction. In particular, if an object is modified or a transaction, request or receipt is deleted, it returns the original version to the beginning of the transaction, or nothing if the entity did not exist then.

I can’t explain it better than Google docs, but it’s intended behavior for transactions based on how Google implements transaction isolation.

+3
source

Source: https://habr.com/ru/post/1264392/


All Articles