【问题标题】:Datastore & Memcache consistency - Google App Engine & Objectify数据存储和 Memcache 一致性 - Google App Engine 和 Objectify
【发布时间】:2015-02-20 15:15:53
【问题描述】:

我在确保数据存储区的一致性方面遇到了一个非常棘手的问题。 我们正在尝试每 1 分钟 (cron) 对 BigQuery 执行一次同步作业,并依靠数据存储区存储上次同步完成时间的时间戳。

当对象被加载时,我们仍然看到最终的一致性,而我已经到了令人毛骨悚然的时间..

Settings 和 ParentClass 类都作为单例存储在 Datastore 中,即只有一个存在。

@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();
    }

}

有谁知道是什么导致这最终保持一致?

编辑:web.xml 提取:

<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>

【问题讨论】:

  • 我在stackoverflow.com/questions/22269411/… 看到了那个帖子,你会遇到类似的问题吗?介意发布您的 web.xml 吗?
  • 由于get() 方法是按键提取,它应该始终具有强一致性。
  • @Patrice,我也看到了那个帖子,但是唉.. 在帖子中添加了 objectify 过滤器..
  • @tx802 - 我同意,这就是为什么我对这个问题完全感到困惑。我什至在尽可能优化后将设置类重命名为设置,但问题仍然存在,有时甚至得到一个小时前的物体,这没有意义..
  • 另外值得注意的是,这会通过刷新 memcache 持续存在..

标签: java google-app-engine google-cloud-datastore objectify consistency


【解决方案1】:

问题在于 Objectify 的内部会话缓存。

最初通过在第一次 load() 之前使用 ofy().clear() 手动清除缓存来解决,然后通过升级到 Objectify 5.1.5 进一步改进。

【讨论】:

  • 会话缓存行为在这里得到了相当详尽的记录:code.google.com/p/objectify-appengine/wiki/Caching。常见问题解答中也提到了这一点:code.google.com/p/objectify-appengine/wiki/…
  • 我认为文档中的重点是:A get-by-key operation (single or batch) for a cached entity will return the entity instance without a call to the datastore or even to the memcache.。可能,您正在加载的实体已经在会话缓存中,因此 objectify 正在进行本地、简单的 hashmap 查找而不是 memcache 调用。
猜你喜欢
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-19
  • 2014-12-10
  • 2011-12-24
  • 2016-03-25
相关资源
最近更新 更多