use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalDeletionArchiveAbstractTest method testCheckpointHistoryRemovingByTruncate.
/**
* Test for check deprecated removing checkpoint by deprecated walHistorySize parameter
*
* @deprecated Test old removing process depends on WalHistorySize.
*/
@Test
public void testCheckpointHistoryRemovingByTruncate() throws Exception {
Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(2 * 1024 * 1024));
GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
CheckpointHistory hist = dbMgr.checkpointHistory();
assertNotNull(hist);
int startHistSize = hist.checkpoints().size();
int checkpointCnt = 10;
for (int i = 0; i < checkpointCnt; i++) {
cache.put(i, i);
// and: wait for checkpoint finished
forceCheckpoint();
// Check that the history is growing.
assertEquals(startHistSize + (i + 1), hist.checkpoints().size());
}
// Ensure rollover and wal archive cleaning.
for (int i = 0; i < 6; i++) cache.put(i, new byte[ignite.configuration().getDataStorageConfiguration().getWalSegmentSize() / 2]);
FileWriteAheadLogManager wal = wal(ignite);
assertTrue(waitForCondition(() -> wal.lastTruncatedSegment() >= 0, 10_000));
assertTrue(hist.checkpoints().size() < checkpointCnt + startHistSize);
File[] cpFiles = dbMgr.checkpointDirectory().listFiles();
// starts & ends + node_start
assertTrue(cpFiles.length <= (checkpointCnt * 2 + 1));
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalDeletionArchiveAbstractTest method testCheckpointStarted_WhenWalHasTooBigSizeWithoutCheckpoint.
/**
* Checkpoint triggered depends on wal size.
*/
@Test
public void testCheckpointStarted_WhenWalHasTooBigSizeWithoutCheckpoint() throws Exception {
// given: configured grid with max wal archive size = 1MB, wal segment size = 512KB
Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(1024 * 1024));
GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
for (int i = 0; i < 500; i++) cache.put(i, i);
// then: checkpoint triggered by size limit of wall without checkpoint
Checkpointer checkpointer = dbMgr.getCheckpointer();
String checkpointReason = U.field((Object) U.field(checkpointer, "curCpProgress"), "reason");
assertEquals("too big size of WAL without checkpoint", checkpointReason);
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method testHistoricalRebalanceIterator.
/**
* @throws Exception if failed.
*/
@Test
public void testHistoricalRebalanceIterator() throws Exception {
System.setProperty(IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0");
extraCcfg = new CacheConfiguration(CACHE_NAME + "2");
extraCcfg.setAffinity(new RendezvousAffinityFunction(false, PARTS));
Ignite ignite = startGrid();
try {
ignite.cluster().active(true);
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ((IgniteEx) ignite).context().cache().context().database();
dbMgr.waitForCheckpoint("test");
// This number depends on wal history size.
int entries = 25;
IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);
IgniteCache<Integer, Integer> cache2 = ignite.cache(CACHE_NAME + "2");
for (int i = 0; i < entries; i++) {
// Put to partition 0.
cache.put(i * PARTS, i * PARTS);
// Put to partition 1.
cache.put(i * PARTS + 1, i * PARTS + 1);
// Put to another cache.
cache2.put(i, i);
dbMgr.waitForCheckpoint("test");
}
for (int i = 0; i < entries; i++) {
assertEquals((Integer) (i * PARTS), cache.get(i * PARTS));
assertEquals((Integer) (i * PARTS + 1), cache.get(i * PARTS + 1));
assertEquals((Integer) (i), cache2.get(i));
}
CacheGroupContext grp = ((IgniteEx) ignite).context().cache().cacheGroup(CU.cacheId(CACHE_NAME));
IgniteCacheOffheapManager offh = grp.offheap();
AffinityTopologyVersion topVer = grp.affinity().lastVersion();
IgniteDhtDemandedPartitionsMap map;
for (int i = 0; i < entries; i++) {
map = new IgniteDhtDemandedPartitionsMap();
map.addHistorical(0, i, entries, PARTS);
WALPointer ptr = reserveWalPointerForIterator(grp.shared());
try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
assertNotNull(it);
assertTrue("Not historical for iteration: " + i, it.historical(0));
for (int j = i; j < entries; j++) {
assertTrue("i=" + i + ", j=" + j, it.hasNextX());
CacheDataRow row = it.next();
assertEquals(j * PARTS, (int) row.key().value(grp.cacheObjectContext(), false));
assertEquals(j * PARTS, (int) row.value().value(grp.cacheObjectContext(), false));
}
assertFalse(it.hasNext());
} finally {
releaseWalPointerForIterator(grp.shared(), ptr);
}
map = new IgniteDhtDemandedPartitionsMap();
map.addHistorical(1, i, entries, PARTS);
ptr = reserveWalPointerForIterator(grp.shared());
try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
assertNotNull(it);
assertTrue("Not historical for iteration: " + i, it.historical(1));
for (int j = i; j < entries; j++) {
assertTrue(it.hasNextX());
CacheDataRow row = it.next();
assertEquals(j * PARTS + 1, (int) row.key().value(grp.cacheObjectContext(), false));
assertEquals(j * PARTS + 1, (int) row.value().value(grp.cacheObjectContext(), false));
}
assertFalse(it.hasNext());
} finally {
releaseWalPointerForIterator(grp.shared(), ptr);
}
}
stopAllGrids();
// Check that iterator is valid after restart.
ignite = startGrid();
ignite.cluster().active(true);
grp = ((IgniteEx) ignite).context().cache().cacheGroup(CU.cacheId(CACHE_NAME));
offh = grp.offheap();
topVer = grp.affinity().lastVersion();
for (int i = 0; i < entries; i++) {
long start = System.currentTimeMillis();
map = new IgniteDhtDemandedPartitionsMap();
map.addHistorical(0, i, entries, PARTS);
WALPointer ptr = reserveWalPointerForIterator(grp.shared());
try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
long end = System.currentTimeMillis();
info("Time to get iterator: " + (end - start));
assertTrue("Not historical for iteration: " + i, it.historical(0));
assertNotNull(it);
start = System.currentTimeMillis();
for (int j = i; j < entries; j++) {
assertTrue("i=" + i + ", j=" + j, it.hasNextX());
CacheDataRow row = it.next();
assertEquals(j * PARTS, (int) row.key().value(grp.cacheObjectContext(), false));
assertEquals(j * PARTS, (int) row.value().value(grp.cacheObjectContext(), false));
}
end = System.currentTimeMillis();
info("Time to iterate: " + (end - start));
assertFalse(it.hasNext());
} finally {
releaseWalPointerForIterator(grp.shared(), ptr);
}
map = new IgniteDhtDemandedPartitionsMap();
map.addHistorical(1, i, entries, PARTS);
ptr = reserveWalPointerForIterator(grp.shared());
try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
assertNotNull(it);
assertTrue("Not historical for iteration: " + i, it.historical(1));
for (int j = i; j < entries; j++) {
assertTrue(it.hasNextX());
CacheDataRow row = it.next();
assertEquals(j * PARTS + 1, (int) row.key().value(grp.cacheObjectContext(), false));
assertEquals(j * PARTS + 1, (int) row.value().value(grp.cacheObjectContext(), false));
}
assertFalse(it.hasNext());
} finally {
releaseWalPointerForIterator(grp.shared(), ptr);
}
}
} finally {
stopAllGrids();
System.clearProperty(IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method testWalTxSimple.
/**
* @throws Exception If failed.
*/
@Test
public void testWalTxSimple() throws Exception {
Ignite ignite = startGrid();
ignite.cluster().active(true);
try {
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ((IgniteEx) ignite).context().cache().context().database();
dbMgr.enableCheckpoints(false).get();
IgniteCache<Integer, IndexedValue> cache = ignite.cache(CACHE_NAME);
int txCnt = 100;
int keysPerTx = 10;
for (int i = 0; i < txCnt; i++) {
try (Transaction tx = ignite.transactions().txStart()) {
for (int j = 0; j < keysPerTx; j++) {
int k = i * keysPerTx + j;
cache.put(k, new IndexedValue(k));
}
tx.commit();
}
}
for (int i = 0; i < txCnt; i++) {
for (int j = 0; j < keysPerTx; j++) {
int k = i * keysPerTx + j;
assertEquals(k, cache.get(k).value());
}
}
stopGrid();
ignite = startGrid();
ignite.cluster().active(true);
cache = ignite.cache(CACHE_NAME);
for (int i = 0; i < txCnt; i++) {
for (int j = 0; j < keysPerTx; j++) {
int k = i * keysPerTx + j;
assertEquals(k, cache.get(k).value());
}
}
for (int i = 0; i < txCnt; i++) {
for (int j = 0; j < keysPerTx; j++) {
int k = i * keysPerTx + j;
QueryCursor<List<?>> cur = cache.query(new SqlFieldsQuery("select sVal from IndexedValue where iVal=?").setArgs(k));
List<List<?>> vals = cur.getAll();
assertEquals(vals.size(), 1);
assertEquals("string-" + k, vals.get(0).get(0));
}
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method testWalAfterPreloading.
/**
* @throws Exception If failed.
*/
@Test
public void testWalAfterPreloading() throws Exception {
Ignite ignite = startGrid();
ignite.cluster().active(true);
try {
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ((IgniteEx) ignite).context().cache().context().database();
dbMgr.enableCheckpoints(false).get();
int entries = 100;
try (IgniteDataStreamer<Integer, Integer> streamer = ignite.dataStreamer(CACHE_NAME)) {
for (int i = 0; i < entries; i++) streamer.addData(i, i);
}
IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);
for (int i = 0; i < entries; i++) assertEquals(new Integer(i), cache.get(i));
stopGrid();
ignite = startGrid();
ignite.cluster().active(true);
cache = ignite.cache(CACHE_NAME);
for (int i = 0; i < entries; i++) assertEquals(new Integer(i), cache.get(i));
} finally {
stopAllGrids();
}
}
Aggregations