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"));
}
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();
}
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;
}
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();
}
}
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;
}
}
Aggregations