【问题标题】:Terracotta BigMemory shared data is not consistentTerracotta BigMemory 共享数据不一致
【发布时间】:2016-08-19 00:06:17
【问题描述】:

我认为 terracotta bigmemory 可以轻松解决数据一致性问题,但它需要 ehcache.xml 和源代码中的多个参数/属性,正如我在其文档中阅读的那样。

我的 ehcache.xml 是:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
         name="config">

  <cache name="bigMemory"
         maxBytesLocalHeap="128M"
         copyOnRead="true"
         copyOnWrite="true"
         eternal="true">

    <terracotta consistency="strong" />
  </cache>

  <terracottaConfig url="localhost:9510" rejoin="false"/>

</ehcache>

读取和递增共享数据现有值的代码sn-p是:

for (int i = 0; i < 1000; i++) {
            transactionController.begin();
            bigMemoryChip.put(new Element(uid, ((Long) bigMemoryChip.get(uid).getObjectValue())+1));
            transactionController.commit();
        }

我所做的是执行代码两次并观察它如何处理一致性,通常我期望最终值比初始值多 2000。

虽然我试了大约15次,只有一次比初始值多2000,但其他的都比初始值多1500-1700左右。

【问题讨论】:

    标签: java shared-memory terracotta ehcache-bigmemory


    【解决方案1】:

    不知道您的transactionController 是什么,但除非它是提供排除的集群数据结构,否则您正在执行的操作不是原子的,因此您会看到putget.

    也就是说,在该节点上的getput 之间的另一个节点上可能会发生put,这最终会隐藏增量。

    由于您使用的是强一致性,如果您在条件replace 中更改put,测试将通过。

    【讨论】:

    • transactionController 属于缓存对象。就文件而言; begin 和 commit 方法将保证原子性。 “是”,一致性很强。 (参见上面的 .xml)@louis_jacomet
    • 好的,你能说明你是怎么得到它的吗?这可能意味着您正在尝试使用本地事务而不配置它们。所以并不奇怪它没有按预期工作。
    猜你喜欢
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多