Search in sources :

Example 1 with GridDhtTxOnePhaseCommitAckRequest

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxOnePhaseCommitAckRequest in project ignite by apache.

the class IgniteTxManager method start0.

/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
    txFinishSync = new GridCacheTxFinishSync<>(cctx);
    txHnd = new IgniteTxHandler(cctx);
    deferredAckMsgSnd = new GridDeferredAckMessageSender<GridCacheVersion>(cctx.time(), cctx.kernalContext().closure()) {

        @Override
        public int getTimeout() {
            return DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_TIMEOUT;
        }

        @Override
        public int getBufferSize() {
            return DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_BUFFER_SIZE;
        }

        @Override
        public void finish(UUID nodeId, ConcurrentLinkedDeque8<GridCacheVersion> vers) {
            GridDhtTxOnePhaseCommitAckRequest ackReq = new GridDhtTxOnePhaseCommitAckRequest(vers);
            cctx.kernalContext().gateway().readLock();
            try {
                cctx.io().send(nodeId, ackReq, GridIoPolicy.SYSTEM_POOL);
            } catch (ClusterTopologyCheckedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Failed to send one phase commit ack to backup node because it left grid: " + nodeId);
            } catch (IgniteCheckedException e) {
                log.error("Failed to send one phase commit ack to backup node [backup=" + nodeId + ']', e);
            } finally {
                cctx.kernalContext().gateway().readUnlock();
            }
        }
    };
    cctx.gridEvents().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt instanceof DiscoveryEvent;
            assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT;
            DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
            UUID nodeId = discoEvt.eventNode().id();
            // Wait some time in case there are some unprocessed messages from failed node.
            cctx.time().addTimeoutObject(new NodeFailureTimeoutObject(nodeId));
            if (txFinishSync != null)
                txFinishSync.onNodeLeft(nodeId);
            for (TxDeadlockFuture fut : deadlockDetectFuts.values()) fut.onNodeLeft(nodeId);
            for (Map.Entry<GridCacheVersion, Object> entry : completedVersHashMap.entrySet()) {
                Object obj = entry.getValue();
                if (obj instanceof GridCacheReturnCompletableWrapper && nodeId.equals(((GridCacheReturnCompletableWrapper) obj).nodeId()))
                    removeTxReturn(entry.getKey());
            }
        }
    }, EVT_NODE_FAILED, EVT_NODE_LEFT);
    this.txDeadlockDetection = new TxDeadlockDetection(cctx);
    cctx.gridIO().addMessageListener(TOPIC_TX, new DeadlockDetectionListener());
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtTxOnePhaseCommitAckRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxOnePhaseCommitAckRequest) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID) GridCacheReturnCompletableWrapper(org.apache.ignite.internal.processors.cache.GridCacheReturnCompletableWrapper) TxDeadlockFuture(org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

UUID (java.util.UUID)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 Event (org.apache.ignite.events.Event)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)1 GridCacheMapEntry (org.apache.ignite.internal.processors.cache.GridCacheMapEntry)1 GridCacheReturnCompletableWrapper (org.apache.ignite.internal.processors.cache.GridCacheReturnCompletableWrapper)1 GridDhtTxOnePhaseCommitAckRequest (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxOnePhaseCommitAckRequest)1 GridNearCacheEntry (org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry)1 TxDeadlockFuture (org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture)1 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)1