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