private void trackBucketForTx(KeyInfo keyInfo) { 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 boolean isKeyInNonColocatedBucket(KeyInfo keyInfo) { Map<Region<?, ?>, TXRegionStub> regionStubs = this.state.getRegionStubs(); Collection<PartitionedRegion> colcatedRegions = (Collection<PartitionedRegion>) ColocationHelper .getAllColocationRegions(this.region).values(); // get all colocated region buckets touched in the transaction for (PartitionedRegion colcatedRegion : colcatedRegions) { PartitionedTXRegionStub regionStub = (PartitionedTXRegionStub) regionStubs.get(colcatedRegion); if (regionStub != null) { buckets.putAll(regionStub.getBuckets()); } } return keyInfo != null && !buckets.isEmpty() && !buckets.containsKey(keyInfo.getBucketId()); }
private void trackBucketForTx(KeyInfo keyInfo) { if (region.getCache().getLogger().fineEnabled()) { region.getCache().getLogger() .fine("adding bucket:" + keyInfo.getBucketId() + " for tx:" + state.getTransactionId()); } if (keyInfo.getBucketId() >= 0) { buckets.put(keyInfo.getBucketId(), Boolean.TRUE); } }
@Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append(getShortClassName()); buf.append("["); buf.append("eventID="); buf.append(this.eventID); if (this.getRegion() != null) { buf.append(";r=").append(this.getRegion().getName()); } buf.append(";op="); buf.append(getOperation()); buf.append(";key="); buf.append(this.getKey()); buf.append(";bucket="); buf.append(this.getKeyInfo().getBucketId()); buf.append(";oldValue="); if (this.putAllOp != null) { buf.append(";putAllDataSize :" + this.putAllOp.putAllDataSize); } if (this.removeAllOp != null) { buf.append(";removeAllDataSize :" + this.removeAllOp.removeAllDataSize); } buf.append("]"); return buf.toString(); } }
public static void gatherAffectedRegions(TreeSet<String> sortedRegionName, ArrayList<DistTxEntryEvent> regionOps) { for (DistTxEntryEvent dtos : regionOps) { InternalRegion ir = dtos.getRegion(); if (ir instanceof PartitionedRegion) { sortedRegionName.add(PartitionedRegionHelper.getBucketFullPath(ir.getFullPath(), dtos.getKeyInfo().getBucketId())); } else { sortedRegionName.add(ir.getFullPath()); } } }
@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); }
public boolean hasSeenEvent(EntryEventImpl event) { BucketRegion bucket = getLocalBucketById(event.getKeyInfo().getBucketId()); if (bucket == null) { return false; } else { return bucket.hasSeenEvent(event); } }
private TransactionException getTransactionException(KeyInfo keyInfo, GemFireException e) { if (isRealDealLocal() && !buckets.isEmpty() && !buckets.containsKey(keyInfo.getBucketId())) { TransactionException ex = new TransactionDataNotColocatedException( String.format("Key %s is not colocated with transaction", keyInfo.getKey())); ex.initCause(e.getCause()); return ex; } Throwable ex = e; while (ex != null) { if (ex instanceof PrimaryBucketException) { return new TransactionDataRebalancedException( "Transactional data moved, due to rebalancing."); } ex = ex.getCause(); } return (TransactionException) e; }
@Override public void invalidateOnRemote(EntryEventImpl event, boolean invokeCallbacks, boolean forceNewEntry) throws DataLocationException { PartitionedRegion pr = (PartitionedRegion) event.getRegion(); pr.getDataStore().invalidateLocally(event.getKeyInfo().getBucketId(), event); }
@Override public void destroyOnRemote(EntryEventImpl event, boolean cacheWrite, Object expectedOldValue) throws DataLocationException { PartitionedRegion pr = (PartitionedRegion) event.getRegion(); pr.getDataStore().destroyLocally(event.getKeyInfo().getBucketId(), event, expectedOldValue); return; }
@Override public boolean putEntryOnRemote(EntryEventImpl event, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue, long lastModified, boolean overwriteDestroyed) throws DataLocationException { PartitionedRegion pr = (PartitionedRegion) event.getRegion(); return pr.getDataStore().putLocally(event.getKeyInfo().getBucketId(), event, ifNew, ifOld, expectedOldValue, requireOldValue, lastModified); }
@Override public void checkIfAboveThreshold(EntryEventImpl entryEvent) throws LowMemoryException { getRegionAdvisor().checkIfBucketSick(entryEvent.getKeyInfo().getBucketId(), entryEvent.getKey()); }
@Override public Object getEntryForIterator(KeyInfo keyInfo, boolean allowTombstones) { InternalDistributedMember primary = region.getBucketPrimary(keyInfo.getBucketId()); if (primary.equals(state.getTarget())) { return getEntry(keyInfo, allowTombstones); } else { return region.getSharedDataView().getEntry(keyInfo, region, allowTombstones); } }
@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; }
@SuppressWarnings("unchecked") private boolean hasAdjunctRecipientsNeedingDelta(EntryEventImpl event) { PartitionedRegion partitionedRegion = (PartitionedRegion) this; BucketRegion bucketRegion; int bId = event.getKeyInfo().getBucketId(); try { bucketRegion = partitionedRegion.dataStore.getInitializedBucketForId(event.getKey(), bId); } catch (ForceReattemptException ignore) { return true; } Set<InternalDistributedMember> recipients = bucketRegion.getCacheDistributionAdvisor().adviseUpdate(event); Set<Object> twoMessages = bucketRegion.getBucketAdvisor().adviseRequiresTwoMessages(); CacheDistributionAdvisor cda = partitionedRegion.getCacheDistributionAdvisor(); FilterRoutingInfo filterRouting = cda.adviseFilterRouting(event, recipients); Set<Object> adjunctRecipients = bucketRegion.getAdjunctReceivers(event, recipients, twoMessages, filterRouting); Set cacheServerMembers = cda.adviseCacheServers(); return !Collections.disjoint(adjunctRecipients, cacheServerMembers); }
@Override public void toData(DataOutput out) throws IOException { DataSerializer.writeObject(this.eventID, out); DataSerializer.writeObject(this.getRegion().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; }
@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; }