本文介绍了处理数据存储的最终一致性的技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GAE的现有持久性框架(如, Datanucleus Twig )如何处理最终一致特性的数据存储?



我正在使用 DatastoreService 图层中的数据存储(我现在没有使用这种持久性框架)。

在我的单元测试中,我有时会得到正确的对象数,有时候不会。这是预期的。



这是我的JUnit帮助器配置:

  private final LocalServiceTestHelper helper = 
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
.setDefaultHighRepJobPolicyUnappliedJobPercentage(50));

现在,即使我已经将put / get方法放在带重试的do-while循环中与重试计数4),它仍然错过放/得到实体。

那么现在,对于那些指定的框架,他们是否能够保证,如果我把3个对象,我会得到3个对象?如果是的话,它是如何实施的?

我能想到的唯一的事情就是使用Memcache,也就是说,我的方法将首先尝试从它获取实体,如果它错过了这是唯一的时间它会检查数据存储。这是一个很好的方法,或者有更好的方法或正确的方法吗? 解决方案

有两种选择:


  1. )使用

    queries。


  2. 操作而不是查询,它们是非常一致的。

如果你仔细地构造你的关键字,通常可以使用gets而不是查询。您的其他选择,如果您需要对给定用户出现一致的查询,则应用一些小技巧:将用户更改注入结果中。所以,如果他们改变他们的名字,并且你重定向到他们的个人资料页面,在发送他们之前将他们的改变注入结果。


How does existing persistence framework for the GAE, like Objectify, Datanucleus, Twig, etc. deal with the "eventual consistent" nature of the datastore?

I'm working with the datastore in the DatastoreService layer (I'm not using such persistence framework right now).

During my unit test I get the correct count of object sometimes and sometimes not. Which is expected.

This is my JUnit helper configuration:

private final LocalServiceTestHelper helper =
    new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
        .setDefaultHighRepJobPolicyUnappliedJobPercentage(50)); 

Now, even if I have placed the put/get methods in a do-while loop with retries (with retry count of 4), it still misses to put/get entities.

So right now, for those specified frameworks, were they able to assure that if I put 3 object I will get 3 objects? If so how was it implemented?

The only thing I can think of is to use Memcache, that is, my methods will try to get the entity from it first, and if it misses that's the only time it will check the datastore. Is this a sound approach, or there is a better approach or right approach?

解决方案

If you want strong consistency of your queries then there are two choices:

  1. ) Useancestorqueries.

  2. ) Use datastoregetoperations instead of queries, they are strongly consistent.

It is often possible to use gets instead of queries if you you structure your key names carefully. Your other choice, if you need queries to "appear" consistent for a given user is to apply a little trick: inject the users changes into the results. So, if they change their name and you redirect to their profile page, inject their change into the results before sending them.

这篇关于处理数据存储的最终一致性的技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 15:40