Search in sources :

Example 56 with CacheGroupContext

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));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) Answer(org.mockito.stubbing.Answer) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IgniteEx(org.apache.ignite.internal.IgniteEx) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 57 with CacheGroupContext

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();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DependencyResolver(org.apache.ignite.internal.processors.resource.DependencyResolver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 58 with CacheGroupContext

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;
}
Also used : IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 59 with CacheGroupContext

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor) HashSet(java.util.HashSet) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 60 with CacheGroupContext

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);
            }
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Aggregations

CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)103 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)31 IgniteEx (org.apache.ignite.internal.IgniteEx)29 Map (java.util.Map)27 HashMap (java.util.HashMap)24 IgniteException (org.apache.ignite.IgniteException)22 ArrayList (java.util.ArrayList)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 Test (org.junit.Test)20 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)19 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)16 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)16 HashSet (java.util.HashSet)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)12 Set (java.util.Set)11 Collection (java.util.Collection)10