use of org.apache.geode.cache.TransactionDataRebalancedException in project geode by apache.
the class DistTXState method precommit.
/*
* (non-Javadoc)
*
* @see org.apache.geode.internal.cache.TXStateInterface#commit()
*
* Take Locks Does conflict check on primary ([DISTTX] TODO on primary only) Invoke TxWriter
*/
@Override
public void precommit() throws CommitConflictException, UnsupportedOperationInTransactionException {
if (logger.isDebugEnabled()) {
logger.debug("DistTXState.precommit transaction {} is closed {} ", getTransactionId(), this.closed, new Throwable());
}
if (this.closed) {
return;
}
synchronized (this.completionGuard) {
this.completionStarted = true;
}
if (onBehalfOfRemoteStub && !proxy.isCommitOnBehalfOfRemoteStub()) {
throw new UnsupportedOperationInTransactionException(LocalizedStrings.TXState_CANNOT_COMMIT_REMOTED_TRANSACTION.toLocalizedString());
}
cleanupNonDirtyRegions();
/*
* Lock buckets so they can't be rebalanced then perform the conflict check to fix #43489
*/
try {
lockBucketRegions();
} catch (PrimaryBucketException pbe) {
// not sure what to do here yet
RuntimeException re = new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString());
re.initCause(pbe);
throw re;
}
if (this.locks == null) {
reserveAndCheck();
}
// For internal testing
if (this.internalAfterConflictCheck != null) {
this.internalAfterConflictCheck.run();
}
updateRegionVersions();
generateTailKeysForParallelDispatcherEvents();
/*
* If there is a TransactionWriter plugged in, we need to to give it an opportunity to abort the
* transaction.
*/
TransactionWriter writer = this.proxy.getTxMgr().getWriter();
if (!firedWriter && writer != null) {
try {
firedWriter = true;
writer.beforeCommit(getEvent());
} catch (TransactionWriterException twe) {
cleanup();
throw new CommitConflictException(twe);
} catch (VirtualMachineError err) {
// cleanup(); this allocates objects so I don't think we can do it -
// that leaves the TX open, but we are poison pilling so we should be
// ok??
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// rollback the transaction!
cleanup();
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
throw new CommitConflictException(t);
}
}
}
use of org.apache.geode.cache.TransactionDataRebalancedException in project geode by apache.
the class PartitionedRegion method getDataRegionForWrite.
@Override
public LocalRegion getDataRegionForWrite(KeyInfo keyInfo) {
BucketRegion br = null;
final Object entryKey = keyInfo.getKey();
try {
final int retryAttempts = calcRetry();
// TODO provide appropriate Operation and arg
int bucketId = keyInfo.getBucketId();
if (bucketId == KeyInfo.UNKNOWN_BUCKET) {
bucketId = PartitionedRegionHelper.getHashKey(this, null, entryKey, keyInfo.getValue(), keyInfo.getCallbackArg());
keyInfo.setBucketId(bucketId);
}
int count = 0;
while (count <= retryAttempts) {
try {
PartitionedRegionDataStore ds = getDataStore();
if (ds == null) {
throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_ON_DATASTORE.toLocalizedString());
}
br = ds.getInitializedBucketWithKnownPrimaryForId(entryKey, bucketId);
break;
} catch (ForceReattemptException ignore) {
// create a new bucket
InternalDistributedMember member = createBucket(bucketId, 0, null);
if (!getMyId().equals(member) && keyInfo.isCheckPrimary()) {
throw new PrimaryBucketException("Bucket " + bucketId + " is not primary. Current primary holder is " + member);
}
count++;
}
}
Assert.assertTrue(br != null, "Could not create storage for Entry");
if (keyInfo.isCheckPrimary()) {
br.checkForPrimary();
}
} catch (PrimaryBucketException pbe) {
throw new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString(), pbe);
} catch (RegionDestroyedException ignore) {
// TODO: why is this purposely not wrapping the original cause?
throw new TransactionDataNotColocatedException(LocalizedStrings.PartitionedRegion_KEY_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(entryKey));
}
return br;
}
use of org.apache.geode.cache.TransactionDataRebalancedException in project geode by apache.
the class TXStateProxyImpl method accessEntry.
public Entry accessEntry(KeyInfo keyInfo, LocalRegion region) {
try {
this.operationCount++;
Entry retVal = getRealDeal(keyInfo, region).accessEntry(keyInfo, region);
trackBucketForTx(keyInfo);
return retVal;
} catch (TransactionDataRebalancedException | PrimaryBucketException re) {
throw getTransactionException(keyInfo, re);
}
}
use of org.apache.geode.cache.TransactionDataRebalancedException in project geode by apache.
the class TXStateProxyImpl method getTransactionException.
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;
}
use of org.apache.geode.cache.TransactionDataRebalancedException in project geode by apache.
the class PartitionedTXRegionStub method getEntry.
public Entry getEntry(KeyInfo keyInfo, boolean allowTombstones) {
PartitionedRegion pr = (PartitionedRegion) region;
try {
Entry e = pr.getEntryRemotely((InternalDistributedMember) state.getTarget(), keyInfo.getBucketId(), keyInfo.getKey(), false, allowTombstones);
trackBucketForTx(keyInfo);
return e;
} catch (EntryNotFoundException enfe) {
return null;
} catch (TransactionException e) {
RuntimeException re = getTransactionException(keyInfo, e);
re.initCause(e.getCause());
throw re;
} catch (PrimaryBucketException e) {
RuntimeException re = getTransactionException(keyInfo, e);
re.initCause(e);
throw re;
} catch (ForceReattemptException e) {
RuntimeException re;
if (isBucketNotFoundException(e)) {
re = new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString());
} else {
re = new TransactionDataNodeHasDepartedException(LocalizedStrings.PartitionedRegion_TRANSACTION_DATA_NODE_0_HAS_DEPARTED_TO_PROCEED_ROLLBACK_THIS_TRANSACTION_AND_BEGIN_A_NEW_ONE.toLocalizedString(state.getTarget()));
}
re.initCause(e);
waitToRetry();
throw re;
}
}
Aggregations