简体   繁体   English

Infinispan,版本控制操作返回错误结果

[英]Infinispan, the versioned operation returning incorrect results

We are planning to use Infinispan in client server mode. 我们计划在客户端服务器模式下使用Infinispan。 The architecture has many clients (client 1, client 2 and so on ) and a distributed infinispan network. 该体系结构具有许多客户端(客户端1,客户端2等)和分布式infinispan网络。

We need to update the data in the cache periodically, say every5 hours . 我们需要定期更新缓存中的数据,例如每5小时更新一次。 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. 如果其中之一(例如客户端1)正在更新,则我们需要阻止其他人执行相同的工作。 Once the updating is complete all clients wait another 5 hour and, any of them will do the the updating again. 更新完成后,所有客户端将再等待5个小时,它们中的任何一个都将再次执行更新。

Infinispan providing a versioned operation for this, But during the testing this methord is giving invalid result. Infinispan为此提供了版本控制操作,但是在测试过程中,该方法给出了无效的结果。

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. 因为在插入其他密钥以缓存现有版本时,它也会更改。

Update:- This was not a bug, it is the expected behavior, see the answer and its discussion. 更新:-这不是一个错误,这是预期的行为,请参见答案及其讨论。

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. 除非调用getWithVersion,否则您将无法知道此新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM