保证新实体的数字自动递增ID总是大于现有ID? [英] Is it guaranteed that numeric auto-incremented ID of new entity always bigger than existing IDs?
问题描述
是否保证新实体的自动递增ID总是大于现有ID?
基本上我想定期将后台任务中的实体(例如Comment)转储到所以如果现在有100个实体,我会将它们存储在blob中,并为这个blob创建助手实体,比如
class BlobRange
{
long fromId; // Comment.id
long toId; // Comment.id
字符串blobKey;
}
下一次后台任务会发现最大的 BlobRange.toId
并且将获取的评论
所以你不能依靠这个去检查新的实体。
改为使用查询游标。创建Comment时记录的时间戳记属性(可以是类型 long
的unix时间戳记)。然后使用查询和游标来检测新实体。
Is it guaranteed that auto-incremented ID of new entity always bigger than existing IDs ?
Basically I want to periodically dump entity (e.g. Comment) in background task into big blobs as they get created by customers.
So if there are 100 entities right now I'll store them in blob and create helper entity for this blob like
class BlobRange
{
long fromId; // Comment.id
long toId; // Comment.id
String blobKey;
}
Next time background task would find biggest BlobRange.toId
and would fetch new chunk of Comment
whose id
is greater than BlobRange.toId
, which in this example would be greater than 100.
Afaik, no. IDs seem to be allocated in blocks (see here). I've personally seen IDs allocated something like this: 1001, 2001, 1002, 3001, 2002, etc.. It seems that they are incremented contiguously within a block, but there are several blocks used in parallel.
So you can not rely on this to check for new entities.
Instead use Query Cursors for this. Create a timestamp property (can be a unix timestamp of type long
) on Comment that records when Comment was created. Then use query and cursors to detect new entities.
这篇关于保证新实体的数字自动递增ID总是大于现有ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!