Is it guaranteed that numeric auto-incremented ID of new entity always bigger than existing IDs?

亡梦爱人 提交于 2019-12-02 02:26:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8542982/is-it-guaranteed-that-numeric-auto-incremented-id-of-new-entity-always-bigger-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!