Search in sources :

Example 6 with MaintenanceRegistry

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

the class FilePageStoreManager method initDir.

/**
 * @param cacheWorkDir Work directory.
 * @param grpId Group ID.
 * @param partitions Number of partitions.
 * @param pageMetrics Page metrics.
 * @param encrypted {@code True} if this cache encrypted.
 * @return Cache store holder.
 * @throws IgniteCheckedException If failed.
 */
private CacheStoreHolder initDir(File cacheWorkDir, int grpId, int partitions, PageMetrics pageMetrics, boolean encrypted) throws IgniteCheckedException {
    try {
        boolean dirExisted = checkAndInitCacheWorkDir(cacheWorkDir);
        if (dirExisted) {
            MaintenanceRegistry mntcReg = cctx.kernalContext().maintenanceRegistry();
            if (!mntcReg.isMaintenanceMode())
                DefragmentationFileUtils.beforeInitPageStores(cacheWorkDir, log);
        }
        File idxFile = new File(cacheWorkDir, INDEX_FILE_NAME);
        if (dirExisted && !idxFile.exists())
            grpsWithoutIdx.add(grpId);
        FileVersionCheckingFactory pageStoreFactory = getPageStoreFactory(grpId, encrypted);
        PageStore idxStore = pageStoreFactory.createPageStore(PageStore.TYPE_IDX, idxFile, pageMetrics.totalPages()::add);
        PageStore[] partStores = new PageStore[partitions];
        for (int partId = 0; partId < partStores.length; partId++) {
            final int p = partId;
            PageStore partStore = pageStoreFactory.createPageStore(PageStore.TYPE_DATA, () -> getPartitionFilePath(cacheWorkDir, p), pageMetrics.totalPages()::add);
            partStores[partId] = partStore;
        }
        return new CacheStoreHolder(idxStore, partStores);
    } catch (IgniteCheckedException e) {
        if (X.hasCause(e, StorageException.class, IOException.class))
            cctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
        throw e;
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FailureContext(org.apache.ignite.failure.FailureContext) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) IOException(java.io.IOException) File(java.io.File) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException)

Example 7 with MaintenanceRegistry

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

the class GridCacheDatabaseSharedManager method startMemoryRestore.

/**
 * {@inheritDoc}
 */
@Override
public void startMemoryRestore(GridKernalContext kctx, TimeBag startTimer) throws IgniteCheckedException {
    if (kctx.clientNode())
        return;
    MaintenanceRegistry mntcRegistry = kctx.maintenanceRegistry();
    MaintenanceTask mntcTask = mntcRegistry.activeMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
    if (mntcTask != null) {
        log.warning("Maintenance task found, stop restoring memory");
        File workDir = ((FilePageStoreManager) cctx.pageStore()).workDir();
        mntcRegistry.registerWorkflowCallback(CORRUPTED_DATA_FILES_MNTC_TASK_NAME, new CorruptedPdsMaintenanceCallback(workDir, Arrays.asList(mntcTask.parameters().split(Pattern.quote(File.separator)))));
        return;
    }
    checkpointReadLock();
    RestoreLogicalState logicalState;
    try {
        // Preform early regions startup before restoring state.
        initAndStartRegions(kctx.config().getDataStorageConfiguration());
        startTimer.finishGlobalStage("Init and start regions");
        // Restore binary memory for all not WAL disabled cache groups.
        restoreBinaryMemory(groupsWithEnabledWal(), physicalRecords());
        if (recoveryVerboseLogging && log.isInfoEnabled()) {
            log.info("Partition states information after BINARY RECOVERY phase:");
            dumpPartitionsInfo(cctx, log);
        }
        startTimer.finishGlobalStage("Restore binary memory");
        CheckpointStatus status = readCheckpointStatus();
        logicalState = applyLogicalUpdates(status, groupsWithEnabledWal(), logicalRecords(), false);
        cctx.tm().clearUncommitedStates();
        cctx.wal().startAutoReleaseSegments();
        if (recoveryVerboseLogging && log.isInfoEnabled()) {
            log.info("Partition states information after LOGICAL RECOVERY phase:");
            dumpPartitionsInfo(cctx, log);
        }
        startTimer.finishGlobalStage("Restore logical state");
    } catch (IgniteCheckedException e) {
        releaseFileLock();
        throw e;
    } finally {
        checkpointReadUnlock();
    }
    walTail = tailPointer(logicalState);
    cctx.wal().onDeActivate(kctx);
}
Also used : CheckpointStatus(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointStatus) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) File(java.io.File)

Example 8 with MaintenanceRegistry

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

the class IgniteDefragmentationImpl method schedule.

/**
 * {@inheritDoc}
 */
@Override
public ScheduleResult schedule(List<String> cacheNames) throws IgniteCheckedException {
    final MaintenanceRegistry maintenanceRegistry = ctx.maintenanceRegistry();
    MaintenanceTask oldTask;
    try {
        oldTask = maintenanceRegistry.registerMaintenanceTask(toStore(cacheNames != null ? cacheNames : Collections.emptyList()));
    } catch (IgniteCheckedException e) {
        throw new IgniteCheckedException("Scheduling failed: " + e.getMessage());
    }
    return oldTask != null ? ScheduleResult.SUCCESS_SUPERSEDED_PREVIOUS : ScheduleResult.SUCCESS;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask)

Example 9 with MaintenanceRegistry

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

the class IgniteDefragmentationImpl method status.

/**
 * {@inheritDoc}
 */
@Override
public DefragmentationStatus status() throws IgniteCheckedException {
    final MaintenanceRegistry maintenanceRegistry = ctx.maintenanceRegistry();
    if (!maintenanceRegistry.isMaintenanceMode())
        throw new IgniteCheckedException("Node is not in maintenance mode.");
    IgniteCacheDatabaseSharedManager dbMgr = ctx.cache().context().database();
    assert dbMgr instanceof GridCacheDatabaseSharedManager;
    CachePartitionDefragmentationManager defrgMgr = ((GridCacheDatabaseSharedManager) dbMgr).defragmentationManager();
    if (defrgMgr == null)
        throw new IgniteCheckedException("There's no active defragmentation process on the node.");
    final Status status = defrgMgr.status();
    final long startTs = status.getStartTs();
    final long finishTs = status.getFinishTs();
    final long elapsedTime = finishTs != 0 ? finishTs - startTs : System.currentTimeMillis() - startTs;
    Map<String, CompletedDefragmentationInfo> completedCaches = new HashMap<>();
    Map<String, InProgressDefragmentationInfo> progressCaches = new HashMap<>();
    status.getFinishedGroups().forEach((context, progress) -> {
        final String name = context.cacheOrGroupName();
        final long oldSize = progress.getOldSize();
        final long newSize = progress.getNewSize();
        final long cgElapsedTime = progress.getFinishTs() - progress.getStartTs();
        final CompletedDefragmentationInfo info = new CompletedDefragmentationInfo(cgElapsedTime, oldSize, newSize);
        completedCaches.put(name, info);
    });
    status.getProgressGroups().forEach((context, progress) -> {
        final String name = context.cacheOrGroupName();
        final long cgElapsedTime = System.currentTimeMillis() - progress.getStartTs();
        final int partsTotal = progress.getPartsTotal();
        final int partsCompleted = progress.getPartsCompleted();
        final InProgressDefragmentationInfo info = new InProgressDefragmentationInfo(cgElapsedTime, partsCompleted, partsTotal);
        progressCaches.put(name, info);
    });
    return new DefragmentationStatus(completedCaches, progressCaches, status.getScheduledGroups(), status.getSkippedGroups(), status.getTotalPartitionCount(), status.getDefragmentedPartitionCount(), startTs, elapsedTime);
}
Also used : Status(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.Status) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) HashMap(java.util.HashMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 10 with MaintenanceRegistry

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

the class WalEnableDisableWithRestartsTest method startNodeWithMaintenance.

/**
 */
private Ignite startNodeWithMaintenance(String consistentId) throws Exception {
    Ignite node;
    try {
        node = Ignition.start(igniteCfg(false, consistentId));
    } catch (Exception ex) {
        if (!X.hasCause(ex, "Cache groups with potentially corrupted partition files", IgniteException.class))
            throw ex;
        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) 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