use of org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager in project ignite by apache.
the class GridCacheProcessor method createSharedContext.
/**
* Creates shared context.
*
* @param kernalCtx Kernal context.
* @param storeSesLsnrs Store session listeners.
* @return Shared context.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, Collection<CacheStoreSessionListener> storeSesLsnrs) throws IgniteCheckedException {
IgniteTxManager tm = new IgniteTxManager();
GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
GridCacheVersionManager verMgr = new GridCacheVersionManager();
GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager();
GridCachePartitionExchangeManager exchMgr = new GridCachePartitionExchangeManager();
IgniteCacheDatabaseSharedManager dbMgr;
IgnitePageStoreManager pageStoreMgr = null;
IgniteWriteAheadLogManager walMgr = null;
if (CU.isPersistenceEnabled(ctx.config()) && !ctx.clientNode()) {
dbMgr = new GridCacheDatabaseSharedManager(ctx);
pageStoreMgr = ctx.plugins().createComponent(IgnitePageStoreManager.class);
if (pageStoreMgr == null)
pageStoreMgr = new FilePageStoreManager(ctx);
walMgr = ctx.plugins().createComponent(IgniteWriteAheadLogManager.class);
if (walMgr == null)
walMgr = new FileWriteAheadLogManager(ctx);
} else {
if (CU.isPersistenceEnabled(ctx.config()) && ctx.clientNode()) {
U.warn(log, "Persistent Store is not supported on client nodes (Persistent Store's" + " configuration will be ignored).");
}
dbMgr = new IgniteCacheDatabaseSharedManager();
}
WalStateManager walStateMgr = new WalStateManager(ctx);
IgniteSnapshotManager snapshotMgr = new IgniteSnapshotManager(ctx);
IgniteCacheSnapshotManager snpMgr = ctx.plugins().createComponent(IgniteCacheSnapshotManager.class);
if (snpMgr == null)
snpMgr = new IgniteCacheSnapshotManager();
GridCacheIoManager ioMgr = new GridCacheIoManager();
CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager();
GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager();
PartitionsEvictManager evict = new PartitionsEvictManager();
CacheJtaManagerAdapter jta = JTA.createOptional();
MvccCachingManager mvccCachingMgr = new MvccCachingManager();
DeadlockDetectionManager deadlockDetectionMgr = new DeadlockDetectionManager();
CacheDiagnosticManager diagnosticMgr = new CacheDiagnosticManager();
return new GridCacheSharedContext(kernalCtx, tm, verMgr, mvccMgr, pageStoreMgr, walMgr, walStateMgr, dbMgr, snapshotMgr, snpMgr, depMgr, exchMgr, topMgr, ioMgr, ttl, evict, jta, storeSesLsnrs, mvccCachingMgr, deadlockDetectionMgr, diagnosticMgr);
}
use of org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager in project ignite by apache.
the class ClusterCachesInfo method processStartNewCacheRequest.
/**
* @param exchangeActions Exchange actions to update.
* @param topVer Topology version.
* @param persistedCfgs {@code True} if process start of persisted caches during cluster activation.
* @param res Accumulator for cache change process results.
* @param req Cache change request.
* @param cacheName Cache name.
* @return True if there was no errors.
*/
private boolean processStartNewCacheRequest(ExchangeActions exchangeActions, AffinityTopologyVersion topVer, boolean persistedCfgs, CacheChangeProcessResult res, DynamicCacheChangeRequest req, String cacheName) {
assert exchangeActions != null;
CacheConfiguration<?, ?> ccfg = req.startCacheConfiguration();
IgniteCheckedException err = null;
if (ctx.cache().context().readOnlyMode()) {
err = new IgniteClusterReadOnlyException(String.format(CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT, "start cache", ccfg.getGroupName(), cacheName));
}
if (err == null) {
String conflictErr = checkCacheConflict(req.startCacheConfiguration());
if (conflictErr != null) {
U.warn(log, "Ignore cache start request. " + conflictErr);
err = new IgniteCheckedException("Failed to start cache. " + conflictErr);
}
}
if (err == null)
err = QueryUtils.checkQueryEntityConflicts(req.startCacheConfiguration(), registeredCaches.values());
if (err == null) {
GridEncryptionManager encMgr = ctx.encryption();
if (ccfg.isEncryptionEnabled()) {
if (encMgr.isMasterKeyChangeInProgress())
err = new IgniteCheckedException("Cache start failed. Master key change is in progress.");
else if (encMgr.masterKeyDigest() != null && !Arrays.equals(encMgr.masterKeyDigest(), req.masterKeyDigest())) {
err = new IgniteCheckedException("Cache start failed. The request was initiated before " + "the master key change and can't be processed.");
}
if (err != null)
U.warn(log, "Ignore cache start request during the master key change process.", err);
}
}
if (err == null && req.restartId() == null) {
IgniteSnapshotManager snapshotMgr = ctx.cache().context().snapshotMgr();
if (snapshotMgr.isRestoring(ccfg)) {
err = new IgniteCheckedException("Cache start failed. A cache or group with the same name is " + "currently being restored from a snapshot [cache=" + cacheName + (ccfg.getGroupName() == null ? "" : ", group=" + ccfg.getGroupName()) + ']');
}
}
if (err != null) {
if (persistedCfgs)
res.errs.add(err);
else
ctx.cache().completeCacheStartFuture(req, false, err);
return false;
}
assert req.cacheType() != null : req;
assert F.eq(ccfg.getName(), cacheName) : req;
int cacheId = CU.cacheId(cacheName);
CacheGroupDescriptor grpDesc = registerCacheGroup(exchangeActions, topVer, ccfg, cacheId, req.initiatingNodeId(), req.deploymentId(), req.encryptionKey(), req.cacheConfigurationEnrichment());
DynamicCacheDescriptor startDesc = new DynamicCacheDescriptor(ctx, ccfg, req.cacheType(), grpDesc, false, req.initiatingNodeId(), false, req.sql(), req.deploymentId(), req.schema(), req.cacheConfigurationEnrichment());
DynamicCacheDescriptor old = registeredCaches.put(ccfg.getName(), startDesc);
registeredCachesById.put(startDesc.cacheId(), startDesc);
restartingCaches.remove(ccfg.getName());
assert old == null;
ctx.discovery().setCacheFilter(startDesc.cacheId(), grpDesc.groupId(), ccfg.getName(), ccfg.getNearConfiguration() != null);
if (!persistedCfgs) {
ctx.discovery().addClientNode(cacheName, req.initiatingNodeId(), req.nearCacheConfiguration() != null);
}
res.addedDescs.add(startDesc);
exchangeActions.addCacheToStart(req, startDesc);
return true;
}
use of org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager in project ignite by apache.
the class GridCommandHandlerTest method testSnapshotRestoreCancelAndStatus.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotRestoreCancelAndStatus() throws Exception {
int keysCnt = 2048;
String snpName = "snapshot_25052021";
String missingSnpName = "snapshot_MISSING";
IgniteEx ig = startGrid(getConfiguration(getTestIgniteInstanceName(0)).setSnapshotThreadPoolSize(1));
startGrid(1).cluster().state(ACTIVE);
injectTestSystemOut();
createCacheAndPreload(ig, keysCnt);
ig.snapshot().createSnapshot(snpName).get(getTestTimeout());
int locPartsCnt = ig.cachex(DEFAULT_CACHE_NAME).context().topology().localPartitions().size();
ig.destroyCache(DEFAULT_CACHE_NAME);
awaitPartitionMapExchange();
CommandHandler h = new CommandHandler();
CountDownLatch ioStartLatch = new CountDownLatch(1);
IgniteSnapshotManager snpMgr = ig.context().cache().context().snapshotMgr();
// Replace the IO factory in the snapshot manager so we have enough time to test the status command.
snpMgr.ioFactory(new SlowDownFileIoFactory(snpMgr.ioFactory(), getTestTimeout() / locPartsCnt, ioStartLatch));
// Restore single cache group.
IgniteFuture<Void> restoreFut = snpMgr.restoreSnapshot(snpName, Collections.singleton(DEFAULT_CACHE_NAME));
ioStartLatch.await(getTestTimeout(), TimeUnit.MILLISECONDS);
assertFalse(restoreFut.isDone());
// Check the status with a control command.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--status"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation is running [snapshot=" + snpName + ']');
// Check "status" with the wrong snapshot name.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", missingSnpName, "--status"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + missingSnpName + ']');
// Check "cancel" with the wrong snapshot name.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", missingSnpName, "--cancel"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + missingSnpName + ']');
// Cancel operation using control command.
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--cancel"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation canceled [snapshot=" + snpName + ']');
GridTestUtils.assertThrowsAnyCause(log, () -> restoreFut.get(getTestTimeout()), IgniteCheckedException.class, "Operation has been canceled by the user.");
// Make sure the context disappeared at node 1.
boolean ctxDisposed = waitForCondition(() -> !grid(1).context().cache().context().snapshotMgr().isRestoring(), getTestTimeout());
assertTrue(ctxDisposed);
assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "restore", snpName, "--status"));
assertContains(log, testOut.toString(), "Snapshot cache group restore operation is NOT running [snapshot=" + snpName + ']');
assertNull(ig.cache(DEFAULT_CACHE_NAME));
}
Aggregations