简体   繁体   中英

Datastore & Memcache consistency - Google App Engine & Objectify

I'm having a pretty tough problem ensuring consistency in the datastore. We're trying to do a sync job to BigQuery every 1 minute (cron) and are relying on the Datastore to store a timestamp for when the previous sync was completed.

We are still seeing eventual consistency when the object is loaded and I'm getting to hair-tearing time..

Both the Settings & ParentClass classes are stored in the Datastore as singletons, Ie only one exists.

@Entity
public class Settings {

    @Parent
    private Key<ParentClass> parent = ParentClass.getKey();

    @Id
    private Long id = 123L;

    ...

    public Settings save(){
        ofy().cache(false).consistency(ReadPolicy.Consistency.STRONG).save().entity(this).now();
        return this;
    }

    public static Settings get(){
        Settings settings = ofy().cache(false).consistency(ReadPolicy.Consistency.STRONG).load().key(Key.create(ParentClass.getKey(), Settings.class, 123L)).now();
        if (settings == null) settings = create();
        return settings;
    }

    private static Settings create(){
        return new Settings().save();
    }

}

Does anyone know what's causing this being eventually consistent?

Edit: web.xml extract:

<filter>
    <filter-name>ObjectifyFilter</filter-name>
    <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ObjectifyFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>asyncCacheFilter</filter-name>
    <filter-class>com.googlecode.objectify.cache.AsyncCacheFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>asyncCacheFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

The problem was the internal session cache of Objectify.

Initially resolved by manually clearing the cache using ofy().clear() prior to the first load() and then improved further by upgrading to Objectify 5.1.5.

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