Search in sources :

Example 1 with DurableBackgroundTaskResult

use of org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult in project ignite by apache.

the class DurableBackgroundCleanupIndexTreeTaskV2 method executeAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<DurableBackgroundTaskResult<Long>> executeAsync(GridKernalContext ctx) {
    assert worker == null;
    log = ctx.log(DurableBackgroundCleanupIndexTreeTaskV2.class);
    IgniteInternalFuture<DurableBackgroundTaskResult<Long>> outFut;
    CacheGroupContext grpCtx = ctx.cache().cacheGroup(CU.cacheGroupId(cacheName, grpName));
    if (grpCtx != null) {
        try {
            // To avoid problems due to node crash between renaming and adding a task.
            if (needToRen) {
                // If the node falls before renaming, then the index was definitely not dropped.
                // If the node crashes after renaming, the task will delete the old index trees,
                // and the node will rebuild this index when the node starts.
                renameIndexRootPages(grpCtx, cacheName, oldTreeName, newTreeName, segments);
                // After restoring from MetaStorage, it will also be {@code false}.
                needToRen = false;
            }
            if (rootPages.isEmpty())
                rootPages.putAll(findIndexRootPages(grpCtx, cacheName, newTreeName, segments));
            if (!rootPages.isEmpty()) {
                GridFutureAdapter<DurableBackgroundTaskResult<Long>> fut = new GridFutureAdapter<>();
                GridWorker w = new GridWorker(ctx.igniteInstanceName(), "async-worker-" + name(), log) {

                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    protected void body() {
                        try {
                            Iterator<Map.Entry<Integer, RootPage>> it = rootPages.entrySet().iterator();
                            while (it.hasNext()) {
                                Map.Entry<Integer, RootPage> e = it.next();
                                RootPage rootPage = e.getValue();
                                int segment = e.getKey();
                                long pages = destroyIndexTrees(grpCtx, rootPage, cacheName, newTreeName, segment);
                                if (pages > 0)
                                    pageCnt.addAndGet(pages);
                                it.remove();
                            }
                            fut.onDone(DurableBackgroundTaskResult.complete(pageCnt.get()));
                        } catch (Throwable t) {
                            fut.onDone(DurableBackgroundTaskResult.restart(t));
                        } finally {
                            worker = null;
                        }
                    }
                };
                new IgniteThread(w).start();
                this.worker = w;
                outFut = fut;
            } else
                outFut = new GridFinishedFuture<>(DurableBackgroundTaskResult.complete());
        } catch (Throwable t) {
            outFut = new GridFinishedFuture<>(DurableBackgroundTaskResult.restart(t));
        }
    } else
        outFut = new GridFinishedFuture<>(DurableBackgroundTaskResult.complete());
    return outFut;
}
Also used : DurableBackgroundTaskResult(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteThread(org.apache.ignite.thread.IgniteThread) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with DurableBackgroundTaskResult

use of org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult in project ignite by apache.

the class DurableBackgroundCleanupIndexTreeTask method executeAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<DurableBackgroundTaskResult> executeAsync(GridKernalContext ctx) {
    log = ctx.log(this.getClass());
    assert worker == null;
    GridFutureAdapter<DurableBackgroundTaskResult> fut = new GridFutureAdapter<>();
    worker = new GridWorker(ctx.igniteInstanceName(), "async-durable-background-task-executor-" + name(), log) {

        /**
         * {@inheritDoc}
         */
        @Override
        protected void body() {
            try {
                execute(ctx);
                worker = null;
                fut.onDone(DurableBackgroundTaskResult.complete(null));
            } catch (Throwable t) {
                worker = null;
                fut.onDone(DurableBackgroundTaskResult.restart(t));
            }
        }
    };
    new IgniteThread(worker).start();
    return fut;
}
Also used : GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) DurableBackgroundTaskResult(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult) IgniteThread(org.apache.ignite.thread.IgniteThread) GridWorker(org.apache.ignite.internal.util.worker.GridWorker)

Example 3 with DurableBackgroundTaskResult

use of org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult in project ignite by apache.

the class DropIndexTest method testCorrectTaskExecute.

/**
 * Checking that the {@link DurableBackgroundCleanupIndexTreeTaskV2} will work correctly.
 *
 * @throws Exception If failed.
 */
@Test
public void testCorrectTaskExecute() throws Exception {
    IgniteEx n = startGrid(0);
    IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
    populate(cache, 100);
    String idxName = "IDX0";
    createIdx(cache, idxName);
    GridCacheContext<Integer, Person> cctx = cacheContext(cache);
    Index idx = index(n, cache, idxName);
    SortedIndexDefinition idxDef = indexDefinition(idx);
    InlineIndexTree[] trees = segments(idx);
    Map<Integer, RootPage> rootPages = toRootPages(trees);
    for (int i = 0; i < trees.length; i++) {
        InlineIndexTree tree = trees[i];
        assertEquals(new FullPageId(tree.getMetaPageId(), tree.groupId()), rootPages.get(i).pageId());
    }
    String oldTreeName = idxDef.treeName();
    String newTreeName = UUID.randomUUID().toString();
    int segments = idxDef.segments();
    assertFalse(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    DurableBackgroundCleanupIndexTreeTaskV2 task = new DurableBackgroundCleanupIndexTreeTaskV2(cctx.group().name(), cctx.name(), idxName, oldTreeName, newTreeName, segments, trees);
    assertTrue(task.name().startsWith(taskNamePrefix(cctx.name(), idxName)));
    assertTrue(getFieldValue(task, "needToRen"));
    GridFutureAdapter<Void> startFut = new GridFutureAdapter<>();
    GridFutureAdapter<Void> endFut = new GridFutureAdapter<>();
    idxTreeFactory = taskIndexTreeFactoryEx(startFut, endFut);
    IgniteInternalFuture<DurableBackgroundTaskResult<Long>> taskFut = task.executeAsync(n.context());
    startFut.get(getTestTimeout());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertFalse(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    endFut.onDone();
    DurableBackgroundTaskResult<Long> res = taskFut.get(getTestTimeout());
    assertTrue(res.completed());
    assertNull(res.error());
    assertTrue(res.result() >= 3);
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    assertFalse(getFieldValue(task, "needToRen"));
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) InlineIndexTree(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree) Index(org.apache.ignite.internal.cache.query.index.Index) DurableBackgroundTaskResult(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) IgniteEx(org.apache.ignite.internal.IgniteEx) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Person(org.apache.ignite.client.Person) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) Test(org.junit.Test)

Aggregations

DurableBackgroundTaskResult (org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)3 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)2 GridWorker (org.apache.ignite.internal.util.worker.GridWorker)2 IgniteThread (org.apache.ignite.thread.IgniteThread)2 Collections.emptyMap (java.util.Collections.emptyMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Person (org.apache.ignite.client.Person)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 Index (org.apache.ignite.internal.cache.query.index.Index)1 DurableBackgroundCleanupIndexTreeTaskV2 (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2)1 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)1 InlineIndexTree (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree)1 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)1 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)1 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)1 Test (org.junit.Test)1