Search in sources :

Example 1 with TxKey

use of org.apache.ignite.internal.processors.cache.mvcc.txlog.TxKey in project ignite by apache.

the class MvccProcessorImpl method waitForLock.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<Void> waitForLock(GridCacheContext cctx, MvccVersion waiterVer, MvccVersion blockerVer) {
    TxKey key = new TxKey(blockerVer.coordinatorVersion(), blockerVer.counter());
    LockFuture fut = new LockFuture(cctx.ioPolicy(), waiterVer);
    Waiter waiter = waitMap.merge(key, fut, Waiter::concat);
    if (!waiter.hasLocalTransaction() && (waiter = waitMap.remove(key)) != null)
        waiter.run(ctx);
    else {
        DeadlockDetectionManager.DelayedDeadlockComputation delayedComputation = ctx.cache().context().deadlockDetectionMgr().initDelayedComputation(waiterVer, blockerVer);
        if (delayedComputation != null)
            fut.listen(fut0 -> delayedComputation.cancel());
    }
    return fut;
}
Also used : GridCompoundIdentityFuture(org.apache.ignite.internal.util.future.GridCompoundIdentityFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) TxLog(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxLog) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) MvccSnapshotResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccSnapshotResponse) ID_FILTER(org.apache.ignite.internal.processors.cache.mvcc.MvccCoordinatorChangeAware.ID_FILTER) MVCC_CRD_COUNTER_NA(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.MVCC_CRD_COUNTER_NA) PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics) GridCursor(org.apache.ignite.internal.util.lang.GridCursor) Map(java.util.Map) TxKey(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxKey) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) KEY_ONLY(org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter.RowData.KEY_ONLY) Stream(java.util.stream.Stream) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) MvccUtils.compare(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.compare) GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) IgniteThread(org.apache.ignite.thread.IgniteThread) MVCC_HINTS_BIT_OFF(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.MVCC_HINTS_BIT_OFF) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) MvccUtils.noCoordinatorError(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.noCoordinatorError) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) S(org.apache.ignite.internal.util.typedef.internal.S) MvccQuerySnapshotRequest(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccQuerySnapshotRequest) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) TX_LOG_CACHE_ID(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxLog.TX_LOG_CACHE_ID) MVCC_COUNTER_NA(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.MVCC_COUNTER_NA) MVCC_START_OP_CNTR(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.MVCC_START_OP_CNTR) MvccMessage(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccMessage) MVCC_READ_OP_CNTR(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.MVCC_READ_OP_CNTR) MvccTxSnapshotRequest(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccTxSnapshotRequest) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) MVCC_INITIAL_CNTR(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.MVCC_INITIAL_CNTR) CustomEventListener(org.apache.ignite.internal.managers.discovery.CustomEventListener) TX_LOG_CACHE_NAME(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxLog.TX_LOG_CACHE_NAME) GridProcessorAdapter(org.apache.ignite.internal.processors.GridProcessorAdapter) DatabaseLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.DatabaseLifecycleListener) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) DynamicCacheChangeRequest(org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) MvccUtils.isVisible(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.isVisible) SYSTEM_POOL(org.apache.ignite.internal.managers.communication.GridIoPolicy.SYSTEM_POOL) MvccUtils.belongToSameTx(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.belongToSameTx) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) GridLongList(org.apache.ignite.internal.util.GridLongList) MvccFutureResponse(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccFutureResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) X(org.apache.ignite.internal.util.typedef.X) TOPIC_CACHE_COORDINATOR(org.apache.ignite.internal.GridTopic.TOPIC_CACHE_COORDINATOR) MvccAckRequestTx(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestTx) IgniteFuture(org.apache.ignite.lang.IgniteFuture) FailureType(org.apache.ignite.failure.FailureType) MVCC_TRACKER_ID_NA(org.apache.ignite.internal.processors.cache.mvcc.MvccQueryTracker.MVCC_TRACKER_ID_NA) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IgniteDiagnosticPrepareContext(org.apache.ignite.internal.IgniteDiagnosticPrepareContext) UUID(java.util.UUID) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) GridSpinBusyLock(org.apache.ignite.internal.util.GridSpinBusyLock) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) DiscoveryEventListener(org.apache.ignite.internal.managers.eventstorage.DiscoveryEventListener) CU(org.apache.ignite.internal.util.typedef.internal.CU) Optional(java.util.Optional) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) NotNull(org.jetbrains.annotations.NotNull) MvccAckRequestQueryCntr(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestQueryCntr) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) HashMap(java.util.HashMap) MvccLinkAwareSearchRow(org.apache.ignite.internal.processors.cache.tree.mvcc.search.MvccLinkAwareSearchRow) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) HashSet(java.util.HashSet) FailureContext(org.apache.ignite.failure.FailureContext) IgniteNodeValidationResult(org.apache.ignite.spi.IgniteNodeValidationResult) IgniteClosure(org.apache.ignite.lang.IgniteClosure) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) MvccActiveQueriesMessage(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccActiveQueriesMessage) MvccRecoveryFinishedMessage(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccRecoveryFinishedMessage) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) MVCC_START_CNTR(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.MVCC_START_CNTR) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) MvccAckRequestQueryId(org.apache.ignite.internal.processors.cache.mvcc.msg.MvccAckRequestQueryId) TxState(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxState) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) MvccUtils.hasNewVersion(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.hasNewVersion) TxKey(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxKey)

Example 2 with TxKey

use of org.apache.ignite.internal.processors.cache.mvcc.txlog.TxKey in project ignite by apache.

the class MvccCachingManager method onTxFinished.

/**
 * @param tx Transaction.
 * @param commit {@code True} if commit.
 */
public void onTxFinished(IgniteInternalTx tx, boolean commit) throws IgniteCheckedException {
    if (log.isDebugEnabled())
        log.debug("Transaction finished: [commit=" + commit + ", tx=" + tx + ']');
    if (tx.system() || tx.internal() || tx.mvccSnapshot() == null)
        return;
    cntrs.remove(new TxKey(tx.mvccSnapshot().coordinatorVersion(), tx.mvccSnapshot().counter()));
    EnlistBuffer buf = enlistCache.remove(tx.xidVersion());
    Map<Integer, Map<KeyCacheObject, MvccTxEntry>> allCached = buf == null ? null : buf.getCached();
    TxCounters txCntrs = tx.txCounters(false);
    Collection<PartitionUpdateCountersMessage> cntrsColl = txCntrs == null ? null : txCntrs.updateCounters();
    if (txCntrs == null || F.isEmpty(cntrsColl))
        return;
    GridIntList cacheIds = tx.txState().cacheIds();
    assert cacheIds != null;
    for (int i = 0; i < cacheIds.size(); i++) {
        int cacheId = cacheIds.get(i);
        GridCacheContext ctx0 = cctx.cacheContext(cacheId);
        assert ctx0 != null;
        ctx0.group().listenerLock().readLock().lock();
        try {
            boolean hasListeners = ctx0.hasContinuousQueryListeners(tx);
            boolean drEnabled = ctx0.isDrEnabled();
            if (!hasListeners && !drEnabled)
                // There are no listeners to notify.
                continue;
            // Get cached entries for the given cache.
            Map<KeyCacheObject, MvccTxEntry> cached = allCached == null ? null : allCached.get(cacheId);
            Map<Integer, Map<Integer, T2<AtomicLong, Long>>> cntrsMap = countersPerPartition(cntrsColl);
            Map<Integer, T2<AtomicLong, Long>> cntrPerCache = cntrsMap.get(cacheId);
            if (F.isEmpty(cntrPerCache))
                // No updates were made for this cache.
                continue;
            boolean fakeEntries = false;
            if (F.isEmpty(cached)) {
                if (log.isDebugEnabled())
                    log.debug("Transaction updates were not cached fully (this can happen when listener started" + " during the transaction execution). [tx=" + tx + ']');
                if (hasListeners) {
                    // Create fake update entries if we have CQ listeners.
                    cached = createFakeCachedEntries(cntrPerCache, tx, cacheId);
                    fakeEntries = true;
                } else
                    // Nothing to do further if tx is not cached entirely and there are no any CQ listeners.
                    continue;
            }
            if (F.isEmpty(cached))
                continue;
            // Feed CQ & DR with entries.
            for (Map.Entry<KeyCacheObject, MvccTxEntry> entry : cached.entrySet()) {
                MvccTxEntry e = entry.getValue();
                assert e.key().partition() != -1;
                assert cntrPerCache != null;
                assert e.cacheId() == cacheId;
                T2<AtomicLong, Long> cntr = cntrPerCache.get(e.key().partition());
                long resCntr = cntr.getKey().incrementAndGet();
                assert resCntr <= cntr.getValue();
                e.updateCounter(resCntr);
                if (ctx0.group().sharedGroup()) {
                    ctx0.group().onPartitionCounterUpdate(cacheId, e.key().partition(), resCntr, tx.topologyVersion(), tx.local());
                }
                if (log.isDebugEnabled())
                    log.debug("Process cached entry:" + e);
                // DR
                if (ctx0.isDrEnabled() && !fakeEntries) {
                    ctx0.dr().replicate(e.key(), e.value(), e.ttl(), e.expireTime(), e.version(), tx.local() ? DR_PRIMARY : DR_BACKUP, e.topologyVersion());
                }
                // CQ
                CacheContinuousQueryManager contQryMgr = ctx0.continuousQueries();
                if (ctx0.continuousQueries().notifyContinuousQueries(tx)) {
                    Map<UUID, CacheContinuousQueryListener> lsnrCol = continuousQueryListeners(ctx0, tx);
                    if (!F.isEmpty(lsnrCol)) {
                        contQryMgr.onEntryUpdated(lsnrCol, e.key(), // Force skip update counter if rolled back.
                        commit ? e.value() : null, // Force skip update counter if rolled back.
                        commit ? e.oldValue() : null, false, e.key().partition(), tx.local(), false, e.updateCounter(), null, e.topologyVersion());
                    }
                }
            }
        } finally {
            ctx0.group().listenerLock().readLock().unlock();
        }
    }
}
Also used : TxKey(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxKey) CacheContinuousQueryManager(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager) CacheContinuousQueryListener(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryListener) PartitionUpdateCountersMessage(org.apache.ignite.internal.processors.cache.distributed.dht.PartitionUpdateCountersMessage) UUID(java.util.UUID) T2(org.apache.ignite.internal.util.typedef.T2) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) TxCounters(org.apache.ignite.internal.processors.cache.transactions.TxCounters) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridIntList(org.apache.ignite.internal.util.GridIntList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 3 with TxKey

use of org.apache.ignite.internal.processors.cache.mvcc.txlog.TxKey in project ignite by apache.

the class MvccCachingManager method addEnlisted.

/**
 * Adds enlisted tx entry to cache.
 *
 * @param key Key.
 * @param val Value.
 * @param ttl Time to live.
 * @param expireTime Expire time.
 * @param ver Version.
 * @param oldVal Old value.
 * @param primary Flag whether this is a primary node.
 * @param topVer Topology version.
 * @param mvccVer Mvcc version.
 * @param cacheId Cache id.
 * @param tx Transaction.
 * @param futId Dht future id.
 * @param batchNum Batch number (for batches reordering prevention).
 * @throws IgniteCheckedException If failed.
 */
public void addEnlisted(KeyCacheObject key, @Nullable CacheObject val, long ttl, long expireTime, GridCacheVersion ver, CacheObject oldVal, boolean primary, AffinityTopologyVersion topVer, MvccVersion mvccVer, int cacheId, IgniteInternalTx tx, IgniteUuid futId, int batchNum) throws IgniteCheckedException {
    assert key != null;
    assert mvccVer != null;
    assert tx != null;
    if (log.isDebugEnabled()) {
        log.debug("Added entry to mvcc cache: [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ", primary=" + primary + ", mvccVer=" + mvccVer + ", cacheId=" + cacheId + ", ver=" + ver + ']');
    }
    // Do not cache updates if there are no DR or CQ were enabled when cache was added as active for the current tx.
    if (!tx.txState().useMvccCaching(cacheId))
        return;
    AtomicInteger cntr = cntrs.computeIfAbsent(new TxKey(mvccVer.coordinatorVersion(), mvccVer.counter()), v -> new AtomicInteger());
    if (cntr.incrementAndGet() > TX_SIZE_THRESHOLD)
        throw new IgniteCheckedException("Transaction is too large. Consider reducing transaction size or " + "turning off continuous queries and datacenter replication [size=" + cntr.get() + ", txXid=" + ver + ']');
    MvccTxEntry e = new MvccTxEntry(key, val, ttl, expireTime, ver, oldVal, primary, topVer, mvccVer, cacheId);
    EnlistBuffer cached = enlistCache.computeIfAbsent(ver, v -> new EnlistBuffer());
    cached.add(primary ? null : futId, primary ? -1 : batchNum, e);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TxKey(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxKey)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TxKey (org.apache.ignite.internal.processors.cache.mvcc.txlog.TxKey)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 BlockingQueue (java.util.concurrent.BlockingQueue)1