Search in sources :

Example 41 with IgniteCacheDatabaseSharedManager

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

the class DistributedMetaStoragePersistentTest method testNamesCollision.

/**
 * @throws Exception If failed.
 */
@Test
public void testNamesCollision() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    IgniteCacheDatabaseSharedManager dbSharedMgr = ignite.context().cache().context().database();
    MetaStorage locMetastorage = dbSharedMgr.metaStorage();
    DistributedMetaStorage distributedMetastorage = ignite.context().distributedMetastorage();
    dbSharedMgr.checkpointReadLock();
    try {
        locMetastorage.write("key", "localValue");
    } finally {
        dbSharedMgr.checkpointReadUnlock();
    }
    distributedMetastorage.write("key", "globalValue");
    dbSharedMgr.checkpointReadLock();
    try {
        assertEquals("localValue", locMetastorage.read("key"));
    } finally {
        dbSharedMgr.checkpointReadUnlock();
    }
    assertEquals("globalValue", distributedMetastorage.read("key"));
}
Also used : MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Test(org.junit.Test)

Example 42 with IgniteCacheDatabaseSharedManager

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

the class WalRolloverTypesTest method checkCurrentSegmentTypeWithCacheActivity.

/**
 * Under load, ensures the record gets into very beginning of the segment in {@code NEXT_SEGMENT} log mode.
 */
private void checkCurrentSegmentTypeWithCacheActivity(WALMode mode, boolean disableArch) throws Exception {
    walMode = mode;
    disableWALArchiving = disableArch;
    IgniteEx ig = startGrid(0);
    ig.cluster().active(true);
    IgniteCache<Integer, Integer> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
    final long testDuration = 30_000;
    long startTime = U.currentTimeMillis();
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(() -> {
        ThreadLocalRandom random = ThreadLocalRandom.current();
        while (U.currentTimeMillis() - startTime < testDuration) cache.put(random.nextInt(100), random.nextInt(100_000));
    }, 8, "cache-put-thread");
    IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
    IgniteCacheDatabaseSharedManager dbMgr = ig.context().cache().context().database();
    AdHocWALRecord markerRecord = new AdHocWALRecord();
    WALPointer ptr0;
    WALPointer ptr1;
    do {
        try {
            U.sleep(1000);
            dbMgr.checkpointReadLock();
            try {
                ptr0 = walMgr.log(markerRecord, CURRENT_SEGMENT);
            } finally {
                dbMgr.checkpointReadUnlock();
            }
            ptr1 = walMgr.log(markerRecord);
            assertTrue(ptr0.index() < ptr1.index());
        } catch (IgniteCheckedException e) {
            log.error(e.getMessage(), e);
        }
    } while (U.currentTimeMillis() - startTime < testDuration);
    fut.get();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 43 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, PageStoreWriter pageWriter, int pageSize) {
    IgniteCacheDatabaseSharedManager db = mock(GridCacheDatabaseSharedManager.class);
    when(db.checkpointLockIsHeldByThread()).thenReturn(true);
    GridCacheSharedContext sctx = Mockito.mock(GridCacheSharedContext.class);
    when(sctx.gridConfig()).thenReturn(cfg);
    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(kernalCtx.log(any(Class.class))).thenReturn(log);
    when(kernalCtx.internalSubscriptionProcessor()).thenAnswer(mock -> new GridInternalSubscriptionProcessor(kernalCtx));
    when(kernalCtx.encryption()).thenAnswer(mock -> new GridEncryptionManager(kernalCtx));
    when(kernalCtx.metric()).thenAnswer(mock -> new GridMetricManager(kernalCtx));
    when(kernalCtx.performanceStatistics()).thenAnswer(mock -> new PerformanceStatisticsProcessor(kernalCtx));
    when(sctx.kernalContext()).thenReturn(kernalCtx);
    when(sctx.gridEvents()).thenAnswer(invocationOnMock -> new GridEventStorageManager(kernalCtx));
    DataRegionConfiguration regCfg = cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration();
    DataRegionMetricsImpl memMetrics = new DataRegionMetricsImpl(regCfg, kernalCtx);
    long[] sizes = prepareSegmentSizes(regCfg.getMaxSize());
    DirectMemoryProvider provider = new UnsafeMemoryProvider(log);
    IgniteOutClosure<CheckpointProgress> clo = () -> Mockito.mock(CheckpointProgressImpl.class);
    PageMemoryImpl memory = new PageMemoryImpl(provider, sizes, sctx, sctx.pageStore(), pageSize, pageWriter, null, () -> true, memMetrics, PageMemoryImpl.ThrottlingPolicy.DISABLED, clo);
    memory.start();
    return memory;
}
Also used : GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) PerformanceStatisticsProcessor(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) 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) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with IgniteCacheDatabaseSharedManager

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

the class IgniteMetaStorageBasicTest method loadKeys.

/**
 */
private void loadKeys(IgniteEx ig, byte keysCnt, String keyPrefix, String newValPrefix, String updatedValPrefix) throws IgniteCheckedException {
    IgniteCacheDatabaseSharedManager db = ig.context().cache().context().database();
    MetaStorage metaStorage = db.metaStorage();
    db.checkpointReadLock();
    try {
        for (byte i = 0; i < keysCnt; i++) metaStorage.write(keyPrefix + i, newValPrefix + i);
        for (byte i = 0; i < keysCnt; i++) metaStorage.write(keyPrefix + i, updatedValPrefix + i);
    } finally {
        db.checkpointReadUnlock();
    }
}
Also used : IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 45 with IgniteCacheDatabaseSharedManager

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

the class IgniteMetaStorageBasicTest method testMetaStorageMigration.

/**
 * Testing data migration between metastorage partitions
 */
@Test
public void testMetaStorageMigration() throws Exception {
    final Map<String, byte[]> testData = new HashMap<>(5_000);
    generateTestData(5_000, -1).forEach(t -> testData.put(t.get1(), t.get2()));
    MetaStorage.PRESERVE_LEGACY_METASTORAGE_PARTITION_ID = true;
    try {
        IgniteEx ig = startGrid(0);
        ig.cluster().active(true);
        IgniteCacheDatabaseSharedManager db = ig.context().cache().context().database();
        MetaStorage metaStorage = db.metaStorage();
        assertNotNull(metaStorage);
        db.checkpointReadLock();
        try {
            for (Map.Entry<String, byte[]> v : testData.entrySet()) metaStorage.write(v.getKey(), v.getValue());
        } finally {
            db.checkpointReadUnlock();
        }
        stopGrid(0);
        MetaStorage.PRESERVE_LEGACY_METASTORAGE_PARTITION_ID = false;
        ig = startGrid(0);
        ig.cluster().active(true);
        db = ig.context().cache().context().database();
        metaStorage = db.metaStorage();
        assertNotNull(metaStorage);
        db.checkpointReadLock();
        try {
            Collection<IgniteBiTuple<String, byte[]>> read = readTestData(testData, metaStorage);
            int cnt = 0;
            for (IgniteBiTuple<String, byte[]> r : read) {
                byte[] test = testData.get(r.get1());
                Assert.assertArrayEquals(r.get2(), test);
                cnt++;
            }
            assertEquals(cnt, testData.size());
        } finally {
            db.checkpointReadUnlock();
        }
    } finally {
        MetaStorage.PRESERVE_LEGACY_METASTORAGE_PARTITION_ID = false;
    }
}
Also used : HashMap(java.util.HashMap) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteEx(org.apache.ignite.internal.IgniteEx) HashMap(java.util.HashMap) Map(java.util.Map) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) 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