删除 jdo 后是否重用 IdGeneratorStrategy.Identity 值
我正在使用谷歌应用程序引擎。
如果 IdGeneratorStrategy.Identity 生成 Long 键字段,然后从数据存储中删除该对象,该键是否有可能被同一类的不同对象再次使用?
reddit 上的 papercrane 写道:
<块引用>文档 GenerationType.IDENTITY 说它 表示持久性提供者( 数据库)将提供唯一的 ID。 所以这完全取决于你的数据库 软件(如果决定重用 ID) 从已删除的记录中。不知不觉中 关于你的问题的任何其他问题我都会 说这是可能的,但我想不出来 任何使用数据库的充分理由 服务器跟踪哪些 ID 使用中并回收旧的。那 似乎有很多开销 好处不大。
马克·罗斯 (Mark Ross) 在 Google 网上论坛上写道 关于如何生成 GAE 身份:
<块引用>由于产品中的数据存储是 由多个后端组成,我们 使用分片计数器方法来领取救济金 出ID,这样我们就不用担心 关于不同的后端分发 相同的 ID。所以,后端A可能是 从一系列 ID 中工作 从 0 到 100,后端 B 可能是 从一系列 ID 中工作 从 101 到 200,依此类推。如果你的 插入命中不同的数据存储 后端你会得到跳转的ID 大约一点。你可以依赖这些 ID 是唯一的,但不是 单调递增。
我现在认为身份值不太可能被重用,但有一个明确的答案仍然是件好事。
I'm using Google App Engine.
If a Long key field is generated by IdGeneratorStrategy.Identity and then the object is deleted from the datastore, is there any chance of the key being used again by a different object of the same class?
papercrane on reddit writes:
The documentation for
GenerationType.IDENTITY says that it
means the persistence provider (the
database) will provide the unique ID.
So it is entirely up to your database
software if it decides to reuse IDs
from deleted records. Without knowing
anything else about your problem I'd
say it is possible, but I can't think
of any good reason for a database
server to keep track of which IDs are
in use and recycle old ones. That
seems like a lot of overhead for very
little benefit.
And Mark Ross on Google Groups writes
on how GAE identities are generated:Since the datastore in prod is
comprised of multiple back-ends, we
use a sharded counter approach to dole
out IDs so that we don't have to worry
about different back-ends handing out
the same id. So, back-end A may be
working from a pool of IDs ranging
from 0 to 100 and back-end B may be
working from a pool of IDs ranging
from 101 to 200, and so on. If your
inserts hit different datastore
back-ends you'll get IDs that jump
around a bit. You can depend on these
IDs being unique, but not
monotonically increasing.
I now think that it is very unlikely that Identity values are reused but it would still be good to have a clear definitive answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
App Engine 绝不会重复使用给定种类和父级的 ID。事实上,我认为你很难找到一个数据库可以做到这一点 - 保持一个简单的计数器比试图找出哪些 ID 仍在使用中要简单得多,而且对于 64 位,你不会身份证用完了。
App Engine will never reuse IDs for a given kind and parent. In fact, I think you'll be hard pressed to find a database that does - keeping a simple counter is far, far simpler than trying to figure out which IDs are still in use, and with 64 bits, you're not going to run out of IDs.