[infinispan-dev] How to get Grouper<T>#computeGroup(key) return value to map to physical Node?

Dan Berindei dan.berindei at gmail.com
Tue May 21 12:15:16 EDT 2013


I guess the grouper could use a KeyAffinityService (or something similar)
to generate a key local to each node and return that instead of "0" or "1".
However, you won't have any guarantee that the keys will stay on the same
node if the cache topology changes (e.g. another node joins).

It used to be that the actual address of the node would (almost) always be
mapped to that node, but that was just an implementation detail, and it
never worked 100%.

Ben, do you think being able to pin a key "permanently" to a node would be
useful?

Cheers
Dan




On Tue, May 21, 2013 at 6:31 PM, Galder Zamarreño <galder at redhat.com> wrote:

> Hmmm, one hacky way might be to hold on to the grouper instance passed in
> via configuration, and once the cache manager has been started, set it in
> the grouper and use to query either the address, or the physical address
> (via EmbeddedCacheManager.getTransport…)?
>
> On May 14, 2013, at 6:34 PM, cotton-ben <ben.cotton at ALUMNI.RUTGERS.EDU>
> wrote:
>
> > I am playing with the Infinispan 5.3 quick-start package to exercise my
> usage
> > of the Grouping API.  As we know the quick start package is made up of
> > AbstractNode.java, Node0.java, Node1.java and Node2.java (plus a
> > util/listener).
> >
> > My ambition is to demonstrate
> >
> > 1.  that any Cache<K,V>.put("DIMENSION.xxx",v) will flow through my
> Grouper
> > and "pin" that key in the Cache at @Node=0.
> > 2.  that any Cache<K,V>.put("POSITION.xxx",v) will flow through my
> Grouper
> > and "pin" that key in the Cache at either @Node=1 or @Node=2 .
> >
> > Here is my AbstractNode#createCacheManagerProgramatically() config:
> >
> > private static EmbeddedCacheManager createCacheManagerProgramatically() {
> >               return new DefaultCacheManager(
> >
> GlobalConfigurationBuilder.defaultClusteredBuilder()
> >
> .transport().addProperty("configurationFile", "jgroups.xml")
> >                               .build(),
> >                               new
> org.infinispan.configuration.cache.ConfigurationBuilder()
> >                               .clustering()
> >                               .cacheMode(CacheMode.DIST_SYNC)
> >
> .hash().numOwners(1).groups().enabled(Boolean.TRUE)
> >                               .addGrouper(new
> > com.jpmorgan.ct.lri.cs.ae.test.DimensionGrouper<String>())
> >                               .build()
> >                               );
> >       }
> >
> > And here is my Grouper<T> implementation
> >
> > public class DimensionGrouper<T> implements Grouper<String> {
> >       public String computeGroup(String key, String group) {
> >               if (key.indexOf("DIMENSION.")==0) {
> >                       String groupPinned = "0";
> >                       System.out.println("Pinning Key=["+key+"]
> @Node=["+groupPinned+"]");
> > //node= exactly 0
> >                       return groupPinned;
> >               } else if (key.indexOf("POSITION.")==0) {
> >                       String groupPinned = ""+(1+
> (int)(Math.random()*2));
> >                       System.out.println("Pinning Key=["+key+"]
> @Node=["+groupPinned+"]");
> > //node= {1,2}
> >                       return groupPinned;
> >               } else {
> >                       return null;
> >               }
> >       }
> >
> >       public Class<String> getKeyType() {
> >               return String.class;
> >       }
> >
> > }
> >
> > The "logic" is working correctly ... i.e. when from Node2.java I call
> >
> >                     for (int i = 0; i < 10; i++) {
> >                               cacheDP.put("DIMENSION." + i,
> "DimensionValue." + i);
> >                               cacheDP.put("POSITION." + i,
> "PositionValue." + i);
> >
> >                       }
> >
> > My DimensionGrouper is returning "0" from computeGroup().  My question is
> > how in Infinispan can I map the computeGroup() return value to a physical
> > Node?  I.e.  How can I make it so that when computeGroup() returns "0", I
> > will *only* add that <K,V> entry to the Cache @Node 0?
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> http://infinispan-developer-list.980875.n3.nabble.com/Re-How-to-get-Grouper-T-computeGroup-key-return-value-to-map-to-physical-Node-tp4027134.html
> > Sent from the Infinispan Developer List mailing list archive at
> Nabble.com.
> > _______________________________________________
> > infinispan-dev mailing list
> > infinispan-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/infinispan-dev
>
>
> --
> Galder Zamarreño
> galder at redhat.com
> twitter.com/galderz
>
> Project Lead, Escalante
> http://escalante.io
>
> Engineer, Infinispan
> http://infinispan.org
>
>
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/infinispan-dev/attachments/20130521/ef3d8104/attachment.html 


More information about the infinispan-dev mailing list