[infinispan-dev] ISPN-359 and grouping entries for distribution

Emmanuel Bernard emmanuel at hibernate.org
Tue Apr 13 05:49:01 EDT 2010


On 13 avr. 2010, at 11:28, Manik Surtani wrote:

> 
> On 13 Apr 2010, at 07:55, Emmanuel Bernard wrote:
> 
>> No need, Marcus had it :)
>> 
>> I'd do something like
>> 
>> cacheFactory.usingContext()
>>   .colocateOn(groupName)
>>   .getCache() (*)
>> (*) assuming the ability to get a cache is
>>   
>> Or is the collocation business something that must be done at the cache level temporarily / for a single operation (thus hosted on the cache interface)?
> 
> The latter.  So something like:
> 
> cache.inGroup("coloGrp1").put("k1", "v1");
> cache.inGroup("coloGrp1").put("k2", "v2");
> cache.inGroup("coloGrp2").put("k3", "v3");
> cache.inGroup("coloGrp2").put("k4", "v4");
> 
> would result in k1 and k2 being placed on the same nodes, regardless of what the 2 keys individually hash to.  Same with k3 and k4.
> 
> Another question (slightly off-topic) - would people then be tempted to use this as a scoping mechanism:
> 
> cache.inGroup("coloGrp1").put("name", "Manik");
> cache.inGroup("coloGrp1").put("location", "London");
> cache.inGroup("coloGrp2").put("name", "Emmanuel");
> cache.inGroup("coloGrp2").put("location", "Paris");
> 
> since this will *not* work.  The cache still primarily is a collection of K -> V mappings and in the above case the last 2 lines will effectively overwrite the 1st 2 lines.

For this use case, you could add a new method, something like
cache.scope("51thState").put("name", "Manik");
cache.scope("51thState").put("location", "London");
cache.scope("cheeseLand").put("name", "Emmanuel");
cache.scope("cheeseLand").put("location", "Paris");

which could prefix the key.
But as it breaks the natural semantic of Infinispan, I'm not sure it's worth the addition.


Regardless, both APIs should also support something like that
ColocatedCache cc = cache.inGroup("cheeseLand"); //cache.collocateIn(String)?
cc.put("name", "Emmanuel");
cc.put("location", "Paris");

A specific interface (ala ColocatedCache) is preferable but boils down to:
 - keep it (design) simple
 - guide the API user and avoid mistakes (ie a ScopedCache cannot be scoped again same for a collocated one I imagine).





More information about the infinispan-dev mailing list