Search code examples
javagoogle-app-enginegoogle-cloud-datastorejdo

GAE @Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE) not generating sequential numbers


I've a field:

enter image description here

When I put it in : enter image description here

It does not get generated sequentially enter image description here

Any reason why the sequence numbers are not in order? I'll add the logs in 2 seperate posts because they are too big for this post.

1:1422624487.413000 [s~server-test-killesk/12.381882801386260762].<stdout>: 13:28:07,413 DEBUG Request FC14E205 ValueGeneration:debug:58 - Creating ValueGenerator instance of "com.google.appengine.datanucleus.valuegenerator.SequenceGenerator" for "com.eurekaapp.server.dao.mappedobjects.DAOJobEvent.sequence"
1:1422624487.424000 [s~server-test-killesk/12.381882801386260762].<stdout>: 13:28:07,423 DEBUG Request FC14E205 ValueGeneration:debug:58 - Generated value for field "com.eurekaapp.server.dao.mappedobjects.DAOJobEvent.sequence" using strategy="sequence" (Generator="com.google.appengine.datanucleus.valuegenerator.SequenceGenerator") : value=1,050,002
1:1422624487.624000 [s~server-test-killesk/12.381882801386260762].<stdout>: 13:28:07,624 DEBUG Request FC14E205 ValueGeneration:debug:58 - Generated value for field "com.eurekaapp.server.dao.mappedobjects.DAOJobEvent.sequence" using strategy="sequence" (Generator="com.google.appengine.datanucleus.valuegenerator.SequenceGenerator") : value=1,040,003
1:1422624487.908000 [s~server-test-killesk/12.381882801386260762].<stdout>: 13:28:07,907 DEBUG Request FC14E205 ValueGeneration:debug:58 - Generated value for field "com.eurekaapp.server.dao.mappedobjects.DAOJobEvent.sequence" using strategy="sequence" (Generator="com.google.appengine.datanucleus.valuegenerator.SequenceGenerator") : value=3,010,003

Solution

  • IdGeneratorStrategy.SEQUENCE is implemented on top of DatastoreService.allocateIds() which is how Cloud Datastore internally assigns Ids. Everything that applies to Cloud Datastore auto-Id allocation applies to SEQUENCE.

    Sequences are only guaranteed to be unique, not monotonically increasing.