是否应该编写实体以确保不重复使用自动分配的 ID?
Should an entity be written to ensure auto allocated ids are not reused?
我在其下有用户实体组和交易实体。我为交易自动分配 ID。我想创建与支付服务集成的唯一密钥。由于交易不是根实体,因此不能保证自动分配的 ID 是唯一的,因此我不能将它们用作唯一键。我目前正在按照
上的建议进行操作
是拥有一个虚拟根实体并为其分配 id,并将该 id 与交易实体一起存储为一个单独的字段。但是,由于它是虚拟的,我目前没有将虚拟实体本身写入数据存储。
我已阅读其他帖子
和
Are deleted entity IDs once again available to App Engine if auto-generated for an Entity?
但我还是不确定。我是否必须只用密钥插入这个虚拟实体?如果不是,如何跟踪此虚拟实体的所有分配 ID 以及相应的存储使用情况如何?
一个实体密钥 ID,连同种类和祖先(可能还有命名空间)定义了一个唯一的实体密钥,这是 有意义的 即使实体实际上没有存在:实体组祖先中的子实体可能附加到不存在的祖先。来自 Ancestor paths(强调我的):
When you create an entity, you can optionally designate another entity
as its parent; the new entity is a child of the parent entity (note
that unlike in a file system, the parent entity need not actually
exist).
因此,您的虚拟实体实际存在与否并不重要:使用 allocateIds()
的密钥 ID pre-allocated 永远不会过期。来自 Assigning identifiers:
Datastore mode's automatic ID generator will keep track of IDs that
have been allocated with these methods and will avoid reusing them for
another entity, so you can safely use such IDs without conflict. You
can not manually choose which values are returned by the
allocateIds()
method. The values returned by allocateIds()
are
assigned by Datastore mode.
支持此观点的个人考虑:
- 数据存储对同类实体、祖先实体和命名空间的数量没有限制,因此它应该支持几乎无限数量的唯一 ID。恕我直言,这意味着甚至不需要考虑 re-using 它们。这可能就是为什么没有提及分配 ID 的任何截止日期或到期时间的原因。
- 如果删除的实体的 ID 将被重复使用,那么从备份中恢复数据存储实体将引发重大问题 - 可能会用以前使用相同 ID 的实体覆盖具有 re-used ID 的新实体
我在其下有用户实体组和交易实体。我为交易自动分配 ID。我想创建与支付服务集成的唯一密钥。由于交易不是根实体,因此不能保证自动分配的 ID 是唯一的,因此我不能将它们用作唯一键。我目前正在按照
上的建议进行操作是拥有一个虚拟根实体并为其分配 id,并将该 id 与交易实体一起存储为一个单独的字段。但是,由于它是虚拟的,我目前没有将虚拟实体本身写入数据存储。
我已阅读其他帖子
和
Are deleted entity IDs once again available to App Engine if auto-generated for an Entity?
但我还是不确定。我是否必须只用密钥插入这个虚拟实体?如果不是,如何跟踪此虚拟实体的所有分配 ID 以及相应的存储使用情况如何?
一个实体密钥 ID,连同种类和祖先(可能还有命名空间)定义了一个唯一的实体密钥,这是 有意义的 即使实体实际上没有存在:实体组祖先中的子实体可能附加到不存在的祖先。来自 Ancestor paths(强调我的):
When you create an entity, you can optionally designate another entity as its parent; the new entity is a child of the parent entity (note that unlike in a file system, the parent entity need not actually exist).
因此,您的虚拟实体实际存在与否并不重要:使用 allocateIds()
的密钥 ID pre-allocated 永远不会过期。来自 Assigning identifiers:
Datastore mode's automatic ID generator will keep track of IDs that have been allocated with these methods and will avoid reusing them for another entity, so you can safely use such IDs without conflict. You can not manually choose which values are returned by the
allocateIds()
method. The values returned byallocateIds()
are assigned by Datastore mode.
支持此观点的个人考虑:
- 数据存储对同类实体、祖先实体和命名空间的数量没有限制,因此它应该支持几乎无限数量的唯一 ID。恕我直言,这意味着甚至不需要考虑 re-using 它们。这可能就是为什么没有提及分配 ID 的任何截止日期或到期时间的原因。
- 如果删除的实体的 ID 将被重复使用,那么从备份中恢复数据存储实体将引发重大问题 - 可能会用以前使用相同 ID 的实体覆盖具有 re-used ID 的新实体