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;
}
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;
}
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"));
}
Aggregations