Search in sources :

Example 1 with DurableBackgroundTask

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"));
}
Also used : IndexName(org.apache.ignite.internal.cache.query.index.IndexName) DurableBackgroundTask(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask) AtomicLong(java.util.concurrent.atomic.AtomicLong) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) DurableBackgroundCleanupIndexTreeTask(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTask) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with DurableBackgroundTask

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();
    }
}
Also used : DurableBackgroundTask(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Example 3 with DurableBackgroundTask

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))));
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) DurableBackgroundTaskResult.restart(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult.restart) GridTestUtils.assertThrows(org.apache.ignite.testframework.GridTestUtils.assertThrows) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReference(java.util.concurrent.atomic.AtomicReference) DurableBackgroundTasksProcessor.metaStorageKey(org.apache.ignite.internal.processors.localtask.DurableBackgroundTasksProcessor.metaStorageKey) CheckpointWorkflow(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointWorkflow) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) DurableBackgroundTaskResult.complete(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult.complete) Map(java.util.Map) DurableBackgroundTask(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) COMPLETED(org.apache.ignite.internal.processors.localtask.DurableBackgroundTaskState.State.COMPLETED) STARTED(org.apache.ignite.internal.processors.localtask.DurableBackgroundTaskState.State.STARTED) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) INIT(org.apache.ignite.internal.processors.localtask.DurableBackgroundTaskState.State.INIT) State(org.apache.ignite.internal.processors.localtask.DurableBackgroundTaskState.State) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) DurableBackgroundTaskResult(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridTestUtils.getFieldValue(org.apache.ignite.testframework.GridTestUtils.getFieldValue) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CheckpointWorkflow(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointWorkflow) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

DurableBackgroundTask (org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 List (java.util.List)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 ACTIVE (org.apache.ignite.cluster.ClusterState.ACTIVE)1 INACTIVE (org.apache.ignite.cluster.ClusterState.INACTIVE)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 StopNodeFailureHandler (org.apache.ignite.failure.StopNodeFailureHandler)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 IndexName (org.apache.ignite.internal.cache.query.index.IndexName)1 DurableBackgroundCleanupIndexTreeTask (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTask)1