/** * This instance method was added so that unit tests could mock it */ int getHashKey(Operation op, Object key, Object value, Object callbackArg) { return PartitionedRegionHelper.getHashKey(this.proxy, op, key, value, callbackArg); }
/** * Runs hashCode() on given key/routing object producing a long value and then finds absolute * value of the modulus with bucketSize. For better key distribution, possibly use MD5 or SHA or * any unique ID generator for the hash function. * * @param event entry event created for this entry operation * @return the bucket id the key/routing object hashes to */ public static int getHashKey(EntryOperation event) { return getHashKey(event, null, null, null, null, null); }
/** * Test Method: Get the DistributedMember identifier for the vm containing a key * * @param key the key to look for * @return The ID of the DistributedMember holding the key, or null if there is no current mapping * for the key */ public DistributedMember getMemberOwning(Object key) { int bucketId = PartitionedRegionHelper.getHashKey(this, null, key, null, null); return getNodeForBucketRead(bucketId); }
@Override public KeyInfo getKeyInfo(Object key, Object value, Object callbackArg) { final int bucketId; if (key == null) { // key is null for putAll bucketId = KeyInfo.UNKNOWN_BUCKET; } else { bucketId = PartitionedRegionHelper.getHashKey(this, null, key, value, callbackArg); } return new KeyInfo(key, callbackArg, bucketId); }
/** * Returns the local BucketRegion given the key. Returns null if no BucketRegion exists. * * @since GemFire 6.1.2.9 */ public BucketRegion getBucketRegion(Object key) { if (this.dataStore == null) return null; Integer bucketId = PartitionedRegionHelper.getHashKey(this, null, key, null, null); return this.dataStore.getLocalBucketById(bucketId); }
public BucketRegion getLocalBucketByKey(Object key) { Integer bucketId = Integer .valueOf(PartitionedRegionHelper.getHashKey(this.partitionedRegion, null, key, null, null)); return getLocalBucketById(bucketId); }
/** * Returns the local BucketRegion given the key and value. Returns null if no BucketRegion exists. */ public BucketRegion getBucketRegion(Object key, Object value) { if (this.dataStore == null) { return null; } final Integer bucketId = PartitionedRegionHelper.getHashKey(this, null, key, value, null); return this.dataStore.getLocalBucketById(bucketId); }
public static int getHashKey(PartitionedRegion pr, Object routingObject) { return getHashKey(routingObject, pr.getTotalNumberOfBuckets()); }
/** * This method is intended for testing purposes only. */ @Override public Object getValueOnDiskOrBuffer(Object key) throws EntryNotFoundException { final int bucketId = PartitionedRegionHelper.getHashKey(this, null, key, null, null); if (this.dataStore == null) { throw new EntryNotFoundException(key.toString()); } return this.dataStore.getLocalValueOnDiskOrBuffer(key, bucketId); }
@Override public Object getValueInVM(Object key) throws EntryNotFoundException { if (this.dataStore == null) { throw new EntryNotFoundException(key.toString()); } final int bucketId = PartitionedRegionHelper.getHashKey(this, null, key, null, null); return this.dataStore.getLocalValueInVM(key, bucketId); }
/** * This method is intended for testing purposes only. */ @Override public Object getValueOnDisk(Object key) throws EntryNotFoundException { final int bucketId = PartitionedRegionHelper.getHashKey(this, null, key, null, null); if (this.dataStore == null) { throw new EntryNotFoundException(key.toString()); } return this.dataStore.getLocalValueOnDisk(key, bucketId); }
/** * Get the current primary owner for a key. Upon return there is no guarantee that primary owner * remains the primary owner, or that the member is still alive. * <p> * This method is not a substitute for {@link Region#containsKey(Object)}. * </p> * * @param r a PartitionedRegion * @param key the key to evaluate * @throws IllegalStateException if the provided region is something other than a * {@linkplain DataPolicy#PARTITION partitioned Region} * @return the primary member for the key, possibly null if a primary is not yet determined * @since GemFire 6.0 */ public static <K, V> DistributedMember getPrimaryMemberForKey(final Region<K, V> r, final K key) { PartitionedRegion pr = isPartitionedCheck(r); int bucketId = PartitionedRegionHelper.getHashKey(pr, null, key, null, null); return pr.getBucketPrimary(bucketId); }
@Override public Object getValueInVM(EntryEventImpl event) throws EntryNotFoundException { if (this.dataStore == null) { throw new EntryNotFoundException(event.getKey().toString()); } final int bucketId = PartitionedRegionHelper.getHashKey(event); return this.dataStore.getLocalValueInVM(event.getKey(), bucketId); }
private static <K, V> Set<? extends DistributedMember> getAllForKey(final Region<K, V> r, final K key) { PartitionedRegion pr = isPartitionedCheck(r); int bucketId = PartitionedRegionHelper.getHashKey(pr, null, key, null, null); return pr.getRegionAdvisor().getBucketOwners(bucketId); }
@Property public void shouldReturnCorrectPartitionForGetHashKey( @Size(min = 1, max = 5) List<@InRange(minInt = 1, maxInt = 20) Integer> partitionSizes, @InRange(minInt = 0, maxInt = 50) int bucketId) { BucketTargetingFixedResolver resolver = new BucketTargetingFixedResolver(); ConcurrentMap<String, Integer[]> fakePartitions = new ConcurrentHashMap<>(); int startingBucket = 0; for (int i = 0; i < partitionSizes.size(); i++) { fakePartitions.put("p" + i, new Integer[] {startingBucket, partitionSizes.get(i)}); startingBucket += partitionSizes.get(i); } assumeTrue(bucketId < startingBucket); final PartitionedRegion region = mock(PartitionedRegion.class); when(region.getPartitionsMap()).thenReturn(fakePartitions); when(region.isFixedPartitionedRegion()).thenReturn(true); when(region.getPartitionResolver()).thenReturn(resolver); assertEquals(bucketId, PartitionedRegionHelper.getHashKey(region, Operation.CREATE, "key", "value", bucketId)); }
@Override public DistributedMember getOwnerForKey(KeyInfo key) { if (key == null) { return super.getOwnerForKey(null); } // TODO provide appropriate Operation and arg int bucketId = key.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, null, key.getKey(), key.getValue(), key.getCallbackArg()); key.setBucketId(bucketId); } return createBucket(bucketId, 0, null); }
/** * @param access true if caller wants last accessed time updated * @param allowTombstones - whether a tombstone can be returned */ @Override protected Region.Entry<?, ?> nonTXGetEntry(KeyInfo keyInfo, boolean access, boolean allowTombstones) { final long startTime = PartitionedRegionStats.startTime(); final Object key = keyInfo.getKey(); try { int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, Operation.GET_ENTRY, key, null, null); keyInfo.setBucketId(bucketId); } InternalDistributedMember targetNode = getOrCreateNodeForBucketRead(bucketId); return getEntryInBucket(targetNode, bucketId, key, access, allowTombstones); } finally { this.prStats.endGetEntry(startTime); } }
@Override protected boolean nonTXContainsValueForKey(KeyInfo keyInfo) { boolean containsValueForKey = false; int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, Operation.CONTAINS_VALUE_FOR_KEY, keyInfo.getKey(), keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } InternalDistributedMember targetNode = getOrCreateNodeForBucketRead(bucketId); // targetNode null means that this key is not in the system. if (targetNode != null) { containsValueForKey = containsKeyInBucket(targetNode, bucketId, keyInfo.getKey(), true); } return containsValueForKey; }
@Override protected RegionEntry basicGetTXEntry(KeyInfo keyInfo) { int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, null, keyInfo.getKey(), keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } if (keyInfo.isCheckPrimary()) { DistributedMember primary = getRegionAdvisor().getPrimaryMemberForBucket(bucketId); if (!primary.equals(getMyId())) { throw new PrimaryBucketException( "Bucket " + bucketId + " is not primary. Current primary holder is " + primary); } } BucketRegion br = this.dataStore.getLocalBucketById(bucketId); RegionEntry re = br.basicGetEntry(keyInfo.getKey()); if (re != null && re.isRemoved()) { re = null; } return re; }
@Override protected boolean nonTXContainsKey(KeyInfo keyInfo) { final long startTime = PartitionedRegionStats.startTime(); boolean contains = false; try { int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, Operation.CONTAINS_KEY, keyInfo.getKey(), keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } Integer bucketIdInt = bucketId; InternalDistributedMember targetNode = getOrCreateNodeForBucketRead(bucketId); // targetNode null means that this key is not in the system. if (targetNode != null) { contains = containsKeyInBucket(targetNode, bucketIdInt, keyInfo.getKey(), false); } } finally { this.prStats.endContainsKey(startTime); } return contains; }