Search in sources :

Example 1 with TransactionDataRebalancedException

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);
        }
    }
}
Also used : CommitConflictException(org.apache.geode.cache.CommitConflictException) TransactionWriter(org.apache.geode.cache.TransactionWriter) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 2 with TransactionDataRebalancedException

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;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 3 with TransactionDataRebalancedException

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);
    }
}
Also used : Entry(org.apache.geode.cache.Region.Entry) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 4 with TransactionDataRebalancedException

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;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 5 with TransactionDataRebalancedException

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;
    }
}
Also used : Entry(org.apache.geode.cache.Region.Entry) TransactionException(org.apache.geode.cache.TransactionException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Aggregations

TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)19 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)9 TransactionException (org.apache.geode.cache.TransactionException)9 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)6 CommitConflictException (org.apache.geode.cache.CommitConflictException)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 Entry (org.apache.geode.cache.Region.Entry)4 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 ArrayList (java.util.ArrayList)3 CacheException (org.apache.geode.cache.CacheException)3 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)3 Region (org.apache.geode.cache.Region)3 TransactionDataNodeHasDepartedException (org.apache.geode.cache.TransactionDataNodeHasDepartedException)3 TransactionWriterException (org.apache.geode.cache.TransactionWriterException)3 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)3 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)3 CustId (org.apache.geode.internal.cache.execute.data.CustId)3 HashSet (java.util.HashSet)2