Search in sources :

Example 6 with PendingRow

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

the class IgniteCacheOffheapManagerImpl method expireInternal.

/**
 * @param cctx Cache context.
 * @param c Closure.
 * @param amount Limit of processed entries by single call, {@code -1} for no limit.
 * @return cleared entries count.
 * @throws IgniteCheckedException If failed.
 */
private int expireInternal(GridCacheContext cctx, IgniteInClosure2X<GridCacheEntryEx, GridCacheVersion> c, int amount) throws IgniteCheckedException {
    long now = U.currentTimeMillis();
    GridCacheVersion obsoleteVer = null;
    GridCursor<PendingRow> cur;
    cctx.shared().database().checkpointReadLock();
    try {
        if (grp.sharedGroup())
            cur = pendingEntries.find(new PendingRow(cctx.cacheId()), new PendingRow(cctx.cacheId(), now, 0));
        else
            cur = pendingEntries.find(null, new PendingRow(CU.UNDEFINED_CACHE_ID, now, 0));
        if (!cur.next())
            return 0;
        if (!busyLock.enterBusy())
            return 0;
        try {
            int cleared = 0;
            do {
                if (amount != -1 && cleared > amount)
                    return cleared;
                PendingRow row = cur.get();
                if (row.key.partition() == -1)
                    row.key.partition(cctx.affinity().partition(row.key));
                assert row.key != null && row.link != 0 && row.expireTime != 0 : row;
                if (pendingEntries.removex(row)) {
                    if (obsoleteVer == null)
                        obsoleteVer = cctx.cache().nextVersion();
                    GridCacheEntryEx entry = cctx.cache().entryEx(row.key);
                    if (entry != null)
                        c.apply(entry, obsoleteVer);
                }
                cleared++;
            } while (cur.next());
            return cleared;
        } finally {
            busyLock.leaveBusy();
        }
    } finally {
        cctx.shared().database().checkpointReadUnlock();
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) PendingRow(org.apache.ignite.internal.processors.cache.tree.PendingRow)

Aggregations

PendingRow (org.apache.ignite.internal.processors.cache.tree.PendingRow)6 PendingEntriesTree (org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree)2 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Duration (javax.cache.expiry.Duration)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)1 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)1 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)1 IgniteCacheOffheapManager (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 SimpleDataRow (org.apache.ignite.internal.processors.cache.persistence.freelist.SimpleDataRow)1 AbstractDataLeafIO (org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO)1 CacheDataTree (org.apache.ignite.internal.processors.cache.tree.CacheDataTree)1 DataRow (org.apache.ignite.internal.processors.cache.tree.DataRow)1