use of org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord in project ignite by apache.
the class WalScannerTest method shouldDumpToLogFoundRecord.
/**
* @throws Exception If failed.
*/
@Test
public void shouldDumpToLogFoundRecord() throws Exception {
// given: Test logger for interception of logging.
long expPageId = 984;
int grpId = 123;
IgniteLogger log = mock(IgniteLogger.class);
when(log.isInfoEnabled()).thenReturn(true);
ArgumentCaptor<String> valCapture = ArgumentCaptor.forClass(String.class);
doNothing().when(log).info(valCapture.capture());
WALIterator mockedIter = mockWalIterator(new IgniteBiTuple<>(NULL_PTR, new PageSnapshot(new FullPageId(expPageId, grpId), dummyPage(1024, expPageId), 1024)), new IgniteBiTuple<>(NULL_PTR, new CheckpointRecord(new WALPointer(5738, 0, 0))), new IgniteBiTuple<>(NULL_PTR, new FixCountRecord(grpId, expPageId, 4)));
IgniteWalIteratorFactory factory = mock(IgniteWalIteratorFactory.class);
when(factory.iterator(any(IteratorParametersBuilder.class))).thenReturn(mockedIter);
Set<T2<Integer, Long>> groupAndPageIds = new HashSet<>();
groupAndPageIds.add(new T2<>(grpId, expPageId));
// when: Scanning WAL for searching expected page.
buildWalScanner(withIteratorParameters(), factory).findAllRecordsFor(groupAndPageIds).forEach(printToLog(log));
// then: Should be find only expected value from log.
List<String> actualRecords = valCapture.getAllValues();
assertEquals(actualRecords.size(), 1);
assertRecord(actualRecords.get(0), "PageSnapshot [", "PAGE_RECORD");
assertRecord(actualRecords.get(0), "CheckpointRecord [", "CHECKPOINT_RECORD");
assertRecord(actualRecords.get(0), "FixCountRecord [", "BTREE_FIX_COUNT");
}
use of org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord in project ignite by apache.
the class WalScannerTest method shouldDumpToFileFoundRecord.
/**
* @throws Exception If failed.
*/
@Test
public void shouldDumpToFileFoundRecord() throws Exception {
// given: File for dumping records.
File targetFile = Paths.get(U.defaultWorkDirectory(), TEST_DUMP_FILE).toFile();
long expectedPageId = 984;
int grpId = 123;
WALIterator mockedIter = mockWalIterator(new IgniteBiTuple<>(NULL_PTR, new PageSnapshot(new FullPageId(expectedPageId, grpId), dummyPage(1024, expectedPageId), 1024)), new IgniteBiTuple<>(NULL_PTR, new CheckpointRecord(new WALPointer(5738, 0, 0))), new IgniteBiTuple<>(NULL_PTR, new FixCountRecord(grpId, expectedPageId, 4)));
IgniteWalIteratorFactory factory = mock(IgniteWalIteratorFactory.class);
when(factory.iterator(any(IteratorParametersBuilder.class))).thenReturn(mockedIter);
Set<T2<Integer, Long>> groupAndPageIds = new HashSet<>();
groupAndPageIds.add(new T2<>(grpId, expectedPageId));
List<String> actualRecords;
try {
// when: Scanning WAL for searching expected page.
buildWalScanner(withIteratorParameters(), factory).findAllRecordsFor(groupAndPageIds).forEach(printToFile(targetFile));
actualRecords = Files.readAllLines(targetFile.toPath());
} finally {
targetFile.delete();
}
// then: Should be find only expected value from file. PageSnapshot string representation is 11 lines long.
assertEquals(13, actualRecords.size());
assertTrue(actualRecords.get(0), actualRecords.get(0).contains("PageSnapshot ["));
assertTrue(actualRecords.get(11), actualRecords.get(11).contains("CheckpointRecord ["));
assertTrue(actualRecords.get(12), actualRecords.get(12).contains("FixCountRecord ["));
}
use of org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord in project ignite by apache.
the class RecordDataV1Serializer method size.
/**
* {@inheritDoc}
*/
@Override
public int size(WALRecord record) throws IgniteCheckedException {
switch(record.type()) {
case PAGE_RECORD:
assert record instanceof PageSnapshot;
PageSnapshot pageRec = (PageSnapshot) record;
return pageRec.pageData().length + 12;
case CHECKPOINT_RECORD:
CheckpointRecord cpRec = (CheckpointRecord) record;
assert cpRec.checkpointMark() == null || cpRec.checkpointMark() instanceof FileWALPointer : "Invalid WAL record: " + cpRec;
int cacheStatesSize = cacheStatesSize(cpRec.cacheGroupStates());
FileWALPointer walPtr = (FileWALPointer) cpRec.checkpointMark();
return 18 + cacheStatesSize + (walPtr == null ? 0 : 16);
case META_PAGE_INIT:
return /*cache ID*/
4 + /*page ID*/
8 + /*ioType*/
2 + /*ioVer*/
2 + /*tree root*/
8 + /*reuse root*/
8;
case PARTITION_META_PAGE_UPDATE_COUNTERS:
return /*cache ID*/
4 + /*page ID*/
8 + /*upd cntr*/
8 + /*rmv id*/
8 + /*part size*/
4 + /*counters page id*/
8 + /*state*/
1 + /*allocatedIdxCandidate*/
4;
case MEMORY_RECOVERY:
return 8;
case PARTITION_DESTROY:
return /*cacheId*/
4 + /*partId*/
4;
case DATA_RECORD:
DataRecord dataRec = (DataRecord) record;
return 4 + dataSize(dataRec);
case METASTORE_DATA_RECORD:
MetastoreDataRecord metastoreDataRec = (MetastoreDataRecord) record;
return 4 + metastoreDataRec.key().getBytes().length + 4 + (metastoreDataRec.value() != null ? metastoreDataRec.value().length : 0);
case HEADER_RECORD:
return HEADER_RECORD_DATA_SIZE;
case DATA_PAGE_INSERT_RECORD:
DataPageInsertRecord diRec = (DataPageInsertRecord) record;
return 4 + 8 + 2 + diRec.payload().length;
case DATA_PAGE_UPDATE_RECORD:
DataPageUpdateRecord uRec = (DataPageUpdateRecord) record;
return 4 + 8 + 2 + 4 + uRec.payload().length;
case DATA_PAGE_INSERT_FRAGMENT_RECORD:
final DataPageInsertFragmentRecord difRec = (DataPageInsertFragmentRecord) record;
return 4 + 8 + 8 + 4 + difRec.payloadSize();
case DATA_PAGE_REMOVE_RECORD:
return 4 + 8 + 1;
case DATA_PAGE_SET_FREE_LIST_PAGE:
return 4 + 8 + 8;
case INIT_NEW_PAGE_RECORD:
return 4 + 8 + 2 + 2 + 8;
case BTREE_META_PAGE_INIT_ROOT:
return 4 + 8 + 8;
case BTREE_META_PAGE_INIT_ROOT2:
return 4 + 8 + 8 + 2;
case BTREE_META_PAGE_ADD_ROOT:
return 4 + 8 + 8;
case BTREE_META_PAGE_CUT_ROOT:
return 4 + 8;
case BTREE_INIT_NEW_ROOT:
NewRootInitRecord<?> riRec = (NewRootInitRecord<?>) record;
return 4 + 8 + 8 + 2 + 2 + 8 + 8 + riRec.io().getItemSize();
case BTREE_PAGE_RECYCLE:
return 4 + 8 + 8;
case BTREE_PAGE_INSERT:
InsertRecord<?> inRec = (InsertRecord<?>) record;
return 4 + 8 + 2 + 2 + 2 + 8 + inRec.io().getItemSize();
case BTREE_FIX_LEFTMOST_CHILD:
return 4 + 8 + 8;
case BTREE_FIX_COUNT:
return 4 + 8 + 2;
case BTREE_PAGE_REPLACE:
ReplaceRecord<?> rRec = (ReplaceRecord<?>) record;
return 4 + 8 + 2 + 2 + 2 + rRec.io().getItemSize();
case BTREE_PAGE_REMOVE:
return 4 + 8 + 2 + 2;
case BTREE_PAGE_INNER_REPLACE:
return 4 + 8 + 2 + 8 + 2 + 8;
case BTREE_FORWARD_PAGE_SPLIT:
return 4 + 8 + 8 + 2 + 2 + 8 + 2 + 2;
case BTREE_EXISTING_PAGE_SPLIT:
return 4 + 8 + 2 + 8;
case BTREE_PAGE_MERGE:
return 4 + 8 + 8 + 2 + 8 + 1;
case BTREE_FIX_REMOVE_ID:
return 4 + 8 + 8;
case PAGES_LIST_SET_NEXT:
return 4 + 8 + 8;
case PAGES_LIST_SET_PREVIOUS:
return 4 + 8 + 8;
case PAGES_LIST_INIT_NEW_PAGE:
return 4 + 8 + 4 + 4 + 8 + 8 + 8;
case PAGES_LIST_ADD_PAGE:
return 4 + 8 + 8;
case PAGES_LIST_REMOVE_PAGE:
return 4 + 8 + 8;
case TRACKING_PAGE_DELTA:
return 4 + 8 + 8 + 8 + 8;
case META_PAGE_UPDATE_LAST_SUCCESSFUL_SNAPSHOT_ID:
return 4 + 8 + 8 + 8;
case META_PAGE_UPDATE_LAST_SUCCESSFUL_FULL_SNAPSHOT_ID:
return 4 + 8 + 8;
case META_PAGE_UPDATE_NEXT_SNAPSHOT_ID:
return 4 + 8 + 8;
case META_PAGE_UPDATE_LAST_ALLOCATED_INDEX:
return 4 + 8 + 4;
case PART_META_UPDATE_STATE:
return /*cacheId*/
4 + /*partId*/
4 + /*State*/
1 + /*Update Counter*/
8;
case PAGE_LIST_META_RESET_COUNT_RECORD:
return /*cacheId*/
4 + /*pageId*/
8;
case SWITCH_SEGMENT_RECORD:
return 0;
case TX_RECORD:
return txRecordSerializer.size((TxRecord) record);
default:
throw new UnsupportedOperationException("Type: " + record.type());
}
}
use of org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord in project ignite by apache.
the class RecordDataV2Serializer method writeRecord.
/**
* {@inheritDoc}
*/
@Override
public void writeRecord(WALRecord rec, ByteBuffer buf) throws IgniteCheckedException {
if (rec instanceof HeaderRecord)
throw new UnsupportedOperationException("Writing header records is forbidden since version 2 of serializer");
switch(rec.type()) {
case CHECKPOINT_RECORD:
CheckpointRecord cpRec = (CheckpointRecord) rec;
assert cpRec.checkpointMark() == null || cpRec.checkpointMark() instanceof FileWALPointer : "Invalid WAL record: " + cpRec;
FileWALPointer walPtr = (FileWALPointer) cpRec.checkpointMark();
UUID cpId = cpRec.checkpointId();
buf.putLong(cpId.getMostSignificantBits());
buf.putLong(cpId.getLeastSignificantBits());
buf.put(walPtr == null ? (byte) 0 : 1);
if (walPtr != null) {
buf.putLong(walPtr.index());
buf.putInt(walPtr.fileOffset());
buf.putInt(walPtr.length());
}
putCacheStates(buf, cpRec.cacheGroupStates());
buf.put(cpRec.end() ? (byte) 1 : 0);
break;
case DATA_RECORD:
DataRecord dataRec = (DataRecord) rec;
buf.putInt(dataRec.writeEntries().size());
buf.putLong(dataRec.timestamp());
for (DataEntry dataEntry : dataRec.writeEntries()) RecordDataV1Serializer.putDataEntry(buf, dataEntry);
break;
case SNAPSHOT:
SnapshotRecord snpRec = (SnapshotRecord) rec;
buf.putLong(snpRec.getSnapshotId());
buf.put(snpRec.isFull() ? (byte) 1 : 0);
break;
case EXCHANGE:
ExchangeRecord r = (ExchangeRecord) rec;
buf.putInt(r.getType().ordinal());
buf.putShort(r.getConstId());
buf.putLong(r.timestamp());
break;
case TX_RECORD:
txRecordSerializer.write((TxRecord) rec, buf);
break;
case BASELINE_TOP_RECORD:
bltRecSerializer.write((BaselineTopologyRecord) rec, buf);
break;
default:
delegateSerializer.writeRecord(rec, buf);
}
}
use of org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord in project ignite by apache.
the class RecordDataV2Serializer method readRecord.
/**
* {@inheritDoc}
*/
@Override
public WALRecord readRecord(WALRecord.RecordType type, ByteBufferBackedDataInput in) throws IOException, IgniteCheckedException {
switch(type) {
case CHECKPOINT_RECORD:
long msb = in.readLong();
long lsb = in.readLong();
boolean hasPtr = in.readByte() != 0;
int idx0 = hasPtr ? in.readInt() : 0;
int off = hasPtr ? in.readInt() : 0;
int len = hasPtr ? in.readInt() : 0;
Map<Integer, CacheState> states = readPartitionStates(in);
boolean end = in.readByte() != 0;
FileWALPointer walPtr = hasPtr ? new FileWALPointer(idx0, off, len) : null;
CheckpointRecord cpRec = new CheckpointRecord(new UUID(msb, lsb), walPtr, end);
cpRec.cacheGroupStates(states);
return cpRec;
case DATA_RECORD:
int entryCnt = in.readInt();
long timeStamp = in.readLong();
List<DataEntry> entries = new ArrayList<>(entryCnt);
for (int i = 0; i < entryCnt; i++) entries.add(delegateSerializer.readDataEntry(in));
return new DataRecord(entries, timeStamp);
case SNAPSHOT:
long snpId = in.readLong();
byte full = in.readByte();
return new SnapshotRecord(snpId, full == 1);
case EXCHANGE:
int idx = in.readInt();
short constId = in.readShort();
long ts = in.readLong();
return new ExchangeRecord(constId, ExchangeRecord.Type.values()[idx], ts);
case TX_RECORD:
return txRecordSerializer.read(in);
case BASELINE_TOP_RECORD:
return bltRecSerializer.read(in);
default:
return delegateSerializer.readRecord(type, in);
}
}
Aggregations