简体   繁体   中英

App Engine: different results for same objectify query

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 since is 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.

Wild guess, this is related to FAQ #3:

https://code.google.com/p/objectify-appengine/wiki/FrequentlyAskedQuestions#Strange_things_are_showing_up_in_my_session_cache!_(or_missing_f

or, when googlecode dies, the third one down:

https://github.com/objectify/objectify/wiki/FrequentlyAskedQuestions

You need to have the ObjectifyFilter installed otherwise you will bleed session data into subsequent requests. Upgrade to a more recent version of Objectify; it will give you a more explicit error (at the cost of complicating test and remote api usage, but that's a different story).

If this isn't your issue, you need to describe your exact code in more detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM