use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.
the class IgniteWalReaderTest method testPrimaryFlagOnTwoNodes.
/**
* Tests transaction generation and WAL for putAll cache operation.
*
* @throws Exception if failed.
*/
@Test
public void testPrimaryFlagOnTwoNodes() throws Exception {
backupCnt = 1;
IgniteEx ignite = startGrid("node0");
Ignite ignite1 = startGrid(1);
ignite.cluster().state(ACTIVE);
IgniteCache<Integer, IndexedObject> cache = ignite.cache(CACHE_NAME);
backupCnt = 0;
int cntEntries = 100;
List<Integer> keys = findKeys(ignite.localNode(), cache, cntEntries, 0, 0);
Map<Integer, IndexedObject> map = new TreeMap<>();
for (Integer key : keys) map.putIfAbsent(key, new IndexedObject(key));
cache.putAll(map);
ignite.cluster().active(false);
String subfolderName1 = genDbSubfolderName(ignite, 0);
String subfolderName2 = genDbSubfolderName(ignite1, 1);
stopAllGrids();
String workDir = U.defaultWorkDirectory();
IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
Map<GridCacheOperation, Integer> operationsFound = new EnumMap<>(GridCacheOperation.class);
IgniteInClosure<DataRecord> drHnd = dataRecord -> {
for (int i = 0; i < dataRecord.entryCount(); i++) {
DataEntry entry = dataRecord.get(i);
GridCacheOperation op = entry.op();
Integer cnt = operationsFound.get(op);
operationsFound.put(op, cnt == null ? 1 : (cnt + 1));
}
};
scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName1).filesOrDirs(workDir + "/db/wal/" + subfolderName1, workDir + "/db/wal/archive/" + subfolderName1), 1, 1, null, drHnd);
primary = false;
scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName2).filesOrDirs(workDir + "/db/wal/" + subfolderName2, workDir + "/db/wal/archive/" + subfolderName2), 1, 1, null, drHnd);
}
use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.
the class IgniteWalRebalanceTest method testSwitchHistoricalRebalanceToFullWhileIteratingOverWAL.
/**
* Tests that demander switches to full rebalance if the previously chosen supplier for a group has failed
* to perform historical rebalance due to an unexpected error while iterating over reserved wal.
*
* @throws Exception If failed
*/
@Test
public void testSwitchHistoricalRebalanceToFullWhileIteratingOverWAL() throws Exception {
testSwitchHistoricalRebalanceToFull(supplier1 -> {
try {
// Corrupt wal record in order to fail historical rebalance from supplier1 node.
IgniteWriteAheadLogManager walMgr = supplier1.context().cache().context().wal();
WALPointer ptr = walMgr.log(new DataRecord(new DataEntry(CU.cacheId("test-cache-1"), new KeyCacheObjectImpl(0, null, 0), null, GridCacheOperation.DELETE, new GridCacheVersion(0, 1, 1, 0), new GridCacheVersion(0, 1, 1, 0), 0, 0, 0, DataEntry.EMPTY_FLAGS)));
File walDir = U.field(walMgr, "walWorkDir");
List<FileDescriptor> walFiles = new IgniteWalIteratorFactory().resolveWalFiles(new IgniteWalIteratorFactory.IteratorParametersBuilder().filesOrDirs(walDir));
FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
WalTestUtils.corruptWalSegmentFile(lastWalFile, ptr);
IgniteCache<Integer, IndexedObject> c1 = supplier1.cache("test-cache-1");
for (int i = 0; i < PARTS_CNT * 100; i++) c1.put(i, new IndexedObject(i + PARTS_CNT));
} catch (IgniteCheckedException | IOException e) {
throw new RuntimeException(e);
}
}, () -> true);
}
use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.
the class TxPartitionCounterStateConsistencyTest method checkWAL.
/**
* @param ig Ignite instance.
* @param ops Ops queue.
* @param exp Expected updates.
*/
private void checkWAL(IgniteEx ig, Queue<T2<Integer, GridCacheOperation>> ops, int exp) throws IgniteCheckedException {
WALIterator iter = walIterator(ig);
long cntr = 0;
while (iter.hasNext()) {
IgniteBiTuple<WALPointer, WALRecord> tup = iter.next();
if (tup.get2() instanceof DataRecord) {
T2<Integer, GridCacheOperation> op = ops.poll();
DataRecord rec = (DataRecord) tup.get2();
assertEquals(1, rec.entryCount());
DataEntry entry = rec.get(0);
assertEquals(op.get1(), entry.key().value(internalCache(ig, DEFAULT_CACHE_NAME).context().cacheObjectContext(), false));
assertEquals(op.get2(), entry.op());
assertEquals(entry.partitionCounter(), ++cntr);
}
}
assertEquals(exp, cntr);
assertTrue(ops.isEmpty());
}
use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.
the class WalStat method registerDataRecord.
/**
* @param record data record to handle.
*/
private void registerDataRecord(DataRecord record) {
int entryCnt = record.entryCount();
if (entryCnt != 0) {
boolean underTx = false;
for (int i = 0; i < entryCnt; i++) {
DataEntry next = record.get(i);
final int size = entryCnt > 1 ? -1 : record.size();
incrementStat(next.op().toString(), dataEntryOperation, size);
incrementStat(next.cacheId(), dataEntryCacheId, size);
txStat.onDataEntry(next);
underTx |= next.nearXidVersion() != null;
}
incrementStat(underTx, record, dataRecordUnderTx);
}
incrementStat(entryCnt, record, dataRecordEntriesCnt);
}
use of org.apache.ignite.internal.pagemem.wal.record.DataEntry in project ignite by apache.
the class IgniteWalConverterSensitiveDataTest method withSensitiveData.
/**
* Creating {@link WALRecord} instances with sensitive data.
*
* @return {@link WALRecord} instances with sensitive data.
*/
private Collection<WALRecord> withSensitiveData() {
List<WALRecord> walRecords = new ArrayList<>();
int cacheId = CU.cacheId(DEFAULT_CACHE_NAME);
DataEntry dataEntry = new DataEntry(cacheId, new KeyCacheObjectImpl(SENSITIVE_DATA_VALUE_PREFIX, null, 0), new CacheObjectImpl(SENSITIVE_DATA_VALUE_PREFIX, null), GridCacheOperation.CREATE, new GridCacheVersion(), new GridCacheVersion(), 0, 0, 0, DataEntry.EMPTY_FLAGS);
byte[] sensitiveDataBytes = SENSITIVE_DATA_VALUE_PREFIX.getBytes(StandardCharsets.UTF_8);
walRecords.add(new DataRecord(dataEntry));
walRecords.add(new MetastoreDataRecord(SENSITIVE_DATA_VALUE_PREFIX, sensitiveDataBytes));
return walRecords;
}
Aggregations