Bug 1252889 - Cache.getAdvancedCache().getDistributionManager().getLocality always returns true
Cache.getAdvancedCache().getDistributionManager().getLocality always returns ...
Product: JBoss Data Grid 6
Classification: JBoss
Component: Documentation (Show other bugs)
Unspecified Unspecified
high Severity unspecified
: Post GA
: 6.5.1
Assigned To: Christian Huffman
Depends On:
  Show dependency treegraph
Reported: 2015-08-12 08:57 EDT by Shay Matasaro
Modified: 2015-10-30 08:32 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2015-10-30 08:32:24 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Shay Matasaro 2015-08-12 08:57:15 EDT
standalone reproducer :

public class RunDistributedTaskService1 {

	private static class DistributedTest<K, V> implements
			DistributedCallable<String, Long, Long>, Serializable {
		private static final long serialVersionUID = 1L;
		private Cache<String, Long> paramCache;
		private Set<String> paramSet;

		public Long call() throws Exception {
			System.out.println("Got here");
			boolean shouldBeFalse = paramCache.getAdvancedCache().getDistributionManager().getLocality("runIdKey3").isLocal();
			boolean shouldBeTrue = paramCache.getAdvancedCache().getDistributionManager().getLocality("runIdKey2").isLocal();
			System.out.println( "shouldBeFalse :" + shouldBeFalse + " shouldBeTrue :"+ shouldBeTrue);
			Long tmpRunId = paramCache.get("runIdKey2");
			tmpRunId = tmpRunId + 1l;
			paramCache.replace("runIdKey2", tmpRunId);
			return tmpRunId;

		public void setEnvironment(Cache<String, Long> paramCache,
				Set<String> paramSet) {
			this.paramCache = paramCache;
			this.paramSet = paramSet;


	public static void main(String[] arg) throws InterruptedException,
			ExecutionException {
		org.infinispan.configuration.cache.Configuration config = new ConfigurationBuilder()
		DefaultCacheManager cacheManager = new DefaultCacheManager(
				new GlobalConfigurationBuilder().transport().defaultTransport()
						.build(), config);
		Cache<String, Long> cache = cacheManager.getCache();
		cache.put("runIdKey2", 1l);

		DistributedExecutorService des = new DefaultExecutorService(cache);
		DistributedTest<String, Long> ct = new DistributedTest<String, Long>();
		Set<String> set = new HashSet<String>(Arrays.asList("runIdKey3"));

		Future<Long> result = des.submit(ct, set);
		Long countCircle = result.get();

		System.out.println("Distributed Run Id Incrementor is " + countCircle);

Comment 2 Tristan Tarrant 2015-08-12 10:46:38 EDT
Shay, I think getLocality()  returns LOCAL even for backup nodes, not just primaries. You should probably change your code to use getPrimaryLocation() instead. We can consider adding primary information to the DataLocality object.
Comment 3 pronane 2015-08-12 13:00:26 EDT
Hi Tristan,

I remember reading a comment you made about getLocality() not working on a forum in the community edition.

But the above doesn't work either.  Please take a look at the code.

Where we have a key(runIdKey3) that is not in the cache the following statement returns true:

		org.infinispan.remoting.transport.Address nodeAddress = paramCache.getCacheManager().getAddress();
			org.infinispan.remoting.transport.Address address = paramCache.getAdvancedCache().getDistributionManager().getPrimaryLocation(key);
			if(nodeAddress.equals(address)) {

The fundamental issue is the same, the key that doesn't exist for any of these methods returns the local node address

Comment 4 pronane 2015-08-13 04:51:37 EDT

I have seen a comment on this bug -> https://bugzilla.redhat.com/show_bug.cgi?id=1251977

I find this quite strange really, own means the hashing function used, own is not very clear here.  You can't own something you don't have.

It seems the only real way to check where a key doesnt exist is a null check which i was previously doing and using getPrimaryLocation...

Comment 5 Shay Matasaro 2015-08-13 09:43:04 EDT
Tristan, if that is the case I'll switch this to a documentation bug , so that getLocality gets a much better description and so does getPrimaryLocation
Comment 7 Tristan Tarrant 2015-10-05 07:57:40 EDT
"Ownership" as defined by the DistributionManager (and the underlying ConsistentHash) is theoretical: both of those constructs have no knowledge about the data in the cache, but are just used to determine on which node a specified key would be stored. Therefore to determine if an entry exists and where you would need to either ask both the cache (cache.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).containsKey(key) && cache.getAdvancedCache().getDistributionManager().getLocality(key).isLocal()).

Alternatively you can query the DataContainer directly:


If the entry is passivated the above will return false.
Comment 10 Christian Huffman 2015-10-30 08:32:24 EDT
This section has been published and is available on the customer portal at the following link:


Note You need to log in before you can comment on or make changes to this bug.