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