Question

Let us say I am using distributed cache schema for cache called "countries" . I have three nodes. I had put some data in the cache . I want to know the data that is present on each node for this cache. Please let me know if there are tools or how we can know it programaticaaly

Was it helpful?

Solution

There are a couple things that you may be asking:

  • If you want to know that the data has redundant copies for availability purposes, you can easily find that in JMX. The "ServiceMBean" mbean has a "StatusHA" attribute whose description is:

The High Availability (HA) status for this service. The value of MACHINE-SAFE means that all the cluster members running on any given computer could be stopped without data loss. The value of NODE-SAFE means that any cluster member could be stopped without data loss. The value of ENDANGERED indicates that abnormal termination of any cluster member that runs this service may cause data loss.

  • If you want to know what partition a key belongs to, you can get the cache's service (CacheService service = cache.getCacheService()) and get the KeyPartitioningStrategy from it (KeyPartitioningStrategy strategy = ((PartitionedService) service).getKeyPartitioningStrategy()), and then ask the strategy where the key goes (int partition = strategy.getKeyPartition(key)).

  • If you use key affinity to control cache data location, it's obviously a little more complicated than that ;-) .. see the JavaDoc for KeyPartitioningStrategy.getKeyPartition for more information.

  • To determine what cluster member a partition belongs to, you can just call PartitionedService.getKeyOwner(Object oKey)

  • The server side equivalent of all the above is BackingMapManagerContext.getKeyPartition() and there's also a handy method BackingMapManagerContext.isKeyOwned().

Now the really cool thing in Coherence is that you don't generally worry about where the data is, because all of the operations are guaranteed to be once-and-only-once operations, and that the results only become visible after the operations have achieved their HA requirements.

For the sake of full disclosure, I work at Oracle. The opinions and views expressed in this post are my own, and do not necessarily reflect the opinions or views of my employer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top