use of org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask in project ignite by apache.
the class LongDestroyDurableBackgroundTaskTest method testConvertOldTaskToNew.
/**
* Checking the converting of the old problem into the new one.
*/
@Test
public void testConvertOldTaskToNew() {
String grpName = "grpTest";
String cacheName = "cacheTest";
String treeName = "treeTest";
String idxName = "idxTest";
List<Long> pages = F.asList(100L);
DurableBackgroundCleanupIndexTreeTask oldTask = new DurableBackgroundCleanupIndexTreeTask(pages, emptyList(), grpName, cacheName, new IndexName(cacheName, "schemaTest", "tableTest", idxName), treeName);
DurableBackgroundTask convertedTask = oldTask.convertAfterRestoreIfNeeded();
assertTrue(convertedTask instanceof DurableBackgroundCleanupIndexTreeTaskV2);
assertEquals(grpName, getFieldValue(convertedTask, "grpName"));
assertEquals(cacheName, getFieldValue(convertedTask, "cacheName"));
assertEquals(treeName, getFieldValue(convertedTask, "oldTreeName"));
assertNotNull(getFieldValue(convertedTask, "newTreeName"));
assertEquals(idxName, getFieldValue(convertedTask, "idxName"));
assertEquals(pages.size(), (int) getFieldValue(convertedTask, "segments"));
}
use of org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask in project ignite by apache.
the class DurableBackgroundTasksProcessor method onReadyForRead.
/**
* {@inheritDoc}
*/
@Override
public void onReadyForRead(ReadOnlyMetastorage metastorage) {
if (!stopLock.enterBusy())
return;
try {
metaStorageOperation(metaStorage -> {
assert metaStorage != null;
metaStorage.iterate(TASK_PREFIX, (k, v) -> {
DurableBackgroundTask task = ((DurableBackgroundTask<?>) v);
DurableBackgroundTask convertedTask = task.convertAfterRestoreIfNeeded();
boolean converted = false;
if (task != convertedTask) {
assert !task.name().equals(convertedTask.name()) : "Duplicate task names [original=" + task.name() + ", converted=" + convertedTask.name() + ']';
GridFutureAdapter<?> outFut = new GridFutureAdapter<>();
outFut.onDone();
DurableBackgroundTaskState<?> state = new DurableBackgroundTaskState<>(task, outFut, true, false);
state.state(COMPLETED);
tasks.put(task.name(), state);
task = convertedTask;
converted = true;
}
tasks.put(task.name(), new DurableBackgroundTaskState<>(task, new GridFutureAdapter<>(), true, converted));
}, true);
});
} finally {
stopLock.leaveBusy();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask in project ignite by apache.
the class DurableBackgroundTasksProcessorSelfTest method testDontDeleteTaskIfItsRestart.
/**
* Check that the task will not be deleted from the MetaStorage if it was restarted.
*
* @throws Exception If failed.
*/
@Test
public void testDontDeleteTaskIfItsRestart() throws Exception {
IgniteEx n = startGrid(0);
ObservingCheckpointListener observingCpLsnr = new ObservingCheckpointListener();
dbMgr(n).addCheckpointListener(observingCpLsnr);
n.cluster().state(ACTIVE);
CheckpointWorkflow cpWorkflow = checkpointWorkflow(n);
List<CheckpointListener> cpLs = cpWorkflow.getRelevantCheckpointListeners(dbMgr(n).checkpointedDataRegions());
assertTrue(cpLs.contains(observingCpLsnr));
assertTrue(cpLs.contains(durableBackgroundTask(n)));
assertTrue(cpLs.indexOf(observingCpLsnr) < cpLs.indexOf(durableBackgroundTask(n)));
SimpleTask simpleTask0 = new SimpleTask("t");
IgniteInternalFuture<Void> taskFut = durableBackgroundTask(n).executeAsync(simpleTask0, true);
simpleTask0.onExecFut.get(getTestTimeout());
forceCheckpoint();
dbMgr(n).enableCheckpoints(false).get(getTestTimeout());
simpleTask0.taskFut.onDone(DurableBackgroundTaskResult.complete(null));
taskFut.get(getTestTimeout());
SimpleTask simpleTask1 = new SimpleTask("t");
AtomicReference<IgniteInternalFuture<Void>> taskFutRef = new AtomicReference<>();
observingCpLsnr.afterCheckpointEndConsumer = ctx -> taskFutRef.set(durableBackgroundTask(n).executeAsync(simpleTask1, true));
dbMgr(n).enableCheckpoints(true).get(getTestTimeout());
forceCheckpoint();
assertNotNull(metaStorageOperation(n, ms -> ms.read(metaStorageKey(simpleTask0))));
simpleTask1.onExecFut.get(getTestTimeout());
simpleTask1.taskFut.onDone(DurableBackgroundTaskResult.complete(null));
taskFutRef.get().get(getTestTimeout());
forceCheckpoint();
assertNull(metaStorageOperation(n, ms -> ms.read(metaStorageKey(simpleTask1))));
}
Aggregations