use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgniteWalRecoveryTest method testAbsentDeadlock_Iterator_RollOver_Archivation.
/**
* @throws Exception if failed.
*/
@Test
public void testAbsentDeadlock_Iterator_RollOver_Archivation() throws Exception {
walSegments = 2;
walSegmentSize = 512 * 1024;
IgniteEx ignite0 = (IgniteEx) startGrid("node0");
ignite0.active(true);
IgniteCache<Object, Object> cache0 = ignite0.cache(CACHE_NAME);
for (int i = 0; i < 100; i++) cache0.put(i, new IndexedObject(i));
GridCacheSharedContext<Object, Object> sharedCtx = ignite0.context().cache().context();
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
db.waitForCheckpoint("test");
db.enableCheckpoints(false).get();
// Log something to know where to start.
WALPointer ptr = sharedCtx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis()));
info("Replay marker: " + ptr);
for (int i = 100; i < 200; i++) cache0.put(i, new IndexedObject(i));
CountDownLatch insertFinished = new CountDownLatch(1);
GridTestUtils.runAsync(() -> {
try (WALIterator it = sharedCtx.wal().replay(ptr)) {
if (it.hasNext()) {
it.next();
insertFinished.await();
}
}
return null;
});
IgniteInternalFuture<Object> future = GridTestUtils.runAsync(() -> {
for (int i = 0; i < 10000; i++) cache0.put(i, new IndexedObject(i));
return null;
});
future.get();
insertFinished.countDown();
ignite0.close();
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgniteWalRecoveryTest method testTxRecordsConsistency.
/**
* Test that all DataRecord WAL records are within transaction boundaries - PREPARED and COMMITTED markers.
*
* @throws Exception If any fail.
*/
@Test
public void testTxRecordsConsistency() throws Exception {
IgniteEx ignite = startGrids(3);
ignite.cluster().state(ClusterState.ACTIVE);
final String cacheName = "transactional";
CacheConfiguration<Object, Object> cacheConfiguration = new CacheConfiguration<>(cacheName).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setAffinity(new RendezvousAffinityFunction(false, 32)).setCacheMode(CacheMode.PARTITIONED).setRebalanceMode(CacheRebalanceMode.SYNC).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(0);
ignite.createCache(cacheConfiguration);
IgniteCache<Object, Object> cache = ignite.cache(cacheName);
GridCacheSharedContext<Object, Object> sharedCtx = ignite.context().cache().context();
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
db.waitForCheckpoint("test");
db.enableCheckpoints(false).get();
// Log something to know where to start.
WALPointer startPtr = sharedCtx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis()));
final int transactions = 100;
final int operationsPerTransaction = 40;
Random random = new Random();
for (int t = 1; t <= transactions; t++) {
Transaction tx = ignite.transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.READ_COMMITTED);
for (int op = 0; op < operationsPerTransaction; op++) {
int key = random.nextInt(1000) + 1;
Object value = random.nextBoolean() ? randomString(random) + key : new BigObject(key);
cache.put(key, value);
}
if (random.nextBoolean())
tx.commit();
else
tx.rollback();
if (t % 50 == 0)
log.info("Finished transaction " + t);
}
Set<GridCacheVersion> activeTransactions = new HashSet<>();
// Check that all DataRecords are within PREPARED and COMMITTED tx records.
try (WALIterator it = sharedCtx.wal().replay(startPtr)) {
while (it.hasNext()) {
IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
WALRecord rec = tup.get2();
if (rec instanceof TxRecord) {
TxRecord txRecord = (TxRecord) rec;
GridCacheVersion txId = txRecord.nearXidVersion();
switch(txRecord.state()) {
case PREPARED:
assert !activeTransactions.contains(txId) : "Transaction is already present " + txRecord;
activeTransactions.add(txId);
break;
case COMMITTED:
assert activeTransactions.contains(txId) : "No PREPARE marker for transaction " + txRecord;
activeTransactions.remove(txId);
break;
case ROLLED_BACK:
activeTransactions.remove(txId);
break;
default:
throw new IllegalStateException("Unknown Tx state of record " + txRecord);
}
} else if (rec instanceof DataRecord) {
DataRecord dataRecord = (DataRecord) rec;
for (int i = 0; i < dataRecord.entryCount(); i++) {
DataEntry entry = dataRecord.get(i);
GridCacheVersion txId = entry.nearXidVersion();
assert activeTransactions.contains(txId) : "No transaction for entry " + entry;
}
}
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class CleanupIndexTreeCheckpointFailoverTest method testCorruptedTree.
/**
* @throws Exception if failed.
*/
@Test
public void testCorruptedTree() throws Exception {
cleanPersistenceDir();
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
CacheConfiguration<Key, Value> cfg = new CacheConfiguration<Key, Value>().setIndexedTypes(Key.class, Value.class).setName("test");
IgniteCache<Key, Value> cache = ig.getOrCreateCache(cfg);
cache.query(new SqlFieldsQuery("create index myindex on value (a asc)")).getAll();
for (int i = 0; i < 5000; i++) cache.put(new Key(i), new Value(String.valueOf(i), "b" + i));
ig.context().cache().context().database().wakeupForCheckpoint("test").get();
cache.query(new SqlFieldsQuery("drop index myindex")).getAll();
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
U.sleep(1000);
dbMgr.enableCheckpoints(false);
stopGrid(0, true);
ig = startGrid(0);
cache = ig.cache("test");
for (int i = 0; i < 5000; i += 2) cache.remove(new Key(i));
cache.query(new SqlFieldsQuery("create index myindex on value (a asc)")).getAll();
for (int i = 0; i < 5000; i++) cache.put(new Key(i), new Value(String.valueOf(i), "b" + i));
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgniteDbSingleNodeWithIndexingWalRestoreTest method testRegularClassesRestored.
/**
* Test for regular objects stored in cache with compactFooter=true setting
* (no metainformation to deserialize values is stored with values themselves).
*/
@Test
public void testRegularClassesRestored() throws Exception {
IgniteEx ig = startGrid(0);
ig.active(true);
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
dbMgr.enableCheckpoints(false).get();
IgniteCache<Object, Object> cache = ig.cache("indexedCache");
for (int i = 0; i < ENTRIES_COUNT; i++) cache.put(i, new RegularPerson("RegularPeter" + i));
stopGrid(0, true);
ig = startGrid(0);
ig.active(true);
cache = ig.cache("indexedCache");
for (int i = 0; i < ENTRIES_COUNT; i++) assertEquals("RegularPeter" + i, ((RegularPerson) cache.get(i)).regName);
}
use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.
the class IgnitePersistentStoreSchemaLoadTest method checkpointLatch.
/**
* @param node Node whose checkpoint to wait for.
* @return Latch released when checkpoint happens.
*/
private CountDownLatch checkpointLatch(IgniteEx node) {
final CountDownLatch cnt = new CountDownLatch(1);
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) node.context().cache().context().database();
db.addCheckpointListener(new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) {
cnt.countDown();
}
@Override
public void beforeCheckpointBegin(Context ctx) throws IgniteCheckedException {
}
@Override
public void onCheckpointBegin(Context ctx) {
/* No-op. */
}
});
return cnt;
}
Aggregations