Search in sources :

Example 46 with GridCacheDatabaseSharedManager

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);
}
Also used : CacheJtaManagerAdapter(org.apache.ignite.internal.processors.cache.jta.CacheJtaManagerAdapter) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteCacheSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteCacheSnapshotManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) MvccCachingManager(org.apache.ignite.internal.processors.cache.mvcc.MvccCachingManager) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) DeadlockDetectionManager(org.apache.ignite.internal.processors.cache.mvcc.DeadlockDetectionManager) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) PartitionsEvictManager(org.apache.ignite.internal.processors.cache.distributed.dht.topology.PartitionsEvictManager) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) IgniteSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 47 with GridCacheDatabaseSharedManager

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;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 48 with GridCacheDatabaseSharedManager

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());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) Arrays(java.util.Arrays) IgniteNodeAttributes(org.apache.ignite.internal.IgniteNodeAttributes) ClusterState(org.apache.ignite.cluster.ClusterState) UnaryOperator(java.util.function.UnaryOperator) IgniteEx(org.apache.ignite.internal.IgniteEx) Formatter(java.util.logging.Formatter) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) EXIT_CODE_INVALID_ARGUMENTS(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) StreamHandler(java.util.logging.StreamHandler) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) DefragmentationParameters(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) LogListener(org.apache.ignite.testframework.LogListener) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) CountDownLatch(java.util.concurrent.CountDownLatch) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test)

Example 49 with GridCacheDatabaseSharedManager

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);
}
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 50 with GridCacheDatabaseSharedManager

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]");
}
Also used : CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Random(java.util.Random) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Path(java.nio.file.Path) IgniteSnapshotManager.databaseRelativePath(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath) BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteDataIntegrityViolationException(org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteEx(org.apache.ignite.internal.IgniteEx) GridIterator(org.apache.ignite.internal.util.lang.GridIterator) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) Test(org.junit.Test)

Aggregations

GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)85 IgniteEx (org.apache.ignite.internal.IgniteEx)54 Test (org.junit.Test)48 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)33 Ignite (org.apache.ignite.Ignite)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)15 ArrayList (java.util.ArrayList)13 File (java.io.File)12 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)12 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 List (java.util.List)10 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)10 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 IgniteCache (org.apache.ignite.IgniteCache)9 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)9 CheckpointListener (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener)9