Google是一个非关系数据库,它建立在最终一致性的概念之上.它还提供了一种通过祖先查询和实体组获得强一致性的方法。但是,在事务中使用祖先查询时,我没有获得很强的一致性。
考虑到这一点:
class Child(ndb.Model):
@classmethod
def create(cls):
child = cls()
child.put()
print Child.query().fetch()
Child.create()因为这没有使用实体组,所以它的操作最终是一致的。正如预期的那样,我们得到:
[]让我们使用实体组和祖先查询来尝试它:
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)这里我们得到了很强的一致性,因此输出如下:
[Child(key=Key('Parent', <id>, 'Child', <id>))]但是,当我们将一个事务放入混合中时:
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)产出如下:
[]考虑到翻译主要是用来处理祖先查询的(跨组标志甚至只是为了绕过这个需求而存在),为什么事务内部会失去很强的一致性呢?
发布于 2017-02-18 19:41:30
谷歌的docs 这里确实解决了你的最后一个例子:
与大多数数据库不同,Cloud事务中的查询和gets事务看不到该事务中以前写入的结果。具体来说,如果在事务中修改或删除了实体,则查询或get将返回事务开始时实体的原始版本,如果该实体当时不存在,则返回任何内容。
我无法比Google文档更好地解释这一点,但这是基于Google如何实现事务隔离的事务的预期行为。
https://stackoverflow.com/questions/42319537
复制相似问题