red*_*nce 5 python google-app-engine app-engine-ndb google-cloud-datastore google-cloud-platform
Google Cloud Datastore是一个非关系数据库,建立在最终一致性的概念之上.它还提供了一种通过祖先查询和实体组获得强一致性的方法.但是,在事务中使用祖先查询时,我没有获得强一致性.
考虑一下:
class Child(ndb.Model):
@classmethod
def create(cls):
child = cls()
child.put()
print Child.query().fetch()
Child.create()
Run Code Online (Sandbox Code Playgroud)
由于这不使用实体组,因此它最终具有一致性.正如所料,我们得到:
[]
Run Code Online (Sandbox Code Playgroud)
让我们使用实体组和祖先查询来尝试它:
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)
Run Code Online (Sandbox Code Playgroud)
这里我们得到了很强的一致性,所以输出是:
[Child(key=Key('Parent', <id>, 'Child', <id>))]
Run Code Online (Sandbox Code Playgroud)
但是,当我们将一个交易投入到混合中时:
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)
Run Code Online (Sandbox Code Playgroud)
输出是:
[]
Run Code Online (Sandbox Code Playgroud)
鉴于翻译主要用于祖先查询(跨组标志甚至存在只是为了绕过该要求),为什么在事务中丢失了强一致性?
归档时间: |
|
查看次数: |
498 次 |
最近记录: |