Search in sources :

Example 16 with CheckpointRecord

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");
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) FixCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteLogger(org.apache.ignite.IgniteLogger) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) T2(org.apache.ignite.internal.util.typedef.T2) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with CheckpointRecord

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 ["));
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) FixCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) ScannerHandlers.printToFile(org.apache.ignite.internal.processors.cache.persistence.wal.scanner.ScannerHandlers.printToFile) File(java.io.File) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) T2(org.apache.ignite.internal.util.typedef.T2) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with CheckpointRecord

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());
    }
}
Also used : DataPageInsertFragmentRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) NewRootInitRecord(org.apache.ignite.internal.pagemem.wal.record.delta.NewRootInitRecord) DataPageInsertRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord) InsertRecord(org.apache.ignite.internal.pagemem.wal.record.delta.InsertRecord) DataPageUpdateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) MetaPageUpdatePartitionDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord) DataPageInsertRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord) ReplaceRecord(org.apache.ignite.internal.pagemem.wal.record.delta.ReplaceRecord) InnerReplaceRecord(org.apache.ignite.internal.pagemem.wal.record.delta.InnerReplaceRecord) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)

Example 19 with CheckpointRecord

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);
    }
}
Also used : DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) HeaderRecord(org.apache.ignite.internal.processors.cache.persistence.wal.record.HeaderRecord) ExchangeRecord(org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) SnapshotRecord(org.apache.ignite.internal.pagemem.wal.record.SnapshotRecord) UUID(java.util.UUID)

Example 20 with CheckpointRecord

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);
    }
}
Also used : FileWALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer) ArrayList(java.util.ArrayList) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) CacheState(org.apache.ignite.internal.pagemem.wal.record.CacheState) SnapshotRecord(org.apache.ignite.internal.pagemem.wal.record.SnapshotRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) ExchangeRecord(org.apache.ignite.internal.pagemem.wal.record.ExchangeRecord) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) UUID(java.util.UUID)

Aggregations

CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)34 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)24 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)19 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)18 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)16 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)15 UUID (java.util.UUID)13 ArrayList (java.util.ArrayList)12 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)12 Test (org.junit.Test)11 ByteBuffer (java.nio.ByteBuffer)10 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)10 IgniteEx (org.apache.ignite.internal.IgniteEx)9 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)9 PartitionMetaStateRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord)9 HashSet (java.util.HashSet)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 CacheState (org.apache.ignite.internal.pagemem.wal.record.CacheState)7 FixCountRecord (org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord)6