use of org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method onCacheStarted.
/**
* {@inheritDoc}
*/
public void onCacheStarted(GridCacheContext cctx) throws IgniteCheckedException {
if (cctx.affinityNode() && cctx.ttl().eagerTtlEnabled() && pendingEntries == null) {
String name = "PendingEntries";
long rootPage = allocateForTree();
pendingEntries = new PendingEntriesTree(grp, name, grp.dataRegion().pageMemory(), rootPage, grp.reuseList(), true);
}
}
use of org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree in project ignite by apache.
the class GridCacheOffheapManager method onCacheStarted.
/**
* {@inheritDoc}
*/
@Override
public void onCacheStarted(GridCacheContext cctx) throws IgniteCheckedException {
if (cctx.affinityNode() && cctx.ttl().eagerTtlEnabled() && pendingEntries == null) {
ctx.database().checkpointReadLock();
try {
final String name = "PendingEntries";
RootPage pendingRootPage = indexStorage.getOrAllocateForTree(name);
pendingEntries = new PendingEntriesTree(grp, name, grp.dataRegion().pageMemory(), pendingRootPage.pageId().pageId(), reuseList, pendingRootPage.isAllocated());
} finally {
ctx.database().checkpointReadUnlock();
}
}
}
use of org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree in project ignite by apache.
the class CachePartitionDefragmentationManager method copyPartitionData.
/**
* Defragmentate partition.
*
* @param partCtx
* @param treeIter
* @throws IgniteCheckedException If failed.
*/
private void copyPartitionData(PartitionContext partCtx, TreeIterator treeIter) throws IgniteCheckedException {
CacheDataTree tree = partCtx.oldCacheDataStore.tree();
CacheDataTree newTree = partCtx.newCacheDataStore.tree();
newTree.enableSequentialWriteMode();
PendingEntriesTree newPendingTree = partCtx.newCacheDataStore.pendingTree();
AbstractFreeList<CacheDataRow> freeList = partCtx.newCacheDataStore.getCacheStoreFreeList();
long cpLockThreshold = 150L;
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
try {
AtomicLong lastCpLockTs = new AtomicLong(System.currentTimeMillis());
AtomicInteger entriesProcessed = new AtomicInteger();
treeIter.iterate(tree, partCtx.cachePageMemory, (tree0, io, pageAddr, idx) -> {
checkCancellation();
if (System.currentTimeMillis() - lastCpLockTs.get() >= cpLockThreshold) {
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
lastCpLockTs.set(System.currentTimeMillis());
}
AbstractDataLeafIO leafIo = (AbstractDataLeafIO) io;
CacheDataRow row = tree.getRow(io, pageAddr, idx);
int cacheId = row.cacheId();
// Reuse row that we just read.
row.link(0);
// "insertDataRow" will corrupt page memory if we don't do this.
if (row instanceof DataRow && !partCtx.oldGrpCtx.storeCacheIdInDataPage())
((DataRow) row).cacheId(CU.UNDEFINED_CACHE_ID);
freeList.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
// Put it back.
if (row instanceof DataRow)
((DataRow) row).cacheId(cacheId);
newTree.putx(row);
long newLink = row.link();
partCtx.linkMap.put(leafIo.getLink(pageAddr, idx), newLink);
if (row.expireTime() != 0)
newPendingTree.putx(new PendingRow(cacheId, row.expireTime(), newLink));
entriesProcessed.incrementAndGet();
return true;
});
checkCancellation();
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
freeList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE);
copyCacheMetadata(partCtx);
} finally {
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method initPendingTree.
/**
* @param cctx Cache context.
* @throws IgniteCheckedException If failed.
*/
protected void initPendingTree(GridCacheContext<?, ?> cctx) throws IgniteCheckedException {
assert !cctx.group().persistenceEnabled();
if (cctx.affinityNode() && cctx.ttl().eagerTtlEnabled() && pendingEntries == null) {
String pendingEntriesTreeName = cctx.name() + "##PendingEntries";
long rootPage = allocateForTree();
pendingEntries = new PendingEntriesTree(grp, pendingEntriesTreeName, grp.dataRegion().pageMemory(), rootPage, grp.reuseList(), true, ctx.diagnostic().pageLockTracker(), FLAG_IDX);
}
}
use of org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree in project ignite by apache.
the class PendingTreeCorruptionTest method testCorruptionWhileLoadingData.
/**
*/
@Test
public void testCorruptionWhileLoadingData() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
String expireCacheName = "cacheWithExpire";
String regularCacheName = "cacheWithoutExpire";
String grpName = "cacheGroup";
IgniteCache<Object, Object> expireCache = ig.getOrCreateCache(new CacheConfiguration<>(expireCacheName).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(MINUTES, 10))).setGroupName(grpName));
IgniteCache<Object, Object> regularCache = ig.getOrCreateCache(new CacheConfiguration<>(regularCacheName).setGroupName(grpName));
// This will initialize partition and cache structures.
expireCache.put(0, 0);
expireCache.remove(0);
int expireCacheId = CU.cacheGroupId(expireCacheName, grpName);
CacheGroupContext grp = ig.context().cache().cacheGroup(CU.cacheId(grpName));
IgniteCacheOffheapManager.CacheDataStore store = grp.topology().localPartition(0).dataStore();
assertNotNull(store);
// Get pending tree of expire cache.
PendingEntriesTree pendingTree = store.pendingTree();
long year = TimeUnit.DAYS.toMillis(365);
long expiration = System.currentTimeMillis() + year;
ig.context().cache().context().database().checkpointReadLock();
try {
// Carefully calculated number. Just enough for the first split to happen, but not more.
for (int i = 0; i < 202; i++) // link != 0
pendingTree.putx(new PendingRow(expireCacheId, expiration, expiration + i));
// Open cursor, it'll cache first leaf of the tree.
GridCursor<PendingRow> cur = pendingTree.find(null, new PendingRow(expireCacheId, expiration + year, 0), PendingEntriesTree.WITHOUT_KEY);
// Required for "do" loop to work.
assertTrue(cur.next());
int cnt = 0;
// Emulate real expiry loop but with a more precise control.
do {
PendingRow row = cur.get();
pendingTree.removex(row);
// with its sibling, meaning that cached "nextPageId" points to empty page from reuse list.
if (row.link - row.expireTime == 100) {
// Put into another cache will take a page from reuse list first. This means that cached
// "nextPageId" points to a data page.
regularCache.put(0, 0);
}
cnt++;
} while (cur.next());
assertEquals(202, cnt);
} finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
}
Aggregations