I am developing a small backend with app engine. Now I get some weird behaviour after saving an entity multiple times with different values. My code to load entities is the same for all entities - each entity gets a changeId so I can transfer only changed entities to the clients:
public class VersionableRecordHelper<T extends VersionableRecord> {
final Class<T> clazz;
public VersionableRecordHelper(Class<T> clazz) {
this.clazz = clazz;
}
Query<T> load() {
return ofy().load().type(clazz);
}
List<T> loadOrdered() {
return load().order("changeId").list();
}
public List<T> loadOrdered(Long since) {
return since == null ? loadOrdered() : load().filter("changeId >", since).order("changeId").list();
}
}
The clients then can query all objects of a class by providing a since value. For example:
private final VersionableRecordHelper<Cat> helper
= new VersionableRecordHelper<>(Cat.class);
// actually an @ApiMethod, simplified here
public List<Cat> getCats(Long since) {
return helper.loadOrdered(since);
}
My Cat entity looks like the following:
@Entity
@Cache
@JsonSerialize(include = JsonSerialize.Inclusion.ALWAYS)
public class Cat extends VersionableRecord {
// some fields, getters, setters
}
public class VersionableRecord {
@Id
private String id;
@Index
private Long changeId;
// getters, setters and more
}
Now, if I do the same REST request with since == 4, I get completely different results - sometimes with changeId == 5, but also with 2, 3 or 4 - which should not even be possible!
I am completely lost here. This is what I checked yet:
- I did not change the records during the test. In fact, I completely left the records alone for more than 90 minutes.
- I checked that only one app engine instance was running.
- I tried to flush the memcache - but the same 2 ObjectifyCache keys keep hanging around.
- The memcache service level is 'Shared'.
- I checked that the value of
sinceis not null by any chance. So the code definitely gets executed. - Currently I am using objectify version 5.0.3. From my build.gradle:
compile 'com.googlecode.objectify:objectify:5.0.3' - I also made sure the entity has the correct changeId in the datastore by checking https://console.developers.google.com/project/project-id/datastore/query?authuser=0
Does anyone have a helpful idea? I also checked for different type of entities - the same behaviour.
curlutility and still get different results. Browser, curl, iOS app - still the same. - mreichelt