use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager 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.GridCacheDatabaseSharedManager in project ignite by apache.
the class SnapshotFutureTask method start.
/**
* Initiates snapshot task.
*
* @return {@code true} if task started by this call.
*/
@Override
public boolean start() {
if (stopping())
return false;
try {
if (!started.compareAndSet(false, true))
return false;
tmpConsIdDir = U.resolveWorkDirectory(tmpSnpWorkDir.getAbsolutePath(), databaseRelativePath(cctx.kernalContext().pdsFolderResolver().resolveFolders().folderName()), false);
for (Integer grpId : parts.keySet()) {
CacheGroupContext gctx = cctx.cache().cacheGroup(grpId);
if (gctx == null)
throw new IgniteCheckedException("Cache group context not found: " + grpId);
if (!CU.isPersistentCache(gctx.config(), cctx.kernalContext().config().getDataStorageConfiguration()))
throw new IgniteCheckedException("In-memory cache groups are not allowed to be snapshot: " + grpId);
// Create cache group snapshot directory on start in a single thread.
U.ensureDirectory(cacheWorkDir(tmpConsIdDir, FilePageStoreManager.cacheDirName(gctx.config())), "directory for snapshotting cache group", log);
}
if (withMetaStorage) {
U.ensureDirectory(cacheWorkDir(tmpConsIdDir, MetaStorage.METASTORAGE_DIR_NAME), "directory for snapshotting metastorage", log);
}
startedFut.listen(f -> ((GridCacheDatabaseSharedManager) cctx.database()).removeCheckpointListener(this));
// Listener will be removed right after first execution.
((GridCacheDatabaseSharedManager) cctx.database()).addCheckpointListener(this);
if (log.isInfoEnabled()) {
log.info("Snapshot operation is scheduled on local node and will be handled by the checkpoint " + "listener [sctx=" + this + ", topVer=" + cctx.discovery().topologyVersionEx() + ']');
}
} catch (IgniteCheckedException e) {
acceptException(e);
return false;
}
return true;
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method testDefragmentationStatus.
/**
* @throws Exception If failed.
*/
@Test
public void testDefragmentationStatus() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
ig.getOrCreateCache(DEFAULT_CACHE_NAME + "1");
IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME + "2");
ig.getOrCreateCache(DEFAULT_CACHE_NAME + "3");
for (int i = 0; i < 1024; i++) cache.put(i, i);
forceCheckpoint(ig);
String grid0ConsId = ig.configuration().getConsistentId().toString();
ListeningTestLogger testLog = new ListeningTestLogger();
CommandHandler cmd = createCommandHandler(testLog);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
String port = grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
stopGrid(0);
blockCdl = new CountDownLatch(128);
waitCdl = new CountDownLatch(1);
UnaryOperator<IgniteConfiguration> cfgOp = cfg -> {
DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
FileIOFactory delegate = dsCfg.getFileIOFactory();
dsCfg.setFileIOFactory((file, modes) -> {
if (file.getName().contains("dfrg")) {
if (blockCdl.getCount() == 0) {
try {
waitCdl.await();
} catch (InterruptedException ignore) {
// No-op.
}
} else
blockCdl.countDown();
}
return delegate.create(file, modes);
});
return cfg;
};
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
try {
startGrid(0, cfgOp);
} catch (Exception e) {
// No-op.
throw new RuntimeException(e);
}
});
blockCdl.await();
List<LogListener> logLsnrs = Arrays.asList(LogListener.matches("default1 - size before/after: 0MB/0MB").build(), LogListener.matches("default2 - partitions processed/all:").build(), LogListener.matches("Awaiting defragmentation: default3").build());
for (LogListener logLsnr : logLsnrs) testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "status"));
waitCdl.countDown();
for (LogListener logLsnr : logLsnrs) assertTrue(logLsnr.check());
fut.get();
((GridCacheDatabaseSharedManager) grid(0).context().cache().context().database()).defragmentationManager().completionFuture().get();
testLog.clearListeners();
logLsnrs = Arrays.asList(LogListener.matches("default1 - size before/after: 0MB/0MB").build(), LogListener.matches(Pattern.compile("default2 - size before/after: (\\S+)/\\1")).build(), LogListener.matches("default3 - size before/after: 0MB/0MB").build());
for (LogListener logLsnr : logLsnrs) testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "status"));
for (LogListener logLsnr : logLsnrs) assertTrue(logLsnr.check());
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager 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.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgniteClusterSnapshotCheckTest method testClusterSnapshotCheckFailsOnPartitionDataDiffers.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotCheckFailsOnPartitionDataDiffers() throws Exception {
CacheConfiguration<Integer, Value> ccfg = txCacheConfig(new CacheConfiguration<Integer, Value>(DEFAULT_CACHE_NAME)).setAffinity(new RendezvousAffinityFunction(false, 1));
IgniteEx ignite = startGridsWithoutCache(2);
ignite.getOrCreateCache(ccfg).put(1, new Value(new byte[2000]));
forceCheckpoint(ignite);
GridCacheSharedContext<?, ?> cctx = ignite.context().cache().context();
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) cctx.database();
BinaryContext binCtx = ((CacheObjectBinaryProcessorImpl) ignite.context().cacheObjects()).binaryContext();
GridCacheAdapter<?, ?> cache = ignite.context().cache().internalCache(dfltCacheCfg.getName());
long partCtr = cache.context().topology().localPartition(PART_ID, NONE, false).dataStore().updateCounter();
AtomicBoolean done = new AtomicBoolean();
db.addCheckpointListener(new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) throws IgniteCheckedException {
// Change the cache value only at on of the cluster node to get hash conflict when the check command ends.
if (!done.compareAndSet(false, true))
return;
GridIterator<CacheDataRow> it = cache.context().offheap().partitionIterator(PART_ID);
assertTrue(it.hasNext());
CacheDataRow row0 = it.nextX();
AffinityTopologyVersion topVer = cctx.exchange().readyAffinityVersion();
GridCacheEntryEx cached = cache.entryEx(row0.key(), topVer);
byte[] bytes = new byte[2000];
new Random().nextBytes(bytes);
try {
BinaryObjectImpl newVal = new BinaryObjectImpl(binCtx, binCtx.marshaller().marshal(new Value(bytes)), 0);
boolean success = cached.initialValue(newVal, new GridCacheVersion(row0.version().topologyVersion(), row0.version().nodeOrder(), row0.version().order() + 1), null, null, TxState.NA, TxState.NA, TTL_ETERNAL, row0.expireTime(), true, topVer, DR_NONE, false, false, null);
assertTrue(success);
long newPartCtr = cache.context().topology().localPartition(PART_ID, NONE, false).dataStore().updateCounter();
assertEquals(newPartCtr, partCtr);
} catch (Exception e) {
throw new IgniteCheckedException(e);
}
}
@Override
public void onCheckpointBegin(Context ctx) throws IgniteCheckedException {
}
@Override
public void beforeCheckpointBegin(Context ctx) throws IgniteCheckedException {
}
});
db.waitForCheckpoint("test-checkpoint");
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
Path part0 = U.searchFileRecursively(snp(ignite).snapshotLocalDir(SNAPSHOT_NAME).toPath(), getPartitionFileName(PART_ID));
assertNotNull(part0);
assertTrue(part0.toString(), part0.toFile().exists());
IdleVerifyResultV2 res = snp(ignite).checkSnapshot(SNAPSHOT_NAME).get();
StringBuilder b = new StringBuilder();
res.print(b::append, true);
assertTrue(F.isEmpty(res.exceptions()));
assertContains(log, b.toString(), "The check procedure has failed, conflict partitions has been found: [counterConflicts=0, hashConflicts=1]");
}
Aggregations