-
1. Re: How to get cache entries when clustering mode is LOCAL or REPL_SYNC
galder.zamarreno Jan 20, 2012 6:35 AM (in response to ursudheesh)First of all, that way of configuring Infinispan is deprecated in 5.1 (not 100% sure it'll have the desired effect btw). In the new configuration, expiration lifespan is not a dynamic property, although you can make a suggestion in https://issues.jboss.org/browse/ISPN
Expiration values applied via Cache methods always have preference, so you can always traverse the entire cache and re-put with the desired lifespan (using map/reduce for example).
-
2. Re: How to get cache entries when clustering mode is LOCAL or REPL_SYNC
ursudheesh Jan 23, 2012 1:25 AM (in response to galder.zamarreno)So i understand the expiration lifespan via configuration has been deprecated in Infinispan 5.1.
Here i am trying a map reduce for a replicated cache whose configuration is :
<clustering mode="replication"> <stateRetrieval timeout="20000" fetchInMemoryState="true"
alwaysProvideInMemoryState="true" /> <sync replTimeout="30000" /> </clustering>
public class MyMapReduceExample {
public static void main(String[] args) {
EmbeddedCacheManager manager;
long ttlOffset= 2000;
try {
manager = new DefaultCacheManager("InfinispanCfgForNode1.xml");
Cache cache = manager.getCache("InfinispanClientTest");
Configuration.CacheMode cacheMode = cache.getConfiguration().getCacheMode();
cache.put("LC", "Cat", 3000, TimeUnit.MILLISECONDS);
MapReduceTask<Object, Object, Object, Object> t =
new MapReduceTask<Object, Object, Object, Object>(cache);
t.mappedWith(new MyShiftTTLMapper(manager, cache.getName(), ttlOffset)).reducedWith(new MyTestReducer());
t.execute();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class MyShiftTTLMapper implements Mapper{
long ttlOffset;
private EmbeddedCacheManager manager;
private String cacheName;
public MyShiftTTLMapper(){
ttlOffset = 0;
}
public MyShiftTTLMapper(EmbeddedCacheManager manager, String cacheName,long ttlOffset){
System.out.println("Inside constructor of MyTestMapper");
this.manager = manager;
this.cacheName = cacheName;
this.ttlOffset = ttlOffset;
}
@Override
public void map(Object key, Object value, Collector arg2) {
Cache cache = this.manager.getCache(this.cacheName);
AdvancedCache advancedCache = cache.getAdvancedCache();
DataContainer dataContainer = advancedCache.getDataContainer();
InternalCacheEntry entry = dataContainer.get(key);
long expiryMillis = entry.getExpiryTime();
if (expiryMillis > 0) {
long newTTL = (expiryMillis- System.currentTimeMillis())+ttlOffset;
entry.setLifespan(newTTL);
}
if(expiryMillis == -1){
System.out.println("Entry is set with never expire; Do Nothing");
//Do nothing. Since this entry should not expiry at any time
}
}
}
While i tried to use the map reduce on the REPL_SYNC configured cache i get the following error:
Exception in thread "main" java.lang.IllegalStateException: Cache mode should be DIST, rather than REPL_SYNC
at org.infinispan.distexec.mapreduce.MapReduceTask.ensureProperCacheState(MapReduceTask.java:443)
at org.infinispan.distexec.mapreduce.MapReduceTask.<init>(MapReduceTask.java:156)
at com.hp.ispan.mapreduce.ttl.MyMapReduceExample.main(MyMapReduceExample.java:14)
This method works well when the cache configuration is DIST. However for REPLY_SYNC configurations i get errors. What should i do now?
-
3. Re: How to get cache entries when clustering mode is LOCAL or REPL_SYNC
galder.zamarreno Jan 29, 2012 7:03 AM (in response to ursudheesh)Hmmmm, don't think it makes sense to do distributed map/reduce with REPL because all nodes have the same data, so all you have to do is loop through one of the node's data and that's it
With DIST, data is stored in a subset, so to work on all the cached data, data from all nodes needs to be computed.
True that Map/Reduce maybe should support this more REPL or LOCAL modes more easily, but taken the burden from the user.
-
4. Re: How to get cache entries when clustering mode is LOCAL or REPL_SYNC
vblagojevic Jan 30, 2012 7:45 AM (in response to galder.zamarreno)Galder,
Nothing against supporting REPL unless we have to add a lot of additional code and maintain lots of special cases in order to support it. I can also foreesee this being useful to setup some basic testing scenarios to test MapReduce. I suggest user open a JIRA and we'll take it from there!
Regards,
Vladimir