use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class BlockedEvictionsTest method testStopNodeDuringEviction_2.
/**
* @throws Exception If failed.
*/
@Test
public void testStopNodeDuringEviction_2() throws Exception {
AtomicInteger holder = new AtomicInteger();
CountDownLatch l1 = new CountDownLatch(1);
CountDownLatch l2 = new CountDownLatch(1);
IgniteEx g0 = startGrid(0, new DependencyResolver() {
@Override
public <T> T resolve(T instance) {
if (instance instanceof GridDhtPartitionTopologyImpl) {
GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) instance;
top.partitionFactory(new GridDhtPartitionTopologyImpl.PartitionFactory() {
@Override
public GridDhtLocalPartition create(GridCacheSharedContext ctx, CacheGroupContext grp, int id, boolean recovery) {
return new GridDhtLocalPartitionSyncEviction(ctx, grp, id, recovery, 3, l1, l2) {
/**
*/
@Override
protected void sync() {
if (holder.get() == id)
super.sync();
}
};
}
});
} else if (instance instanceof IgniteCacheOffheapManager) {
IgniteCacheOffheapManager mgr = (IgniteCacheOffheapManager) instance;
IgniteCacheOffheapManager spied = Mockito.spy(mgr);
Mockito.doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object ret = invocation.callRealMethod();
// Wait is necessary here to guarantee test progress.
doSleep(2_000);
return ret;
}
}).when(spied).stop();
return (T) spied;
}
return instance;
}
});
startGrid(1);
awaitPartitionMapExchange();
IgniteCache<Object, Object> cache = g0.getOrCreateCache(cacheConfiguration());
int p0 = evictingPartitionsAfterJoin(g0, cache, 1).get(0);
holder.set(p0);
loadDataToPartition(p0, g0.name(), DEFAULT_CACHE_NAME, 5_000, 0, 3);
startGrid(2);
U.awaitQuiet(l1);
GridDhtLocalPartition part = g0.cachex(DEFAULT_CACHE_NAME).context().topology().localPartition(p0);
AtomicReference<GridFutureAdapter<?>> ref = U.field(part, "finishFutRef");
GridFutureAdapter<?> finishFut = ref.get();
IgniteInternalFuture fut = runAsync(g0::close);
// Give some time to execute cache store destroy.
doSleep(500);
l2.countDown();
fut.get();
// Partition clearing future should be finished with NodeStoppingException.
assertTrue(finishFut.error().getMessage(), finishFut.error() != null && X.hasCause(finishFut.error(), NodeStoppingException.class));
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class BlockedEvictionsTest method testOperationDuringEviction.
/**
* @param persistence {@code True} to use persistence.
* @param mode Mode: <ul><li>0 - block before clearing start</li>
* <li>1 - block in the middle of clearing</li></ul>
* @param r A runnable to run while eviction is blocked.
* @throws Exception If failed.
*/
protected void testOperationDuringEviction(boolean persistence, int mode, Runnable r) throws Exception {
this.persistence = persistence;
AtomicInteger holder = new AtomicInteger();
CountDownLatch l1 = new CountDownLatch(1);
CountDownLatch l2 = new CountDownLatch(1);
IgniteEx g0 = startGrid(0, new DependencyResolver() {
@Override
public <T> T resolve(T instance) {
if (instance instanceof GridDhtPartitionTopologyImpl) {
GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) instance;
top.partitionFactory(new GridDhtPartitionTopologyImpl.PartitionFactory() {
@Override
public GridDhtLocalPartition create(GridCacheSharedContext ctx, CacheGroupContext grp, int id, boolean recovery) {
return new GridDhtLocalPartitionSyncEviction(ctx, grp, id, recovery, mode, l1, l2) {
/**
*/
@Override
protected void sync() {
if (holder.get() == id)
super.sync();
}
};
}
});
}
return instance;
}
});
startGrid(1);
if (persistence)
g0.cluster().state(ClusterState.ACTIVE);
awaitPartitionMapExchange(true, true, null);
IgniteCache<Object, Object> cache = g0.getOrCreateCache(cacheConfiguration());
List<Integer> allEvicting = evictingPartitionsAfterJoin(g0, cache, 1024);
int p0 = allEvicting.get(0);
holder.set(p0);
final int cnt = 5_000;
List<Integer> keys = partitionKeys(g0.cache(DEFAULT_CACHE_NAME), p0, cnt, 0);
try (IgniteDataStreamer<Object, Object> ds = g0.dataStreamer(DEFAULT_CACHE_NAME)) {
for (Integer key : keys) ds.addData(key, key);
}
IgniteEx joining = startGrid(2);
if (persistence)
resetBaselineTopology();
assertTrue(U.await(l1, 30_000, TimeUnit.MILLISECONDS));
r.run();
l2.countDown();
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class PageMemoryTracker method pageStoreAllocatedPages.
/**
* Total count of allocated pages in page store.
*/
private long pageStoreAllocatedPages() {
IgnitePageStoreManager pageStoreMgr = gridCtx.cache().context().pageStore();
assert pageStoreMgr != null;
long totalAllocated = pageStoreMgr.pagesAllocated(MetaStorage.METASTORAGE_CACHE_ID);
if (MvccUtils.mvccEnabled(gridCtx))
totalAllocated += pageStoreMgr.pagesAllocated(TxLog.TX_LOG_CACHE_ID);
for (CacheGroupContext ctx : gridCtx.cache().cacheGroups()) totalAllocated += pageStoreMgr.pagesAllocated(ctx.groupId());
return totalAllocated;
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class PageMemoryTracker method checkPages.
/**
* Checks if there are any differences between the Ignite's data regions content and pages inside the tracker.
*
* @param checkAll Check all tracked pages, otherwise check until first error.
* @param checkPageCnt Check tracked and allocated pages count. This check can be done only if there is no
* concurrent modification of pages in the system (for example when checkpointWriteLock is held). Some threads
* (for example MVCC vacuum cleaner) can modify pages even if there is no activity from a users point of view.
* @return {@code true} if content of all tracked pages equals to content of these pages in the ignite instance.
*/
private boolean checkPages(boolean checkAll, boolean checkPageCnt) throws IgniteCheckedException {
if (!started)
throw new IgniteCheckedException("Page memory checking only possible when tracker is started.");
GridCacheProcessor cacheProc = gridCtx.cache();
boolean res = true;
synchronized (pageAllocatorMux) {
long totalAllocated = pageStoreAllocatedPages();
log.info(">>> Total tracked pages: " + pages.size());
log.info(">>> Total allocated pages: " + totalAllocated);
dumpStats();
if (emptyPds && checkPageCnt && pages.size() != totalAllocated) {
res = false;
log.error("Started from empty PDS, but tracked pages count not equals to allocated pages count");
dumpPagesCountDiff();
if (!checkAll)
return false;
}
}
Set<Integer> groupsWarned = new HashSet<>();
for (DirectMemoryPage page : pages.values()) {
FullPageId fullPageId = page.fullPageId();
PageMemory pageMem;
if (fullPageId.groupId() == MetaStorage.METASTORAGE_CACHE_ID)
pageMem = cacheProc.context().database().metaStorage().pageMemory();
else if (fullPageId.groupId() == TxLog.TX_LOG_CACHE_ID)
pageMem = cacheProc.context().database().dataRegion(TxLog.TX_LOG_CACHE_NAME).pageMemory();
else {
CacheGroupContext ctx = cacheProc.cacheGroup(fullPageId.groupId());
if (ctx != null)
pageMem = ctx.dataRegion().pageMemory();
else {
if (!groupsWarned.contains(fullPageId.groupId())) {
log.warning("Cache group " + fullPageId.groupId() + " not found.");
groupsWarned.add(fullPageId.groupId());
}
continue;
}
}
assert pageMem instanceof PageMemoryImpl;
long rmtPage = pageMem.acquirePage(fullPageId.groupId(), fullPageId.pageId());
try {
long rmtPageAddr = pageMem.readLockForce(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
try {
page.lock();
try {
if (rmtPageAddr == 0L) {
res = false;
log.error("Can't lock page: " + fullPageId);
dumpHistory(page);
} else if (!comparePages(fullPageId, page, rmtPageAddr))
res = false;
if (!res && !checkAll)
return false;
} finally {
page.unlock();
}
} finally {
if (rmtPageAddr != 0L)
pageMem.readUnlock(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
}
} finally {
pageMem.releasePage(fullPageId.groupId(), fullPageId.pageId(), rmtPage);
}
}
return res;
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class CachePageWriteLockUnlockTest method preloadPartition.
/**
* Preload partition fast by iterating on all pages in disk order.
*
* @param grid Grid.
* @param cacheName Cache name.
* @param p P.
*/
private void preloadPartition(Ignite grid, String cacheName, int p) throws IgniteCheckedException {
GridDhtCacheAdapter<Object, Object> dht = ((IgniteKernal) grid).internalCache(cacheName).context().dht();
GridDhtLocalPartition part = dht.topology().localPartition(p);
assertNotNull(part);
assertTrue(part.state() == OWNING);
CacheGroupContext grpCtx = dht.context().group();
if (part.state() != OWNING)
return;
IgnitePageStoreManager pageStoreMgr = grpCtx.shared().pageStore();
if (pageStoreMgr instanceof FilePageStoreManager) {
FilePageStoreManager filePageStoreMgr = (FilePageStoreManager) pageStoreMgr;
PageStore pageStore = filePageStoreMgr.getStore(grpCtx.groupId(), part.id());
PageMemoryEx pageMemory = (PageMemoryEx) grpCtx.dataRegion().pageMemory();
long pageId = pageMemory.partitionMetaPageId(grpCtx.groupId(), part.id());
for (int pageNo = 0; pageNo < pageStore.pages(); pageId++, pageNo++) {
long pagePointer = -1;
try {
pagePointer = pageMemory.acquirePage(grpCtx.groupId(), pageId);
} finally {
if (pagePointer != -1)
pageMemory.releasePage(grpCtx.groupId(), pageId, pagePointer);
}
}
}
}
Aggregations