【发布时间】:2017-07-08 06:07:27
【问题描述】:
Google Cloud Datastore 是一个非关系型数据库,基于 eventual consistency 的概念构建。它还提供了一种通过ancestor queries and entity groups 获得强一致性的方法。但是,在 transaction 中使用祖先查询时,我没有获得强一致性。
考虑一下:
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)
输出是:
[]
鉴于翻译主要用于处理祖先查询(跨组标志甚至只是为了绕过该要求而存在),为什么在事务中会丢失强一致性?
【问题讨论】:
标签: python google-app-engine google-cloud-platform google-cloud-datastore app-engine-ndb