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, I.e. 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>
get()method is doing a fetch-by-key, it should always have strong consistency. - tx802