Search in sources :

Example 26 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class GridCachePartitionExchangeManagerWarningsTest method testDumpLongRunningOperationsWaitForFullyInitializedExchangeManager.

/**
 */
@Test
public void testDumpLongRunningOperationsWaitForFullyInitializedExchangeManager() throws Exception {
    long waitingTimeout = 5_000;
    PrintStream errStream = System.err;
    CountDownLatch startLatch = new CountDownLatch(1);
    CountDownLatch waitLatch = new CountDownLatch(1);
    try {
        // GridCachePartitionExchangeManager#dumpLongRunningOperations() uses diagnostic log,
        // which can be non-initialized, and so, error messgaes are logged into standard error output stream.
        ByteArrayOutputStream testOut = new ByteArrayOutputStream(16 * 1024);
        System.setErr(new PrintStream(testOut));
        AtomicReference<IgniteInternalFuture<?>> dumpOpsFut = new AtomicReference<>();
        IgniteInternalFuture<Ignite> startFut = null;
        // Lyficycle bean allows to register DatabaseLifecycleListener and trigger dumpLongRunningOperations
        // before GridCachePartitionExchangeManager is started.
        lifecycleBean = new LifecycleBean() {

            /**
             * Ignite instance.
             */
            @IgniteInstanceResource
            IgniteEx ignite;

            /**
             * {@inheritDoc}
             */
            @Override
            public void onLifecycleEvent(LifecycleEventType evt) throws IgniteException {
                if (evt == LifecycleEventType.BEFORE_NODE_START) {
                    ignite.context().internalSubscriptionProcessor().registerDatabaseListener(new DatabaseLifecycleListener() {

                        @Override
                        public void onInitDataRegions(IgniteCacheDatabaseSharedManager mgr) throws IgniteCheckedException {
                            dumpOpsFut.set(GridTestUtils.runAsync(() -> ignite.context().cache().context().exchange().dumpLongRunningOperations(1_000)));
                            // Let's allow to check that dumpLongRunningOperations is triggered.
                            startLatch.countDown();
                            // Wait for the check
                            try {
                                if (!waitLatch.await(waitingTimeout * 3, TimeUnit.MILLISECONDS))
                                    throw new IgniteCheckedException("Failed to wait for a check of dumpLongRunningOperations");
                            } catch (InterruptedException e) {
                                throw new IgniteCheckedException(e);
                            }
                        }
                    });
                }
            }
        };
        startFut = GridTestUtils.runAsync(new Callable<Ignite>() {

            @Override
            public Ignite call() throws Exception {
                return startGrid(0);
            }
        });
        assertTrue("Server node did not start in " + waitingTimeout + " ms.", startLatch.await(waitingTimeout, TimeUnit.MILLISECONDS));
        // Check that dumpLongRunningOperations did not produce any error.
        if (GridTestUtils.waitForCondition(() -> dumpOpsFut.get().isDone(), waitingTimeout)) {
            // Check that error output stream does not contain NullPointerException.
            String output = testOut.toString();
            assertTrue("Unexpected error [err=" + output + ']', output.isEmpty());
        }
        // Unblock starting the node.
        waitLatch.countDown();
        assertTrue("Dumping log running operations is not completed yet.", GridTestUtils.waitForCondition(() -> dumpOpsFut.get().isDone(), waitingTimeout));
        // Check that error output stream does not contain any error.
        String output = testOut.toString();
        assertTrue("Unexpected error [err=" + output + ']', output.isEmpty());
        startFut.get(waitingTimeout, TimeUnit.MILLISECONDS);
    } finally {
        startLatch.countDown();
        waitLatch.countDown();
        System.setErr(errStream);
    }
}
Also used : PrintStream(java.io.PrintStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteException(org.apache.ignite.IgniteException) LifecycleBean(org.apache.ignite.lifecycle.LifecycleBean) Ignite(org.apache.ignite.Ignite) LifecycleEventType(org.apache.ignite.lifecycle.LifecycleEventType) DatabaseLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.DatabaseLifecycleListener) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 27 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class SystemViewSelfTest method testMetastorage.

/**
 */
@Test
public void testMetastorage() throws Exception {
    cleanPersistenceDir();
    try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))))) {
        ignite.cluster().state(ClusterState.ACTIVE);
        IgniteCacheDatabaseSharedManager db = ignite.context().cache().context().database();
        SystemView<MetastorageView> metaStoreView = ignite.context().systemView().view(METASTORE_VIEW);
        assertNotNull(metaStoreView);
        String name = "test-key";
        String val = "test-value";
        String unmarshalledName = "unmarshalled-key";
        String unmarshalledVal = "[Raw data. 0 bytes]";
        db.checkpointReadLock();
        try {
            db.metaStorage().write(name, val);
            db.metaStorage().writeRaw(unmarshalledName, new byte[0]);
        } finally {
            db.checkpointReadUnlock();
        }
        assertNotNull(F.find(metaStoreView, null, (IgnitePredicate<? super MetastorageView>) view -> name.equals(view.name()) && val.equals(view.value())));
        assertNotNull(F.find(metaStoreView, null, (IgnitePredicate<? super MetastorageView>) view -> unmarshalledName.equals(view.name()) && unmarshalledVal.equals(view.value())));
    }
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) MetastorageView(org.apache.ignite.spi.systemview.view.MetastorageView) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 28 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class IgnitePdsPageReplacementTest method getMemory.

/**
 * @param ig Ignite instance.
 * @return Memory and store.
 * @throws Exception If failed to initialize the store.
 */
private PageMemory getMemory(IgniteEx ig) throws Exception {
    final GridCacheSharedContext<Object, Object> sharedCtx = ig.context().cache().context();
    final IgniteCacheDatabaseSharedManager db = sharedCtx.database();
    return db.dataRegion(null).pageMemory();
}
Also used : IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 29 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager 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 30 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class InlineIndexFactory method createIndex.

/**
 * {@inheritDoc}
 */
@Override
public Index createIndex(GridCacheContext<?, ?> cctx, IndexDefinition def) {
    SortedIndexDefinition sdef = (SortedIndexDefinition) def;
    InlineIndexTree[] trees = new InlineIndexTree[sdef.segments()];
    InlineRecommender recommender = new InlineRecommender(cctx, sdef);
    IoStatisticsHolderIndex stats = new IoStatisticsHolderIndex(SORTED_INDEX, cctx.name(), sdef.idxName().idxName(), cctx.kernalContext().metric());
    try {
        for (int i = 0; i < sdef.segments(); ++i) {
            // Required for persistence.
            IgniteCacheDatabaseSharedManager db = cctx.shared().database();
            db.checkpointReadLock();
            try {
                RootPage page = rootPage(cctx, sdef.treeName(), i);
                trees[i] = createIndexSegment(cctx, sdef, page, stats, recommender, i);
            } finally {
                db.checkpointReadUnlock();
            }
        }
        return new InlineIndexImpl(cctx, sdef, trees, stats);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IoStatisticsHolderIndex(org.apache.ignite.internal.metric.IoStatisticsHolderIndex) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Aggregations

IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)58 Test (org.junit.Test)27 IgniteEx (org.apache.ignite.internal.IgniteEx)24 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)10 GridInternalSubscriptionProcessor (org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor)9 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)8 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)7 GridSystemViewManager (org.apache.ignite.internal.managers.systemview.GridSystemViewManager)7 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)7 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)7 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)7 IgnitePluginProcessor (org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor)6 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)6 HashMap (java.util.HashMap)5 GridEncryptionManager (org.apache.ignite.internal.managers.encryption.GridEncryptionManager)5 JmxSystemViewExporterSpi (org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi)5