Search in sources :

Example 6 with TXStateProxy

use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.

the class DefaultQuery method executeUsingContext.

public Object executeUsingContext(ExecutionContext context) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    QueryObserver observer = QueryObserverHolder.getInstance();
    long startTime = CachePerfStats.getStatTime();
    TXStateProxy tx = ((TXManagerImpl) this.cache.getCacheTransactionManager()).internalSuspend();
    try {
        observer.startQuery(this);
        observer.beforeQueryEvaluation(this.compiledQuery, context);
        if (DefaultQuery.testHook != null) {
            DefaultQuery.testHook.doTestHook(6);
        }
        Object results = null;
        try {
            // two-pass evaluation.
            // first pre-compute dependencies, cached in the context.
            this.compiledQuery.computeDependencies(context);
            if (testHook != null) {
                testHook.doTestHook(1);
            }
            results = this.compiledQuery.evaluate(context);
        } catch (QueryExecutionCanceledException ignore) {
            // when query is canceled.
            if (this.canceledException != null) {
                throw this.canceledException;
            } else {
                throw new QueryExecutionCanceledException("Query was canceled. It may be due to low memory or the query was running longer than the MAX_QUERY_EXECUTION_TIME.");
            }
        } finally {
            observer.afterQueryEvaluation(results);
        }
        return results;
    } finally {
        observer.endQuery();
        long endTime = CachePerfStats.getStatTime();
        updateStatistics(endTime - startTime);
        pdxClassToFieldsMap.remove();
        pdxClassToMethodsMap.remove();
        ((TXManagerImpl) this.cache.getCacheTransactionManager()).internalResume(tx);
    }
}
Also used : TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy)

Example 7 with TXStateProxy

use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.

the class PartitionMessage method process.

/**
   * Upon receipt of the message, both process the message and send an acknowledgement, not
   * necessarily in that order. Note: Any hang in this message may cause a distributed deadlock for
   * those threads waiting for an acknowledgement.
   * 
   * @throws PartitionedRegionException if the region does not exist (typically, if it has been
   *         destroyed)
   */
@Override
public void process(final DistributionManager dm) {
    Throwable thr = null;
    boolean sendReply = true;
    PartitionedRegion pr = null;
    long startTime = 0;
    EntryLogger.setSource(getSender(), "PR");
    try {
        if (checkCacheClosing(dm) || checkDSClosing(dm)) {
            thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
            return;
        }
        pr = getPartitionedRegion();
        if (pr == null && failIfRegionMissing()) {
            // if the distributed system is disconnecting, don't send a reply saying
            // the partitioned region can't be found (bug 36585)
            thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_0_COULD_NOT_FIND_PARTITIONED_REGION_WITH_ID_1.toLocalizedString(dm.getDistributionManagerId(), regionId));
            // reply sent in finally block below
            return;
        }
        if (pr != null) {
            startTime = getStartPartitionMessageProcessingTime(pr);
        }
        thr = UNHANDLED_EXCEPTION;
        InternalCache cache = getInternalCache();
        if (cache == null) {
            throw new ForceReattemptException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString());
        }
        TXManagerImpl txMgr = getTXManagerImpl(cache);
        TXStateProxy tx = txMgr.masqueradeAs(this);
        if (tx == null) {
            sendReply = operateOnPartitionedRegion(dm, pr, startTime);
        } else {
            try {
                if (txMgr.isClosed()) {
                    // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
                    sendReply = false;
                } else if (tx.isInProgress()) {
                    sendReply = operateOnPartitionedRegion(dm, pr, startTime);
                    tx.updateProxyServer(this.getSender());
                }
            } finally {
                txMgr.unmasquerade(tx);
            }
        }
        thr = null;
    } catch (ForceReattemptException fre) {
        thr = fre;
    } catch (DataLocationException fre) {
        thr = new ForceReattemptException(fre.getMessage(), fre);
    } catch (DistributedSystemDisconnectedException se) {
        // bug 37026: this is too noisy...
        // throw new CacheClosedException("remote system shutting down");
        // thr = se; cache is closed, no point trying to send a reply
        thr = null;
        sendReply = false;
        if (logger.isDebugEnabled()) {
            logger.debug("shutdown caught, abandoning message: {}", se.getMessage(), se);
        }
    } catch (RegionDestroyedException | RegionNotFoundException rde) {
        // [bruce] RDE does not always mean that the sender's region is also
        // destroyed, so we must send back an exception. If the sender's
        // region is also destroyed, who cares if we send it an exception
        // if (pr != null && pr.isClosed) {
        thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_REGION_IS_DESTROYED_IN_0.toLocalizedString(dm.getDistributionManagerId()), rde);
    // }
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // 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();
        // log the exception at fine level if there is no reply to the message
        thr = null;
        if (sendReply) {
            if (!checkDSClosing(dm)) {
                thr = t;
            } else {
                // don't pass arbitrary runtime exceptions and errors back if this
                // cache/vm is closing
                thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_DISTRIBUTED_SYSTEM_IS_DISCONNECTING.toLocalizedString());
            }
        }
        if (logger.isTraceEnabled(LogMarker.DM) && t instanceof RuntimeException) {
            logger.trace(LogMarker.DM, "Exception caught while processing message: {}", t.getMessage(), t);
        }
    } finally {
        if (sendReply) {
            ReplyException rex = null;
            if (thr != null) {
                // don't transmit the exception if this message was to a listener
                // and this listener is shutting down
                boolean excludeException = this.notificationOnly && ((thr instanceof CancelException) || (thr instanceof ForceReattemptException));
                if (!excludeException) {
                    rex = new ReplyException(thr);
                }
            }
            // Send the reply if the operateOnPartitionedRegion returned true
            sendReply(getSender(), this.processorId, dm, rex, pr, startTime);
            EntryLogger.clearSource();
        }
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) DataLocationException(org.apache.geode.internal.cache.DataLocationException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheClosedException(org.apache.geode.cache.CacheClosedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CancelException(org.apache.geode.CancelException)

Example 8 with TXStateProxy

use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.

the class PartitionMessage method initTxMemberId.

public void initTxMemberId() {
    this.txUniqId = TXManagerImpl.getCurrentTXUniqueId();
    TXStateProxy txState = TXManagerImpl.getCurrentTXState();
    if (txState != null) {
        // [DISTTX] Lets not throw this exception for Dist Tx
        if (canStartRemoteTransaction() && txState.isRealDealLocal() && !txState.isDistTx()) {
            // RuntimeException("STACK"));
            throw new IllegalStateException("Sending remote txId even though transaction is local. This should never happen: txState=" + txState);
        }
    }
    if (txState != null && txState.isMemberIdForwardingRequired()) {
        this.txMemberId = txState.getOriginatingMember();
    }
}
Also used : TXStateProxy(org.apache.geode.internal.cache.TXStateProxy)

Example 9 with TXStateProxy

use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.

the class GetMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(final DistributionManager dm, PartitionedRegion r, long startTime) throws ForceReattemptException {
    if (logger.isTraceEnabled(LogMarker.DM)) {
        logger.trace(LogMarker.DM, "GetMessage operateOnRegion: {}", r.getFullPath());
    }
    PartitionedRegionDataStore ds = r.getDataStore();
    if (this.getTXUniqId() != TXManagerImpl.NOTX) {
        assert r.getDataView() instanceof TXStateProxy;
    }
    RawValue valueBytes;
    Object val = null;
    try {
        if (ds != null) {
            VersionTagHolder event = new VersionTagHolder();
            try {
                KeyInfo keyInfo = r.getKeyInfo(key, cbArg);
                boolean lockEntry = forceUseOfPRExecutor || isDirectAck();
                val = r.getDataView().getSerializedValue(r, keyInfo, !lockEntry, this.context, event, returnTombstones);
                if (val == BucketRegion.REQUIRES_ENTRY_LOCK) {
                    Assert.assertTrue(!lockEntry);
                    this.forceUseOfPRExecutor = true;
                    if (logger.isDebugEnabled()) {
                        logger.debug("Rescheduling GetMessage due to possible cache-miss");
                    }
                    schedule(dm);
                    return false;
                }
                valueBytes = val instanceof RawValue ? (RawValue) val : new RawValue(val);
            } catch (DistributedSystemDisconnectedException sde) {
                sendReply(getSender(), this.processorId, dm, new ReplyException(new ForceReattemptException(LocalizedStrings.GetMessage_OPERATION_GOT_INTERRUPTED_DUE_TO_SHUTDOWN_IN_PROGRESS_ON_REMOTE_VM.toLocalizedString(), sde)), r, startTime);
                return false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                return false;
            } catch (DataLocationException e) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(e), r, startTime);
                return false;
            }
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.debug("GetMessage sending serialized value {} back via GetReplyMessage using processorId: {}", valueBytes, getProcessorId());
            }
            r.getPrStats().endPartitionMessagesProcessing(startTime);
            GetReplyMessage.send(getSender(), getProcessorId(), valueBytes, getReplySender(dm), event.getVersionTag());
            // response
            return false;
        } else {
            throw new InternalGemFireError(LocalizedStrings.GetMessage_GET_MESSAGE_SENT_TO_WRONG_MEMBER.toLocalizedString());
        }
    } finally {
        OffHeapHelper.release(val);
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) KeyInfo(org.apache.geode.internal.cache.KeyInfo) RawValue(org.apache.geode.internal.cache.BucketRegion.RawValue) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 10 with TXStateProxy

use of org.apache.geode.internal.cache.TXStateProxy in project geode by apache.

the class TXFailoverCommand method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    // Build the TXId for the transaction
    InternalDistributedMember client = (InternalDistributedMember) serverConnection.getProxyID().getDistributedMember();
    int uniqId = clientMessage.getTransactionId();
    if (logger.isDebugEnabled()) {
        logger.debug("TX: Transaction {} from {} is failing over to this server", uniqId, client);
    }
    TXId txId = new TXId(client, uniqId);
    TXManagerImpl mgr = (TXManagerImpl) serverConnection.getCache().getCacheTransactionManager();
    // in case it's already completing here in another
    mgr.waitForCompletingTransaction(txId);
    // thread
    if (mgr.isHostedTxRecentlyCompleted(txId)) {
        writeReply(clientMessage, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        mgr.removeHostedTXState(txId);
        return;
    }
    // fixes bug 43350
    boolean wasInProgress = mgr.setInProgress(true);
    TXStateProxy tx = mgr.getTXState();
    Assert.assertTrue(tx != null);
    if (!tx.isRealDealLocal()) {
        // send message to all peers to find out who hosts the transaction
        FindRemoteTXMessageReplyProcessor processor = FindRemoteTXMessage.send(serverConnection.getCache(), txId);
        try {
            processor.waitForRepliesUninterruptibly();
        } catch (ReplyException e) {
            e.handleAsUnexpected();
        }
        // if hosting member is not null, bootstrap PeerTXStateStub to that member
        // if hosting member is null, rebuild TXCommitMessage from partial TXCommitMessages
        InternalDistributedMember hostingMember = processor.getHostingMember();
        if (hostingMember != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("TX: txState is not local, bootstrapping PeerTXState stub for targetNode: {}", hostingMember);
            }
            // inject the real deal
            tx.setLocalTXState(new PeerTXStateStub(tx, hostingMember, client));
        } else {
            // bug #42228 and bug #43504 - this cannot return until the current view
            // has been installed by all members, so that dlocks are released and
            // the same keys can be used in a new transaction by the same client thread
            InternalCache cache = serverConnection.getCache();
            try {
                WaitForViewInstallation.send((DistributionManager) cache.getDistributionManager());
            } catch (InterruptedException e) {
                cache.getDistributionManager().getCancelCriterion().checkCancelInProgress(e);
                Thread.currentThread().interrupt();
            }
            // tx host has departed, rebuild the tx
            if (processor.getTxCommitMessage() != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("TX: for txId: {} rebuilt a recently completed tx", txId);
                }
                mgr.saveTXCommitMessageForClientFailover(txId, processor.getTxCommitMessage());
            } else {
                writeException(clientMessage, new TransactionDataNodeHasDepartedException("Could not find transaction host for " + txId), false, serverConnection);
                serverConnection.setAsTrue(RESPONDED);
                mgr.removeHostedTXState(txId);
                return;
            }
        }
    }
    if (!wasInProgress) {
        mgr.setInProgress(false);
    }
    writeReply(clientMessage, serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) TXId(org.apache.geode.internal.cache.TXId) InternalCache(org.apache.geode.internal.cache.InternalCache) FindRemoteTXMessageReplyProcessor(org.apache.geode.internal.cache.FindRemoteTXMessage.FindRemoteTXMessageReplyProcessor) ReplyException(org.apache.geode.distributed.internal.ReplyException) PeerTXStateStub(org.apache.geode.internal.cache.PeerTXStateStub) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Aggregations

TXStateProxy (org.apache.geode.internal.cache.TXStateProxy)37 TXManagerImpl (org.apache.geode.internal.cache.TXManagerImpl)20 Test (org.junit.Test)9 CommitConflictException (org.apache.geode.cache.CommitConflictException)8 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)8 IOException (java.io.IOException)6 TransactionException (org.apache.geode.cache.TransactionException)6 InternalCache (org.apache.geode.internal.cache.InternalCache)6 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 InternalGemFireError (org.apache.geode.InternalGemFireError)5 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)5 EntryExistsException (org.apache.geode.cache.EntryExistsException)5 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 CacheWriterException (org.apache.geode.cache.CacheWriterException)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 Region (org.apache.geode.cache.Region)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ResourceException (javax.resource.ResourceException)3