use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class MasterKeyChangeTest method testRecoveryFromWalWithCacheOperations.
/**
* @throws Exception If failed.
*/
@Test
public void testRecoveryFromWalWithCacheOperations() throws Exception {
// 1. Start two nodes.
T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
IgniteEx grid0 = grids.get1();
grid0.cluster().active(true);
CacheConfiguration<Long, String> ccfg = new CacheConfiguration<Long, String>(cacheName()).setWriteSynchronizationMode(FULL_SYNC).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setEncryptionEnabled(true);
// 2. Create cache.
IgniteCache<Long, String> cache1 = grids.get2().createCache(ccfg);
assertEquals(DEFAULT_MASTER_KEY_NAME, grid0.encryption().getMasterKeyName());
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) grid0.context().cache().context().database();
// 3. Prevent checkpoints to recovery from WAL.
dbMgr.enableCheckpoints(false).get();
AtomicLong cnt = new AtomicLong();
AtomicBoolean stop = new AtomicBoolean();
// 4. Run cache operations.
IgniteInternalFuture loadFut = runAsync(() -> {
while (!stop.get()) {
try (Transaction tx = grids.get2().transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
cache1.put(cnt.get(), String.valueOf(cnt.get()));
tx.commit();
cnt.incrementAndGet();
}
}
});
// Put some data before master key change.
waitForCondition(() -> cnt.get() >= 20, 10_000);
// 5. Change master key.
grid0.encryption().changeMasterKey(MASTER_KEY_NAME_2).get();
MetaStorage metaStorage = grid0.context().cache().context().database().metaStorage();
DynamicCacheDescriptor desc = grid0.context().cache().cacheDescriptor(cacheName());
Serializable oldKey = metaStorage.read(ENCRYPTION_KEYS_PREFIX + desc.groupId());
assertNotNull(oldKey);
dbMgr.checkpointReadLock();
// 6. Simulate group key write error to MetaStore for one node to check recovery from WAL.
metaStorage.write(ENCRYPTION_KEYS_PREFIX + desc.groupId(), new byte[0]);
dbMgr.checkpointReadUnlock();
// Put some data after master key change.
long oldCnt = cnt.get();
waitForCondition(() -> cnt.get() >= oldCnt + 20, 10_000);
stop.set(true);
loadFut.get();
// 7. Restart node.
stopGrid(GRID_0, true);
IgniteEx grid = startGrid(GRID_0);
grid(GRID_1).resetLostPartitions(Collections.singleton(ENCRYPTED_CACHE));
// 8. Check that restarted node recoveries keys from WAL. Check data.
assertEquals(MASTER_KEY_NAME_2, grid(GRID_0).encryption().getMasterKeyName());
assertEquals(MASTER_KEY_NAME_2, grid(GRID_1).encryption().getMasterKeyName());
IgniteCache<Long, String> cache0 = grid.cache(cacheName());
for (long i = 0; i < cnt.get(); i++) {
assertEquals(String.valueOf(i), cache0.get(i));
assertEquals(String.valueOf(i), cache1.get(i));
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method reserveWalPointerForIterator.
/**
* Reserves a WAL pointer for historical iterator.
*
* @param cctx Cache shared context.
* @return WAL pointer.
*/
private WALPointer reserveWalPointerForIterator(GridCacheSharedContext cctx) {
final CheckpointHistory cpHist = ((GridCacheDatabaseSharedManager) cctx.database()).checkpointHistory();
WALPointer oldestPtr = cpHist.firstCheckpointPointer();
AtomicReference<WALPointer> preloading = getFieldValue(cctx.database(), "reservedForPreloading");
preloading.set(oldestPtr);
cctx.wal().reserve(oldestPtr);
return oldestPtr;
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method recoveryNoPageLost.
/**
* @param checkpoint Checkpoint enable flag.
* @throws Exception If failed.
*/
private void recoveryNoPageLost(boolean checkpoint) throws Exception {
try {
pageSize = 1024;
extraCcfg = new CacheConfiguration(CACHE2_NAME);
extraCcfg.setAffinity(new RendezvousAffinityFunction(false, 32));
List<Integer> pages = null;
AtomicInteger cnt = new AtomicInteger();
for (int iter = 0; iter < 5; iter++) {
log.info("Start node: " + iter);
Ignite ignite = startGrid(0);
ignite.cluster().active(true);
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ((IgniteEx) ignite).context().cache().context().database();
if (!checkpoint)
dbMgr.enableCheckpoints(false).get();
if (pages != null) {
List<Integer> curPags = allocatedPages(ignite, CACHE2_NAME);
assertEquals(pages, curPags);
}
IgniteCache<Integer, Object> cache = ignite.cache(CACHE2_NAME);
for (int i = 0; i < 128; i++) cache.put(cnt.incrementAndGet(), new byte[256 + iter * 100]);
pages = allocatedPages(ignite, CACHE2_NAME);
stopGrid(0, true);
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalDeletionArchiveAbstractTest method testCorrectDeletedCheckpointHistoryButKeepWalFiles.
/**
* Correct delete checkpoint history from memory depends on IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE.
* WAL files doesn't delete because deleting was disabled.
*/
@Test
@WithSystemProperty(key = IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE, value = "2")
public void testCorrectDeletedCheckpointHistoryButKeepWalFiles() throws Exception {
// given: configured grid with disabled WAL removing.
Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(DataStorageConfiguration.UNLIMITED_WAL_ARCHIVE));
GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
CheckpointHistory hist = dbMgr.checkpointHistory();
assertNotNull(hist);
IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
// when: put to cache
for (int i = 0; i < 500; i++) {
cache.put(i, i);
if (i % 10 == 0)
forceCheckpoint();
}
forceCheckpoint();
// then: WAL files was not deleted but some of checkpoint history was deleted.
FileWriteAheadLogManager wal = wal(ignite);
assertNull(getFieldValueHierarchy(wal, "cleaner"));
FileDescriptor[] files = wal.walArchiveFiles();
assertTrue(Stream.of(files).anyMatch(desc -> desc.file().getName().endsWith("0001.wal")));
assertTrue(hist.checkpoints().size() == 2);
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalDeletionArchiveAbstractTest method testCorrectDeletedArchivedWalFiles.
/**
* Correct delete archived wal files.
*/
@Test
public void testCorrectDeletedArchivedWalFiles() throws Exception {
// given: configured grid with setted max wal archive size
long maxWalArchiveSize = 2 * 1024 * 1024;
Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(maxWalArchiveSize));
GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
CheckpointHistory hist = dbMgr.checkpointHistory();
assertNotNull(hist);
IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
// when: put to cache more than 2 MB
for (int i = 0; i < 500; i++) {
if (i % 100 == 0)
forceCheckpoint();
cache.put(i, i);
}
// then: total archive size less than of maxWalArchiveSize(by current logic)
FileWriteAheadLogManager wal = wal(ignite);
assertTrue(waitForCondition(() -> wal.lastTruncatedSegment() >= 0, 10_000));
FileDescriptor[] files = wal.walArchiveFiles();
long totalSize = wal.totalSize(files);
assertTrue(files.length >= 1);
assertTrue(totalSize < maxWalArchiveSize);
assertFalse(Stream.of(files).anyMatch(desc -> desc.file().getName().endsWith("00001.wal")));
assertTrue(!hist.checkpoints().isEmpty());
}
Aggregations