Search in sources :

Example 1 with MaintenanceRegistry

use of org.apache.ignite.maintenance.MaintenanceRegistry in project ignite by apache.

the class IgniteDefragmentationImpl method getStatus.

/**
 * Get defragmentation status.
 * @return Defragmentation status or {@code null} if there is no ongoing defragmentation.
 */
private Status getStatus() {
    final MaintenanceRegistry maintenanceRegistry = ctx.maintenanceRegistry();
    if (!maintenanceRegistry.isMaintenanceMode())
        return null;
    IgniteCacheDatabaseSharedManager dbMgr = ctx.cache().context().database();
    assert dbMgr instanceof GridCacheDatabaseSharedManager;
    CachePartitionDefragmentationManager defrgMgr = ((GridCacheDatabaseSharedManager) dbMgr).defragmentationManager();
    if (defrgMgr == null)
        return null;
    return defrgMgr.status();
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 2 with MaintenanceRegistry

use of org.apache.ignite.maintenance.MaintenanceRegistry in project ignite by apache.

the class IgniteDefragmentationImpl method cancel.

/**
 * {@inheritDoc}
 */
@Override
public CancelResult cancel() throws IgniteCheckedException {
    final MaintenanceRegistry maintenanceRegistry = ctx.maintenanceRegistry();
    if (!maintenanceRegistry.isMaintenanceMode()) {
        boolean deleted = maintenanceRegistry.unregisterMaintenanceTask(DEFRAGMENTATION_MNTC_TASK_NAME);
        return deleted ? CancelResult.CANCELLED_SCHEDULED : CancelResult.SCHEDULED_NOT_FOUND;
    } else {
        List<MaintenanceAction<?>> actions;
        try {
            actions = maintenanceRegistry.actionsForMaintenanceTask(DEFRAGMENTATION_MNTC_TASK_NAME);
        } catch (IgniteException e) {
            return CancelResult.COMPLETED_OR_CANCELLED;
        }
        Optional<MaintenanceAction<?>> stopAct = actions.stream().filter(a -> "stop".equals(a.name())).findAny();
        assert stopAct.isPresent();
        try {
            Object res = stopAct.get().execute();
            assert res instanceof Boolean;
            boolean cancelled = (Boolean) res;
            return cancelled ? CancelResult.CANCELLED : CancelResult.COMPLETED_OR_CANCELLED;
        } catch (Exception e) {
            throw new IgniteCheckedException("Exception occurred: " + e.getMessage(), e);
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) HashMap(java.util.HashMap) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) GridKernalContext(org.apache.ignite.internal.GridKernalContext) DefragmentationParameters.toStore(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters.toStore) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) List(java.util.List) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) Status(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.Status) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) DEFRAGMENTATION_MNTC_TASK_NAME(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.DEFRAGMENTATION_MNTC_TASK_NAME) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 3 with MaintenanceRegistry

use of org.apache.ignite.maintenance.MaintenanceRegistry in project ignite by apache.

the class IgnitePdsDefragmentationTest method createMaintenanceRecord.

/**
 */
protected void createMaintenanceRecord(String... cacheNames) throws IgniteCheckedException {
    IgniteEx grid = grid(0);
    MaintenanceRegistry mntcReg = grid.context().maintenanceRegistry();
    final List<String> caches = new ArrayList<>();
    caches.add(DEFAULT_CACHE_NAME);
    if (cacheNames != null && cacheNames.length != 0)
        caches.addAll(Arrays.asList(cacheNames));
    mntcReg.registerMaintenanceTask(toStore(caches));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry)

Example 4 with MaintenanceRegistry

use of org.apache.ignite.maintenance.MaintenanceRegistry in project ignite by apache.

the class LocalWalModeChangeDuringRebalancingSelfTest method testPdsWithBrokenBinaryConsistencyIsClearedAfterRestartWithDisabledWal.

/**
 * Test is opposite to {@link #testConsistentPdsIsNotClearedAfterRestartWithDisabledWal()}
 *
 * <p>
 * Test scenario:
 * <ol>
 *      <li>
 *          Two server nodes are started, cluster is activated, baseline is set. 2500 keys are put into cache.
 *      </li>
 *      <li>
 *          Checkpoint is started and finished on both nodes.
 *      </li>
 *      <li>
 *          Node n1 is stopped, another 2500 keys are put into the same cache.
 *      </li>
 *      <li>
 *          Node n1 is started back so rebalancing is triggered from n0 to n1. WAL is turned off on n1 automatically.
 *      </li>
 *      <li>
 *          Both nodes are stopped without checkpoint.
 *      </li>
 *      <li>
 *          CP END marker for the first checkpoint is removed on node n1 so node will think it crushed during checkpoint
 *          on the next restart.
 *      </li>
 *      <li>
 *          Node n1 fails to start as it sees potentially corrupted files of one cache. Manual action is required.
 *      </li>
 *      <li>
 *          Cache files are cleaned up manually on node n1 and it starts successfully.
 *      </li>
 * </ol>
 * </p>
 *
 * @throws Exception If failed.
 */
@Test
public void testPdsWithBrokenBinaryConsistencyIsClearedAfterRestartWithDisabledWal() throws Exception {
    dfltCacheBackupCnt = 1;
    IgniteEx ig0 = startGrid(0);
    IgniteEx ig1 = startGrid(1);
    String ig1Folder = ig1.context().pdsFolderResolver().resolveFolders().folderName();
    File dbDir = U.resolveWorkDirectory(ig1.configuration().getWorkDirectory(), "db", false);
    File ig1LfsDir = new File(dbDir, ig1Folder);
    File ig1CpDir = new File(ig1LfsDir, "cp");
    ig0.cluster().baselineAutoAdjustEnabled(false);
    ig0.cluster().state(ACTIVE);
    IgniteCache<Integer, Integer> cache = ig0.cache(DEFAULT_CACHE_NAME);
    for (int k = 0; k < 2500; k++) cache.put(k, k);
    GridCacheDatabaseSharedManager dbMrg0 = (GridCacheDatabaseSharedManager) ig0.context().cache().context().database();
    GridCacheDatabaseSharedManager dbMrg1 = (GridCacheDatabaseSharedManager) ig1.context().cache().context().database();
    dbMrg0.forceCheckpoint("cp").futureFor(CheckpointState.FINISHED).get();
    dbMrg1.forceCheckpoint("cp").futureFor(CheckpointState.FINISHED).get();
    stopGrid(1);
    for (int k = 2500; k < 5000; k++) cache.put(k, k);
    ig1 = startGrid(1);
    awaitExchange(ig1);
    stopAllGrids(false);
    ig0 = startGrid(0);
    File[] cpMarkers = ig1CpDir.listFiles();
    for (File cpMark : cpMarkers) {
        if (cpMark.getName().contains("-END"))
            cpMark.delete();
    }
    assertThrows(null, () -> startGrid(1), Exception.class, null);
    ig1 = startGrid(1);
    assertEquals(1, ig0.cluster().nodes().size());
    assertEquals(1, ig1.cluster().nodes().size());
    AtomicBoolean actionNotFound = new AtomicBoolean(false);
    ig1.compute().run(new IgniteRunnable() {

        @IgniteInstanceResource
        private Ignite ig;

        @Override
        public void run() {
            MaintenanceRegistry mntcRegistry = ((IgniteEx) ig).context().maintenanceRegistry();
            List<MaintenanceAction<?>> actions = mntcRegistry.actionsForMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
            Optional<MaintenanceAction<?>> optional = actions.stream().filter(a -> a.name().equals(CleanCacheStoresMaintenanceAction.ACTION_NAME)).findFirst();
            if (!optional.isPresent())
                actionNotFound.set(true);
            else
                optional.get().execute();
            mntcRegistry.unregisterMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
        }
    });
    assertFalse("Action to clear corrupted PDS is not found", actionNotFound.get());
    stopAllGrids();
    ig1 = startGrid(1);
    ig1.cluster().state(ACTIVE);
    assertEquals(1, ig1.cluster().nodes().size());
    cache = ig1.cache(DEFAULT_CACHE_NAME);
    for (int k = 0; k < 2500; k++) assertFalse(cache.containsKey(k));
}
Also used : Optional(java.util.Optional) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) List(java.util.List) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with MaintenanceRegistry

use of org.apache.ignite.maintenance.MaintenanceRegistry in project ignite by apache.

the class WalEnableDisableWithNodeShutdownTest method startNodeWithMaintenance.

/**
 */
private Ignite startNodeWithMaintenance(String consistentId) throws Exception {
    Ignite node;
    try {
        node = Ignition.start(igniteCfg(false, consistentId));
    } catch (Exception ex) {
        assertTrue(X.hasCause(ex, "Cache groups with potentially corrupted partition files", IgniteException.class));
        node = Ignition.start(igniteCfg(false, consistentId));
        node.compute().run(new IgniteRunnable() {

            /**
             */
            @IgniteInstanceResource
            private Ignite ignite;

            /**
             */
            @Override
            public void run() {
                MaintenanceRegistry mntcRegistry = ((IgniteEx) ignite).context().maintenanceRegistry();
                List<MaintenanceAction<?>> actions = mntcRegistry.actionsForMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
                actions.stream().filter(a -> a.name().equals(CleanCacheStoresMaintenanceAction.ACTION_NAME)).findFirst().get().execute();
                mntcRegistry.unregisterMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
            }
        });
        node.close();
        node = Ignition.start(igniteCfg(false, consistentId));
    }
    return node;
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteException(org.apache.ignite.IgniteException) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) CleanCacheStoresMaintenanceAction(org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction) X(org.apache.ignite.internal.util.typedef.X) After(org.junit.After) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LinkedList(java.util.LinkedList) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) CORRUPTED_DATA_FILES_MNTC_TASK_NAME(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CORRUPTED_DATA_FILES_MNTC_TASK_NAME) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) CleanCacheStoresMaintenanceAction(org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction) Ignite(org.apache.ignite.Ignite) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Aggregations

MaintenanceRegistry (org.apache.ignite.maintenance.MaintenanceRegistry)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 List (java.util.List)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 File (java.io.File)3 Ignite (org.apache.ignite.Ignite)3 IgniteException (org.apache.ignite.IgniteException)3 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)3 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)3 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)3 MaintenanceAction (org.apache.ignite.maintenance.MaintenanceAction)3 MaintenanceTask (org.apache.ignite.maintenance.MaintenanceTask)3 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Optional (java.util.Optional)2 Ignition (org.apache.ignite.Ignition)2 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)2