我是Google CloudDatastore的新用户并正在阅读文档 (注意:我们不打算只使用Google AppEngine,只使用DataStore。)
根据document,DataStore支持事务,但
If you want to use queries within a transaction,
your data must be organized into entity groups in such a way
that you can specify ancestor filters that will match the right data.
所以我想只要我想使用事务,我就不得不创建一些父键并将其设置为祖先。父母下的所有实体都有一个限制,即更新和交易每秒只能执行一次。
但是,我在这里也看到了一个非常简单的插入示例: https://cloud.google.com/datastore/docs/concepts/entities#datastore-insert-python
with client.transaction():
incomplete_key = client.key('Task')
task = datastore.Entity(key=incomplete_key)
task.update({
'category': 'Personal',
'done': False,
'priority': 4,
'description': 'Learn Cloud Datastore'
})
client.put(task)
它没有指定父级并在事务中使用单个根实体,是吗?即使是Transaction page中的示例,只有“只读事务”中的示例才明确指定父项。其他人只是在实际存在的情况下省略父母吗?
我想知道我可以使用没有实体组的事务(=没有大的性能降低),如果我可以指定根实体的密钥,但文档中没有这样的描述......
如果有人能澄清这种行为,我会很感激。感谢。
答案 0 :(得分:2)
Transactions across multiple entity groups is indeed allowed (with a limit of 25 entity groups per documentation)
If you want to use queries within a transaction,
Note this key sentence in the text you quoted. It is saying any 'queries' you want to issue inside of a transaction need to be ancestor queries. This is because non-ancestor queries are eventually consistent, so it would be impossible for the transaction engine to reason about any state changes and hence not know when to fail or succeed the transaction. It is not saying you cannot to do transactions across entity groups.
It doesn't specify a parent and use a single root entity inside a transaction, does it ?
I think this is the other source of confusion. Only children entities have parents specified to denote which entity group they are in. When no parent is specified, then the entity in question is a root entity (it's parent is root). Another way of saying this is every root entity is it's own entity group.
答案 1 :(得分:0)
从技术上讲,您的描述中的任务实体即使没有子实体也构成实体组。允许的最大实体组数为25,因此如果您尝试使用此模式创建超过25个顶级实体,则查询将失败。
我避免性能命中的方法是使用多个实体组。我构建了我的数据存储区,以便我有多个根实体并尝试限制实体组中的多个事务。