private void trackBucketForTx(KeyInfo keyInfo) { GemFireCacheImpl cache = (GemFireCacheImpl) txMgr.getCache(); if (keyInfo.getBucketId() >= 0) { if (logger.isDebugEnabled()) { logger.debug("adding bucket:{} for tx:{}", keyInfo.getBucketId(), getTransactionId()); } } if (keyInfo.getBucketId() >= 0) { buckets.put(keyInfo.getBucketId(), Boolean.TRUE); } }
private void trackBucketForTx(KeyInfo keyInfo) { if (region.getCache().getLoggerI18n().fineEnabled()) { region.getCache().getLoggerI18n().fine("adding bucket:"+keyInfo.getBucketId()+" for tx:"+state.getTransactionId()); } if (keyInfo.getBucketId() >= 0) { buckets.put(keyInfo.getBucketId(), Boolean.TRUE); } }
public boolean hasSeenEvent(EntryEventImpl event) { BucketRegion bucket = getLocalBucketById(event.getKeyInfo().getBucketId()); if (bucket == null) { return false; } else { return bucket.hasSeenEvent(event); } }
@Override public Entry getEntryOnRemote(KeyInfo keyInfo, LocalRegion localRegion, boolean allowTombstones) throws DataLocationException { PartitionedRegion pr = (PartitionedRegion)localRegion; return pr.getDataStore().getEntryLocally(keyInfo.getBucketId(), keyInfo.getKey(), false, allowTombstones, true); }
public static void gatherAffectedRegions(TreeSet<String> sortedRegionName, ArrayList<DistTxEntryEvent> regionOps) { for (DistTxEntryEvent dtos : regionOps) { LocalRegion lr = dtos.getRegion(); if (lr instanceof PartitionedRegion) { sortedRegionName.add(PartitionedRegionHelper.getBucketFullPath( lr.getFullPath(), dtos.getKeyInfo().getBucketId())); } else { sortedRegionName.add(lr.getFullPath()); } } }
@Override public void invalidateOnRemote(EntryEventImpl event, boolean invokeCallbacks, boolean forceNewEntry) throws DataLocationException { PartitionedRegion pr = (PartitionedRegion)event.getLocalRegion(); pr.getDataStore().invalidateLocally(event.getKeyInfo().getBucketId(), event); } @Override
@Override public void checkIfAboveThreshold(EntryEventImpl evi) throws LowMemoryException { getRegionAdvisor().checkIfBucketSick(evi.getKeyInfo().getBucketId(), evi.getKey()); }
@Override public void destroyOnRemote(EntryEventImpl event, boolean cacheWrite, Object expectedOldValue) throws DataLocationException { PartitionedRegion pr = (PartitionedRegion)event.getLocalRegion(); pr.getDataStore().destroyLocally(event.getKeyInfo().getBucketId(), event, expectedOldValue); return; } @Override
@Override public boolean putEntryOnRemote(EntryEventImpl event, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue, long lastModified, boolean overwriteDestroyed) throws DataLocationException { PartitionedRegion pr = (PartitionedRegion)event.getLocalRegion(); return pr.getDataStore().putLocally(event.getKeyInfo().getBucketId(), event, ifNew, ifOld, expectedOldValue, requireOldValue, lastModified); } @Override
private TransactionException getTransactionException(KeyInfo keyInfo, GemFireException e) { if (isRealDealLocal() && !buckets.isEmpty() && !buckets.containsKey(keyInfo.getBucketId())) { TransactionException ex = new TransactionDataNotColocatedException(LocalizedStrings. PartitionedRegion_KEY_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(keyInfo.getKey())); ex.initCause(e.getCause()); return ex; } Throwable ex = e; while (ex != null) { if (ex instanceof PrimaryBucketException) { return new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING .toLocalizedString()); } ex = ex.getCause(); } return (TransactionException) e; }
@Override public EntrySnapshot getEntryOnRemote(final KeyInfo keyInfo, final LocalRegion localRegion, boolean allowTombstones) throws DataLocationException, EntryNotFoundException { final PartitionedRegion pr = (PartitionedRegion)localRegion; final EntrySnapshot entry = pr.getDataStore().getEntryLocally( keyInfo.getBucketId(), keyInfo.getKey(), false, null, allowTombstones); if (entry != null) { return entry; } throw new EntryNotFoundException( LocalizedStrings.PartitionedRegionDataStore_ENTRY_NOT_FOUND .toLocalizedString()); }
public Object getEntryForIterator(KeyInfo keyInfo, boolean allowTombstones) { PartitionedRegion pr = (PartitionedRegion)region; InternalDistributedMember primary = pr.getBucketPrimary(keyInfo.getBucketId()); if (primary.equals(state.getTarget())) { return getEntry(keyInfo, allowTombstones); } else { return pr.getSharedDataView().getEntry(keyInfo, pr, allowTombstones); } }
protected final InternalDistributedMember getOrCreateNodeForBucketRead( final KeyInfo keyInfo, final boolean noCreateNode) { final Object key = keyInfo.getKey(); int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, Operation.GET_ENTRY, key, keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } if (noCreateNode) { return getNodeForBucketRead(bucketId); } return getOrCreateNodeForBucketRead(bucketId); }
protected final InternalDistributedMember getOrCreateNodeForInitializedBucketRead( final KeyInfo keyInfo, final boolean noCreateNode) { final Object key = keyInfo.getKey(); int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, Operation.GET_ENTRY, key, keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } if (noCreateNode) { return getNodeForInitializedBucketRead(bucketId, false); } return getOrCreateNodeForInitializedBucketRead(bucketId, false); }
/** * Now only used for tests. TODO: method should be removed. */ public DistributedMember getOwnerForKey(KeyInfo keyInfo) { if (keyInfo == null) { return getMyId(); } int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, null, keyInfo.getKey(), keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } return createBucket(bucketId, 0, null); }
@Override public DistributedMember getOwnerForKey(KeyInfo keyInfo) { if (keyInfo == null) { return super.getOwnerForKey(null); } // TODO provide appropriate Operation and arg int bucketId = keyInfo.getBucketId(); if (bucketId == KeyInfo.UNKNOWN_BUCKET) { bucketId = PartitionedRegionHelper.getHashKey(this, null, keyInfo.getKey(), keyInfo.getValue(), keyInfo.getCallbackArg()); keyInfo.setBucketId(bucketId); } return createBucket(bucketId, 0, null); } @Override
@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; }
@SuppressWarnings("unchecked") private boolean hasAdjunctRecipientsNeedingDelta(EntryEventImpl event) { PartitionedRegion pr = ((PartitionedRegion)this); BucketRegion br = null; FilterRoutingInfo filterRouting = null; Set twoMessages = Collections.EMPTY_SET; Set adjunctRecipients = Collections.EMPTY_SET; Set cacheservers = null; int bId = event.getKeyInfo().getBucketId(); try { br = pr.dataStore.getInitializedBucketForId(event.getKey(), bId); } catch (ForceReattemptException fre) { return true; } Set<InternalDistributedMember> recipients = br.getCacheDistributionAdvisor().adviseUpdate(event); twoMessages = br.getBucketAdvisor().adviseRequiresTwoMessages(); CacheDistributionAdvisor cda = pr.getCacheDistributionAdvisor(); filterRouting = cda.adviseFilterRouting(event, recipients); adjunctRecipients = br.getAdjunctReceivers(event, recipients, twoMessages, filterRouting); cacheservers = cda.adviseCacheServers(); return !Collections.disjoint(adjunctRecipients, cacheservers); }
@Override public void toData(DataOutput out) throws IOException { DataSerializer.writeObject(this.eventID, out); DataSerializer.writeObject(this.region.getFullPath(), out); out.writeByte(this.op.ordinal); DataSerializer.writeObject(this.getKey(), out); DataSerializer.writeInteger(this.keyInfo.getBucketId(), out); DataSerializer.writeObject(this.basicGetNewValue(), out); byte flags = 0; if (this.putAllOp != null) { flags |= HAS_PUTALL_OP; } if (this.removeAllOp != null) { flags |= HAS_REMOVEALL_OP; } DataSerializer.writeByte(flags, out); // handle putAll if (this.putAllOp != null) { putAllToData(out); } // handle removeAll if (this.removeAllOp != null) { removeAllToData(out); } }
@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; }