Search in sources :

Example 1 with IgniteCacheDatabaseSharedManager

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

the class IgnitePageMemReplaceDelayedWriteUnitTest method createPageMemory.

/**
 * @param cfg configuration
 * @param pageWriter writer for page replacement.
 * @param pageSize page size
 * @return implementation for test
 */
@NotNull
private PageMemoryImpl createPageMemory(IgniteConfiguration cfg, ReplacedPageWriter pageWriter, int pageSize) {
    IgniteCacheDatabaseSharedManager db = mock(GridCacheDatabaseSharedManager.class);
    when(db.checkpointLockIsHeldByThread()).thenReturn(true);
    GridCacheSharedContext sctx = Mockito.mock(GridCacheSharedContext.class);
    when(sctx.pageStore()).thenReturn(new NoOpPageStoreManager());
    when(sctx.wal()).thenReturn(new NoOpWALManager());
    when(sctx.database()).thenReturn(db);
    when(sctx.logger(any(Class.class))).thenReturn(log);
    GridKernalContext kernalCtx = mock(GridKernalContext.class);
    when(kernalCtx.config()).thenReturn(cfg);
    when(sctx.kernalContext()).thenReturn(kernalCtx);
    DataRegionConfiguration regCfg = cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration();
    DataRegionMetricsImpl memMetrics = new DataRegionMetricsImpl(regCfg);
    long[] sizes = prepareSegmentSizes(regCfg.getMaxSize());
    DirectMemoryProvider provider = new UnsafeMemoryProvider(log);
    PageMemoryImpl memory = new PageMemoryImpl(provider, sizes, sctx, pageSize, pageWriter, null, () -> true, memMetrics, PageMemoryImpl.ThrottlingPolicy.DISABLED, null);
    memory.start();
    return memory;
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with IgniteCacheDatabaseSharedManager

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

the class PageMemoryImplTest method createPageMemory.

/**
 * @param throttlingPlc Throttling Policy.
 * @throws Exception If creating mock failed.
 */
private PageMemoryImpl createPageMemory(PageMemoryImpl.ThrottlingPolicy throttlingPlc) throws Exception {
    long[] sizes = new long[5];
    for (int i = 0; i < sizes.length; i++) sizes[i] = MAX_SIZE * MB / 4;
    sizes[4] = 5 * MB;
    DirectMemoryProvider provider = new UnsafeMemoryProvider(log);
    IgniteConfiguration igniteCfg = new IgniteConfiguration();
    igniteCfg.setDataStorageConfiguration(new DataStorageConfiguration());
    GridTestKernalContext kernalCtx = new GridTestKernalContext(new GridTestLog4jLogger(), igniteCfg);
    kernalCtx.add(new IgnitePluginProcessor(kernalCtx, igniteCfg, Collections.<PluginProvider>emptyList()));
    GridCacheSharedContext<Object, Object> sharedCtx = new GridCacheSharedContext<>(kernalCtx, null, null, null, new NoOpPageStoreManager(), new NoOpWALManager(), null, new IgniteCacheDatabaseSharedManager(), null, null, null, null, null, null, null, null);
    CheckpointWriteProgressSupplier noThrottle = Mockito.mock(CheckpointWriteProgressSupplier.class);
    Mockito.when(noThrottle.currentCheckpointPagesCount()).thenReturn(1_000_000);
    Mockito.when(noThrottle.evictedPagesCntr()).thenReturn(new AtomicInteger(0));
    Mockito.when(noThrottle.syncedPagesCounter()).thenReturn(new AtomicInteger(1_000_000));
    Mockito.when(noThrottle.writtenPagesCounter()).thenReturn(new AtomicInteger(1_000_000));
    PageMemoryImpl mem = new PageMemoryImpl(provider, sizes, sharedCtx, PAGE_SIZE, (fullPageId, byteBuf, tag) -> {
        assert false : "No page replacement (rotation with disk) should happen during the test";
    }, new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {

        @Override
        public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) {
        }
    }, new CheckpointLockStateChecker() {

        @Override
        public boolean checkpointLockIsHeldByThread() {
            return true;
        }
    }, new DataRegionMetricsImpl(igniteCfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration()), throttlingPlc, noThrottle);
    mem.start();
    return mem;
}
Also used : IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) CheckpointLockStateChecker(org.apache.ignite.internal.processors.cache.persistence.CheckpointLockStateChecker) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) PluginProvider(org.apache.ignite.plugin.PluginProvider) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) CheckpointWriteProgressSupplier(org.apache.ignite.internal.processors.cache.persistence.CheckpointWriteProgressSupplier) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 3 with IgniteCacheDatabaseSharedManager

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

the class SqlViewExporterSpiTest method testMetastorage.

/**
 */
@Test
public void testMetastorage() throws Exception {
    IgniteCacheDatabaseSharedManager db = ignite0.context().cache().context().database();
    SystemView<MetastorageView> metaStoreView = ignite0.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();
    }
    assertEquals(1, execute(ignite0, "SELECT * FROM SYS.METASTORAGE WHERE name = ? AND value = ?", name, val).size());
    assertEquals(1, execute(ignite0, "SELECT * FROM SYS.METASTORAGE WHERE name = ? AND value = ?", unmarshalledName, unmarshalledVal).size());
}
Also used : MetastorageView(org.apache.ignite.spi.systemview.view.MetastorageView) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) AbstractExporterSpiTest(org.apache.ignite.internal.metric.AbstractExporterSpiTest) Test(org.junit.Test)

Example 4 with IgniteCacheDatabaseSharedManager

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

the class BPlusTreeReuseListPageMemoryImplTest method createPageMemory.

/**
 * {@inheritDoc}
 */
@Override
protected PageMemory createPageMemory() throws Exception {
    long[] sizes = new long[CPUS + 1];
    for (int i = 0; i < sizes.length; i++) sizes[i] = 1024 * MB / CPUS;
    sizes[CPUS] = 10 * MB;
    DirectMemoryProvider provider = new UnsafeMemoryProvider(log);
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setEncryptionSpi(new NoopEncryptionSpi());
    cfg.setMetricExporterSpi(new NoopMetricExporterSpi());
    cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi());
    cfg.setDataStorageConfiguration(new DataStorageConfiguration());
    GridTestKernalContext cctx = new GridTestKernalContext(log, cfg);
    cctx.add(new IgnitePluginProcessor(cctx, cfg, Collections.emptyList()));
    cctx.add(new GridInternalSubscriptionProcessor(cctx));
    cctx.add(new PerformanceStatisticsProcessor(cctx));
    cctx.add(new GridEncryptionManager(cctx));
    cctx.add(new GridMetricManager(cctx));
    cctx.add(new GridSystemViewManager(cctx));
    GridCacheSharedContext<Object, Object> sharedCtx = new GridCacheSharedContext<>(cctx, null, null, null, new NoOpPageStoreManager(), new NoOpWALManager(), null, new IgniteCacheDatabaseSharedManager(), null, null, null, null, null, null, null, null, null, null, null, null, null);
    IgniteOutClosure<CheckpointProgress> clo = new IgniteOutClosure<CheckpointProgress>() {

        @Override
        public CheckpointProgress apply() {
            return Mockito.mock(CheckpointProgressImpl.class);
        }
    };
    PageMemory mem = new PageMemoryImpl(provider, sizes, sharedCtx, sharedCtx.pageStore(), PAGE_SIZE, (fullPageId, byteBuf, tag) -> {
        assert false : "No page replacement (rotation with disk) should happen during the test";
    }, new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {

        @Override
        public void applyx(Long page, FullPageId fullPageId, PageMemoryEx pageMem) {
        }
    }, () -> true, new DataRegionMetricsImpl(new DataRegionConfiguration(), cctx), PageMemoryImpl.ThrottlingPolicy.DISABLED, clo);
    mem.start();
    return mem;
}
Also used : IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) NoopEncryptionSpi(org.apache.ignite.spi.encryption.noop.NoopEncryptionSpi) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) JmxSystemViewExporterSpi(org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi) PerformanceStatisticsProcessor(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 5 with IgniteCacheDatabaseSharedManager

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

the class StatisticsStorageRestartTest method testUnreadableStatistics.

/**
 * Test that after any deserialization error during startup reads all statistics for object will be deleted:
 *
 * 1) put into metastore some statistics for two objects.
 * 2) put into metastore some broken (A) value into statistics obj1 prefix
 * 3) put into metastore some object (B) outside the statistics prefix.
 * 4) start statistics store with such metastore
 * 5) check that log will contain error message and that object A will be deleted from metastore (with all objects
 * partition statistics), while
 * object C won't be deleted.
 *
 * @throws IgniteCheckedException In case of errors.
 */
@Test
public void testUnreadableStatistics() throws IgniteCheckedException {
    statStore.onReadyForReadWrite(metastorage);
    statStore.saveLocalPartitionStatistics(k1, stat1_1);
    statStore.replaceLocalPartitionsStatistics(k2, Arrays.asList(stat2_2, stat2_3));
    String statKeyInvalid = String.format("stats.data.%s.%s.%d", k1.schema(), k1.obj(), 1000);
    metastorage.write(statKeyInvalid, new byte[2]);
    String outerStatKey = "some.key.1";
    byte[] outerStatValue = new byte[] { 1, 2 };
    metastorage.write(outerStatKey, outerStatValue);
    IgniteStatisticsPersistenceStoreImpl statStore2 = new IgniteStatisticsPersistenceStoreImpl(subscriptionProcessor, new IgniteCacheDatabaseSharedManager() {
    }, cls -> log);
    statStore2.onReadyForReadWrite(metastorage);
    assertNull(metastorage.read(statKeyInvalid));
    assertTrue(statStore.getLocalPartitionsStatistics(k1).isEmpty());
    assertFalse(statStore.getLocalPartitionsStatistics(k2).isEmpty());
    assertTrue(Arrays.equals(outerStatValue, (byte[]) metastorage.read(outerStatKey)));
}
Also used : IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Test(org.junit.Test)

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