Infinispan,版本控制操作返回错误结果 [英] Infinispan, the versioned operation returning incorrect results

查看:114
本文介绍了Infinispan,版本控制操作返回错误结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们计划在客户端服务器模式下使用Infinispan.该体系结构具有许多客户端(客户端1,客户端2等)和分布式infinispan网络.

We are planning to use Infinispan in client server mode. The architecture has many clients (client 1, client 2 and so on ) and a distributed infinispan network.

我们需要定期更新缓存中的数据,例如,每5小时更新一次.所有客户端都可以更新数据.如果其中一个(例如客户端1)正在更新,则我们需要阻止其他人执行相同的工作.更新完成后,所有客户端将再等待5个小时,他们中的任何一个都会再次进行更新.

We need to update the data in the cache periodically, say every5 hours . All clients could be able to update the data. If one of them (say client 1) is updating we need to prevent others doing the same job. Once the updating is complete all clients wait another 5 hour and, any of them will do the the updating again.

Infinispan为此提供了版本控制操作,但是在测试过程中,该方法给出了无效的结果.

Infinispan providing a versioned operation for this, But during the testing this methord is giving invalid result.

String key="test";
RemoteCacheManager cacheManager = new RemoteCacheManager();
RemoteCache<String, Object> remoteCache = cacheManager.getCache("MyCache");
remoteCache.put(key, new Object());
for (int i = 1; i < 5; i++) {
        System.out.println("version Before:" + remoteCache.getVersioned(key).getVersion());
        System.out.println("version to put:"+(i));
        System.out.println(remoteCache.replaceWithVersion(key, new Object(),i));
        System.out.println("version after:" + remoteCache.getVersioned(key).getVersion());
        System.out.println("---------------------");
}

这给出了正确的结果,例如

This is giving correct result like,

version Before:1
version to put:1
true
version after:2
---------------------
version Before:2
version to put:2
true
version after:3
---------------------
version Before:3
version to put:3
true
version after:4
---------------------

但是一旦我向同一个缓存中添加了新的不同密钥,旧密钥的版本就会给出错误

But once I add a new different key to the same cache the version to the old key is giving incorrectly

for (int i = 1; i < 5; i++) {
    remoteCache.put("Hello", new Object());
    System.out.println("version Before:" + remoteCache.getVersioned(key).getVersion());
    System.out.println("version to put:"+(i));
    System.out.println(remoteCache.replaceWithVersion(key, new Object(),i));
    System.out.println("version after:" + remoteCache.getVersioned(key).getVersion());
    System.out.println("---------------------");

}

version Before:1
version to put:1
true
version after:3
---------------------
version Before:3
version to put:2
false
version after:3
---------------------
version Before:3
version to put:3
true
version after:6
---------------------
version Before:6
version to put:4
false
version after:6
---------------------

看起来像版本在变化,与密钥无关,但对于缓存而言.因为在插入其他密钥以缓存现有版本时也会发生变化.

Looks like version is changing irrespective of the key but for cache. Because while inserting a different key to cache the version of existing also changes.

更新:-这不是错误,是预期的行为,请参见答案及其讨论.

推荐答案

这是预期的行为.当您将新条目写入高速缓存时,它将获得新版本.从原子计数器获取新版本,以确保始终生成某些新版本.除非您调用getWithVersion,否则您将无法知道此新版本.

This is expected behaviour. When you write a new entry into the cache, it gets a new version. New versions are obtained from atomic counter which makes sure that always some new version is generated. You cannot know this new version unless you call the getWithVersion.

这篇关于Infinispan,版本控制操作返回错误结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆