Search in sources :

Example 11 with WALIterator

use of org.apache.ignite.internal.pagemem.wal.WALIterator in project ignite by apache.

the class IgniteWalConverter method main.

/**
 * @param args Args.
 */
public static void main(String[] args) throws Exception {
    if (args.length < 2)
        throw new IllegalArgumentException("\nYou need to provide:\n" + "\t1. Size of pages, which was selected for file store (1024, 2048, 4096, etc).\n" + "\t2. Path to dir with wal files.\n" + "\t3. (Optional) Path to dir with archive wal files.");
    PageIO.registerH2(H2InnerIO.VERSIONS, H2LeafIO.VERSIONS);
    H2ExtrasInnerIO.register();
    H2ExtrasLeafIO.register();
    boolean printRecords = IgniteSystemProperties.getBoolean("PRINT_RECORDS", false);
    boolean printStat = IgniteSystemProperties.getBoolean("PRINT_STAT", true);
    final IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(new NullLogger(), Integer.parseInt(args[0]), null, null, false);
    final File walWorkDirWithConsistentId = new File(args[1]);
    final File[] workFiles = walWorkDirWithConsistentId.listFiles(FileWriteAheadLogManager.WAL_SEGMENT_FILE_FILTER);
    if (workFiles == null)
        throw new IllegalArgumentException("No .wal files in dir: " + args[1]);
    @Nullable final WalStat stat = printStat ? new WalStat() : null;
    try (WALIterator stIt = factory.iteratorWorkFiles(workFiles)) {
        while (stIt.hasNextX()) {
            IgniteBiTuple<WALPointer, WALRecord> next = stIt.nextX();
            final WALPointer pointer = next.get1();
            final WALRecord record = next.get2();
            if (stat != null)
                stat.registerRecord(record, pointer, true);
            if (printRecords)
                System.out.println("[W] " + record);
        }
    }
    if (args.length >= 3) {
        final File walArchiveDirWithConsistentId = new File(args[2]);
        try (WALIterator stIt = factory.iteratorArchiveDirectory(walArchiveDirWithConsistentId)) {
            while (stIt.hasNextX()) {
                IgniteBiTuple<WALPointer, WALRecord> next = stIt.nextX();
                final WALPointer pointer = next.get1();
                final WALRecord record = next.get2();
                if (stat != null)
                    stat.registerRecord(record, pointer, false);
                if (printRecords)
                    System.out.println("[A] " + record);
            }
        }
    }
    System.err.flush();
    if (stat != null)
        System.out.println("Statistic collected:\n" + stat.toString());
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) NullLogger(org.apache.ignite.logger.NullLogger) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) File(java.io.File) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)11 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)8 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)8 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)5 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)5 File (java.io.File)4 HashMap (java.util.HashMap)4 PageDeltaRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord)4 ByteBuffer (java.nio.ByteBuffer)3 MemoryRecoveryRecord (org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord)3 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)3 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)3 FileWALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)3 Nullable (org.jetbrains.annotations.Nullable)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2