-
1. Re: Infispan Automatic Task Failover
vblagojevic Feb 10, 2015 3:20 AM (in response to bijesh_roy)Hi Bijesh,
Automatic task failover does not provide any consistency guarantees regarding keys iterated. If you have some code samples to share I would be glad to help you further.
Regards,
Vladimir
-
2. Re: Infispan Automatic Task Failover
bijesh_roy Feb 10, 2015 2:30 PM (in response to vblagojevic)Hi Vladimir,
Here is my callable statement:
public class DistributedCacheTest<V, K, T> implements DistributedCallable<K, V, T>,Serializable{
private static final long serialVersionUID = 8331682008912636780L;
//private final String cacheName;
private transient Cache cache;
private final String key;DistributedCacheTest(Cache cache,String key){
this.cache=cache;
this.key=key;
}
@Override
public void setEnvironment(Cache<K, V> arg0, Set<K> arg1) {
// TODO Auto-generated method stub
this.cache=arg0;
}@SuppressWarnings("unchecked")
@Override
public T call() throws Exception {
cache.put(key, UUID.randomUUID());
System.out.println("Printing from Distributed cache Key="+key);
//Thread.currentThread().sleep(5000);
return null;
}}
And the Executor node and I have another node which is just calling the cache manager:
public class TestDistributedCache {
public static void main(String args[]) throws IOException, InterruptedException{
EmbeddedCacheManager cacheManager=null;
try {
cacheManager = createCacheManager();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Cache cache=cacheManager.getCache("dist");
//for (int i=0;i<20;i++){
// cache.put(String.valueOf(i),UUID.randomUUID().toString());
//}
DistributedExecutorService des = new DefaultExecutorService(cache);
List<Future<String>> results = new ArrayList<Future<String>>();
try{
for(int i=0;i<=20; i++){
results.add((Future<String>) des.submit(new DistributedCacheTest(cache,String.valueOf(i))));
Thread.currentThread().sleep(2000);
//results.add((Future<String>) des.submit(new EchoTask(cache,String.valueOf(i))));
}
for (Future<String> f : results) {
String echoResult = f.get();
System.out.println("Response received for DistributedCacheTest:"+echoResult);
}
}catch(ExecutionException e){
System.out.println("Execution Exception Occured="+e.getMessage());
}
System.out.println("After task execution cache size="+cacheManager.getCache("dist").size());}
private static EmbeddedCacheManager createCacheManager() throws IOException {
System.out.println("Starting a cache manager with an XML configuration");
//System.setProperty("nodeName", nodeName);
return new DefaultCacheManager("infinispan.xml");}
}
However after task failure I can see that keys that the down node puts into cache are missing even in some cases. Is it a normal behavior or something is wrong with my code. Also if possible can you please send me some sample code which handles the task failover properly?
Thanks in advance!!
-
3. Re: Infispan Automatic Task Failover
vblagojevic Feb 11, 2015 8:32 AM (in response to bijesh_roy)Hey Bijesh,
I would suggest that you read a bit more of Infinispan documentation. Failover is not done by default and you would have to set it up programmatically yourself.
Regards,
Vladimir