Search in sources :

Example 1 with GridCacheMvccEntryInfo

use of org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo in project ignite by apache.

the class GridDhtPartitionSupplier method extractEntryInfo.

/**
 * Extracts entry info from row.
 *
 * @param row Cache data row.
 * @return Entry info.
 */
private GridCacheEntryInfo extractEntryInfo(CacheDataRow row) {
    GridCacheEntryInfo info = grp.mvccEnabled() ? new GridCacheMvccEntryInfo() : new GridCacheEntryInfo();
    info.key(row.key());
    info.cacheId(row.cacheId());
    if (grp.mvccEnabled()) {
        assert row.mvccCoordinatorVersion() != MvccUtils.MVCC_CRD_COUNTER_NA;
        // Rows from rebalance iterator have actual states already.
        if (row.mvccTxState() != TxState.COMMITTED)
            return null;
        ((MvccVersionAware) info).mvccVersion(row);
        ((GridCacheMvccEntryInfo) info).mvccTxState(TxState.COMMITTED);
        if (row.newMvccCoordinatorVersion() != MvccUtils.MVCC_CRD_COUNTER_NA && row.newMvccTxState() == TxState.COMMITTED) {
            ((MvccUpdateVersionAware) info).newMvccVersion(row);
            ((GridCacheMvccEntryInfo) info).newMvccTxState(TxState.COMMITTED);
        }
    }
    info.value(row.value());
    info.version(row.version());
    info.expireTime(row.expireTime());
    return info;
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) MvccVersionAware(org.apache.ignite.internal.processors.cache.mvcc.MvccVersionAware) GridCacheMvccEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo) MvccUpdateVersionAware(org.apache.ignite.internal.processors.cache.mvcc.MvccUpdateVersionAware)

Example 2 with GridCacheMvccEntryInfo

use of org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo in project ignite by apache.

the class GridDhtTxAbstractEnlistFuture method fetchHistoryInfo.

/**
 * @param key Key.
 * @param hist History rows.
 * @return History entries.
 * @throws IgniteCheckedException, if failed.
 */
private CacheEntryInfoCollection fetchHistoryInfo(KeyCacheObject key, List<MvccLinkAwareSearchRow> hist) {
    List<GridCacheEntryInfo> res = new ArrayList<>();
    for (int i = 0; i < hist.size(); i++) {
        MvccLinkAwareSearchRow row0 = hist.get(i);
        MvccDataRow row = new MvccDataRow(cctx.group(), row0.hash(), row0.link(), key.partition(), CacheDataRowAdapter.RowData.NO_KEY_WITH_HINTS, row0.mvccCoordinatorVersion(), row0.mvccCounter(), row0.mvccOperationCounter(), false);
        GridCacheMvccEntryInfo entry = new GridCacheMvccEntryInfo();
        entry.cacheId(cctx.cacheId());
        entry.version(row.version());
        entry.value(row.value());
        entry.expireTime(row.expireTime());
        // Row should be retrieved with actual hints.
        entry.mvccVersion(row);
        entry.newMvccVersion(row);
        if (MvccUtils.compare(mvccSnapshot, row.mvccCoordinatorVersion(), row.mvccCounter()) != 0)
            entry.mvccTxState(row.mvccTxState());
        if (row.newMvccCoordinatorVersion() != MvccUtils.MVCC_CRD_COUNTER_NA && MvccUtils.compare(mvccSnapshot, row.newMvccCoordinatorVersion(), row.newMvccCounter()) != 0)
            entry.newMvccTxState(row.newMvccTxState());
        assert mvccSnapshot.coordinatorVersion() != MvccUtils.MVCC_CRD_COUNTER_NA;
        res.add(entry);
    }
    return new CacheEntryInfoCollection(res);
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridCacheMvccEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) ArrayList(java.util.ArrayList) MvccDataRow(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataRow) MvccLinkAwareSearchRow(org.apache.ignite.internal.processors.cache.tree.mvcc.search.MvccLinkAwareSearchRow)

Example 3 with GridCacheMvccEntryInfo

use of org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo in project ignite by apache.

the class GridDhtPartitionDemander method mvccPreloadEntries.

/**
 * Adds mvcc entries with theirs history to partition p.
 *
 * @param topVer Topology version.
 * @param node Node which sent entry.
 * @param p Partition id.
 * @param infos Entries info for preload.
 * @throws IgniteCheckedException If failed.
 */
private void mvccPreloadEntries(AffinityTopologyVersion topVer, ClusterNode node, int p, Iterator<GridCacheEntryInfo> infos) throws IgniteCheckedException {
    if (!infos.hasNext())
        return;
    // Received keys by caches, for statistics.
    IntHashMap<GridMutableLong> receivedKeys = new IntHashMap<>();
    List<GridCacheMvccEntryInfo> entryHist = new ArrayList<>();
    GridCacheContext<?, ?> cctx = grp.sharedGroup() ? null : grp.singleCacheContext();
    // Loop through all received entries and try to preload them.
    while (infos.hasNext() || !entryHist.isEmpty()) {
        ctx.database().checkpointReadLock();
        try {
            for (int i = 0; i < PRELOAD_SIZE_UNDER_CHECKPOINT_LOCK; i++) {
                boolean hasMore = infos.hasNext();
                assert hasMore || !entryHist.isEmpty();
                GridCacheMvccEntryInfo entry = null;
                boolean flushHistory;
                if (hasMore) {
                    entry = (GridCacheMvccEntryInfo) infos.next();
                    GridCacheMvccEntryInfo prev = entryHist.isEmpty() ? null : entryHist.get(0);
                    flushHistory = prev != null && ((grp.sharedGroup() && prev.cacheId() != entry.cacheId()) || !prev.key().equals(entry.key()));
                } else
                    flushHistory = true;
                if (flushHistory) {
                    assert !entryHist.isEmpty();
                    int cacheId = entryHist.get(0).cacheId();
                    if (grp.sharedGroup() && (cctx == null || cacheId != cctx.cacheId())) {
                        assert cacheId != CU.UNDEFINED_CACHE_ID;
                        cctx = grp.shared().cacheContext(cacheId);
                    }
                    if (cctx != null) {
                        mvccPreloadEntry(cctx, node, entryHist, topVer, p);
                        rebalanceFut.onReceivedKeys(p, 1, node);
                        receivedKeys.computeIfAbsent(cacheId, cid -> new GridMutableLong()).incrementAndGet();
                    }
                    entryHist.clear();
                    if (!hasMore)
                        break;
                }
                entryHist.add(entry);
            }
        } finally {
            ctx.database().checkpointReadUnlock();
        }
    }
    updateKeyReceivedMetrics(grp, receivedKeys);
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) Collectors.counting(java.util.stream.Collectors.counting) IteratorWrapper(org.apache.ignite.internal.util.lang.GridIterableAdapter.IteratorWrapper) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) EVT_CACHE_REBALANCE_STARTED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STARTED) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) EVT_CACHE_REBALANCE_STOPPED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STOPPED) EVT_CACHE_REBALANCE_PART_LOADED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_LOADED) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) Collectors.toSet(java.util.stream.Collectors.toSet) CACHE_GROUP_METRICS_PREFIX(org.apache.ignite.internal.processors.cache.CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) AtomicReferenceFieldUpdater(java.util.concurrent.atomic.AtomicReferenceFieldUpdater) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DR_PRELOAD(org.apache.ignite.internal.processors.dr.GridDrType.DR_PRELOAD) Set(java.util.Set) NavigableSet(java.util.NavigableSet) UUID(java.util.UUID) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) Objects.nonNull(java.util.Objects.nonNull) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) EVT_CACHE_REBALANCE_OBJECT_LOADED(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_OBJECT_LOADED) GridCachePartitionExchangeManager(org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager) LongAdder(java.util.concurrent.atomic.LongAdder) DR_NONE(org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Collectors.partitioningBy(java.util.stream.Collectors.partitioningBy) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgnitePredicateX(org.apache.ignite.internal.util.lang.IgnitePredicateX) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) AtomicReference(java.util.concurrent.atomic.AtomicReference) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) LT(org.apache.ignite.internal.util.typedef.internal.LT) ArrayList(java.util.ArrayList) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter) S(org.apache.ignite.internal.util.typedef.internal.S) MOVING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.MOVING) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) PAGE_SNAPSHOT_TAKEN(org.apache.ignite.internal.processors.cache.persistence.CheckpointState.PAGE_SNAPSHOT_TAKEN) FINISHED(org.apache.ignite.internal.processors.cache.persistence.CheckpointState.FINISHED) F(org.apache.ignite.internal.util.typedef.F) GridIterableAdapter(org.apache.ignite.internal.util.lang.GridIterableAdapter) Iterator(java.util.Iterator) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) TTL_ETERNAL(org.apache.ignite.internal.processors.cache.GridCacheUtils.TTL_ETERNAL) GridMutableLong(org.apache.ignite.internal.util.GridMutableLong) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) GridToStringInclude(org.apache.ignite.internal.util.tostring.GridToStringInclude) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) WalStateManager(org.apache.ignite.internal.processors.cache.WalStateManager) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) GridCacheMvccEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo) Collections(java.util.Collections) TxState(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxState) PRELOAD_SIZE_UNDER_CHECKPOINT_LOCK(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl.PRELOAD_SIZE_UNDER_CHECKPOINT_LOCK) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) GridCacheMvccEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo) ArrayList(java.util.ArrayList) GridMutableLong(org.apache.ignite.internal.util.GridMutableLong)

Aggregations

GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)3 GridCacheMvccEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheMvccEntryInfo)3 ArrayList (java.util.ArrayList)2 CacheEntryInfoCollection (org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 NavigableSet (java.util.NavigableSet)1 Objects.nonNull (java.util.Objects.nonNull)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1