Search in sources :

Example 1 with GridCacheObsoleteEntryExtras

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

the class GridDhtLocalPartition method clearAll.

/**
 * Removes all entries and rows from this partition.
 *
 * @return Number of rows cleared from page memory.
 * @throws NodeStoppingException If node stopping.
 */
protected long clearAll(EvictionContext evictionCtx) throws NodeStoppingException {
    long order = clearVer;
    GridCacheVersion clearVer = ctx.versions().startVersion();
    GridCacheObsoleteEntryExtras extras = new GridCacheObsoleteEntryExtras(clearVer);
    boolean rec = grp.eventRecordable(EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
    long cleared = 0;
    int stopCntr = 0;
    CacheMapHolder hld = grp.sharedGroup() ? null : singleCacheEntryMap;
    boolean recoveryMode = ctx.kernalContext().recoveryMode();
    try {
        // because atomic and transactional caches use different partition counters implementation.
        if (state() == MOVING && !recoveryMode && grp.walEnabled() && grp.config().getAtomicityMode() == ATOMIC)
            ctx.wal().log(new PartitionClearingStartRecord(id, grp.groupId(), order));
        GridIterator<CacheDataRow> it0 = grp.offheap().partitionIterator(id);
        while (it0.hasNext()) {
            if ((stopCntr = (stopCntr + 1) & 1023) == 0 && evictionCtx.shouldStop())
                return cleared;
            ctx.database().checkpointReadLock();
            try {
                CacheDataRow row = it0.next();
                // Do not clear fresh rows in case of partition reloading.
                // This is required because normal updates are possible to moving partition which is currently cleared.
                // We can clean OWNING partition if a partition has been reset from lost state.
                // In this case new updates must be preserved.
                // Partition state can be switched from RENTING to MOVING and vice versa during clearing.
                long order0 = row.version().order();
                if ((state() == MOVING || recoveryMode) && (order0 == 0 || /**
                 * Inserted by isolated updater.
                 */
                order0 > order))
                    continue;
                if (grp.sharedGroup() && (hld == null || hld.cctx.cacheId() != row.cacheId()))
                    hld = cacheMapHolder(ctx.cacheContext(row.cacheId()));
                assert hld != null;
                GridCacheMapEntry cached = putEntryIfObsoleteOrAbsent(hld, hld.cctx, grp.affinity().lastVersion(), row.key(), true, true);
                assert cached != null : "Expecting the reservation " + this;
                if (cached.deleted())
                    continue;
                if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry) cached).clearInternal(clearVer, extras)) {
                    removeEntry(cached);
                    if (rec && !hld.cctx.config().isEventsDisabled()) {
                        hld.cctx.events().addEvent(cached.partition(), cached.key(), ctx.localNodeId(), null, null, null, EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), null, null, false);
                    }
                    cleared++;
                }
            } catch (GridDhtInvalidPartitionException e) {
                assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
                // Partition is already concurrently cleared and evicted.
                break;
            } finally {
                ctx.database().checkpointReadUnlock();
            }
        }
        if (forceTestCheckpointOnEviction) {
            if (partWhereTestCheckpointEnforced == null && cleared >= fullSize()) {
                ctx.database().forceCheckpoint("test").futureFor(FINISHED).get();
                log.warning("Forced checkpoint by test reasons for partition: " + this);
                partWhereTestCheckpointEnforced = id;
            }
        }
        // Attempt to destroy.
        if (!recoveryMode)
            ((GridDhtPreloader) grp.preloader()).tryFinishEviction(this);
    } catch (NodeStoppingException e) {
        if (log.isDebugEnabled())
            log.debug("Failed to get iterator for evicted partition: " + id);
        throw e;
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to get iterator for evicted partition: " + id, e);
    }
    return cleared;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) PartitionClearingStartRecord(org.apache.ignite.internal.pagemem.wal.record.PartitionClearingStartRecord) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheObsoleteEntryExtras(org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry)

Example 2 with GridCacheObsoleteEntryExtras

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

the class GridDhtLocalPartition method clearAll.

/**
 * Removes all entries and rows from this partition.
 *
 * @return Number of rows cleared from page memory.
 * @throws NodeStoppingException If node stopping.
 */
private long clearAll() throws NodeStoppingException {
    GridCacheVersion clearVer = ctx.versions().next();
    GridCacheObsoleteEntryExtras extras = new GridCacheObsoleteEntryExtras(clearVer);
    boolean rec = grp.eventRecordable(EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
    if (grp.sharedGroup()) {
        for (CacheMapHolder hld : cacheMaps.values()) clear(hld.map, extras, rec);
    } else
        clear(singleCacheEntryMap.map, extras, rec);
    long cleared = 0;
    if (!grp.allowFastEviction()) {
        CacheMapHolder hld = grp.sharedGroup() ? null : singleCacheEntryMap;
        try {
            GridIterator<CacheDataRow> it0 = grp.offheap().partitionIterator(id);
            while (it0.hasNext()) {
                ctx.database().checkpointReadLock();
                try {
                    CacheDataRow row = it0.next();
                    // Do not clear fresh rows in case of single partition clearing.
                    if (row.version().compareTo(clearVer) >= 0 && (state() == MOVING && clear))
                        continue;
                    if (grp.sharedGroup() && (hld == null || hld.cctx.cacheId() != row.cacheId()))
                        hld = cacheMapHolder(ctx.cacheContext(row.cacheId()));
                    assert hld != null;
                    GridCacheMapEntry cached = putEntryIfObsoleteOrAbsent(hld, hld.cctx, grp.affinity().lastVersion(), row.key(), true, false);
                    if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry) cached).clearInternal(clearVer, extras)) {
                        removeEntry(cached);
                        if (rec && !hld.cctx.config().isEventsDisabled()) {
                            hld.cctx.events().addEvent(cached.partition(), cached.key(), ctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), null, null, null, false);
                        }
                        cleared++;
                    }
                } catch (GridDhtInvalidPartitionException e) {
                    assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
                    // Partition is already concurrently cleared and evicted.
                    break;
                } finally {
                    ctx.database().checkpointReadUnlock();
                }
            }
        } catch (NodeStoppingException e) {
            if (log.isDebugEnabled())
                log.debug("Failed to get iterator for evicted partition: " + id);
            throw e;
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to get iterator for evicted partition: " + id, e);
        }
    }
    return cleared;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheObsoleteEntryExtras(org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)2 GridCacheMapEntry (org.apache.ignite.internal.processors.cache.GridCacheMapEntry)2 GridCacheObsoleteEntryExtras (org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras)2 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)2 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)2 PartitionClearingStartRecord (org.apache.ignite.internal.pagemem.wal.record.PartitionClearingStartRecord)1 GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)1