Bug 1252889 - Cache.getAdvancedCache().getDistributionManager().getLocality always returns true
Summary: Cache.getAdvancedCache().getDistributionManager().getLocality always returns ...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Data Grid 6
Classification: JBoss
Component: Documentation
Version: 6.5.0
Hardware: Unspecified
OS: Unspecified
high
unspecified
Target Milestone: Post GA
: 6.5.1
Assignee: Christian Huffman
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-08-12 12:57 UTC by Shay Matasaro
Modified: 2019-07-11 09:48 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-10-30 12:32:24 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Shay Matasaro 2015-08-12 12:57:15 UTC
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;

		@Override
		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;
		}

		@Override
		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()
				.clustering().cacheMode(CacheMode.DIST_SYNC).sync().l1()
				.build();
		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 14:46:38 UTC
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 17:00:26 UTC
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

Thanks
Paul

Comment 4 pronane 2015-08-13 08:51:37 UTC
Hi,

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...

Thanks
Paul

Comment 5 Shay Matasaro 2015-08-13 13:43:04 UTC
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 11:57:40 UTC
"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:

cache.getAdvancedCache().getDataContainer().containsKey(key)

If the entry is passivated the above will return false.

Comment 10 Christian Huffman 2015-10-30 12:32:24 UTC
This section has been published and is available on the customer portal at the following link:

https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Data_Grid/6.5/html-single/Developer_Guide/index.html#Distributed_Execution_and_Locality


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