Search in sources :

Example 11 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class MigrationTestUtils method changeVersionNumber.

public static void changeVersionNumber(FileSystemAbstraction fileSystem, File storeFile, String versionString) throws IOException {
    byte[] versionBytes = UTF8.encode(versionString);
    try (StoreChannel fileChannel = fileSystem.open(storeFile, "rw")) {
        fileChannel.position(fileSystem.getFileSize(storeFile) - versionBytes.length);
        fileChannel.write(ByteBuffer.wrap(versionBytes));
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel)

Example 12 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class DumpLogicalLog method dump.

public void dump(String filenameOrDirectory, PrintStream out, Predicate<LogEntry[]> filter, Function<LogEntry, String> serializer) throws IOException {
    File file = new File(filenameOrDirectory);
    printFile(file, out);
    File firstFile;
    LogVersionBridge bridge;
    if (file.isDirectory()) {
        // Use natural log version bridging if a directory is supplied
        final PhysicalLogFiles logFiles = new PhysicalLogFiles(file, fileSystem);
        bridge = new ReaderLogVersionBridge(fileSystem, logFiles) {

            @Override
            public LogVersionedStoreChannel next(LogVersionedStoreChannel channel) throws IOException {
                LogVersionedStoreChannel next = super.next(channel);
                if (next != channel) {
                    printFile(logFiles.getLogFileForVersion(next.getVersion()), out);
                }
                return next;
            }
        };
        firstFile = logFiles.getLogFileForVersion(logFiles.getLowestLogVersion());
    } else {
        // Use no bridging, simple reading this single log file if a file is supplied
        firstFile = file;
        bridge = NO_MORE_CHANNELS;
    }
    StoreChannel fileChannel = fileSystem.open(firstFile, "r");
    ByteBuffer buffer = ByteBuffer.allocateDirect(LOG_HEADER_SIZE);
    LogHeader logHeader;
    try {
        logHeader = readLogHeader(buffer, fileChannel, false, firstFile);
    } catch (IOException ex) {
        out.println("Unable to read timestamp information, no records in logical log.");
        out.println(ex.getMessage());
        fileChannel.close();
        throw ex;
    }
    out.println("Logical log format: " + logHeader.logFormatVersion + " version: " + logHeader.logVersion + " with prev committed tx[" + logHeader.lastCommittedTxId + "]");
    PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(fileChannel, logHeader.logVersion, logHeader.logFormatVersion);
    ReadableClosablePositionAwareChannel logChannel = new ReadAheadLogChannel(channel, bridge, DEFAULT_READ_AHEAD_SIZE);
    LogEntryReader<ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader<>();
    IOCursor<LogEntry> entryCursor = new LogEntryCursor(entryReader, logChannel);
    TransactionLogEntryCursor transactionCursor = new TransactionLogEntryCursor(entryCursor);
    try (IOCursor<LogEntry[]> cursor = filter == null ? transactionCursor : new FilteringIOCursor<>(transactionCursor, filter)) {
        while (cursor.next()) {
            for (LogEntry entry : cursor.get()) {
                out.println(serializer.apply(entry));
            }
        }
    }
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) ReaderLogVersionBridge(org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge) LogVersionBridge(org.neo4j.kernel.impl.transaction.log.LogVersionBridge) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) TransactionLogEntryCursor(org.neo4j.kernel.impl.transaction.log.TransactionLogEntryCursor) TransactionLogEntryCursor(org.neo4j.kernel.impl.transaction.log.TransactionLogEntryCursor) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) ReaderLogVersionBridge(org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) File(java.io.File) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 13 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class RsdrMain method readStore.

private static void readStore(FileSystemAbstraction fileSystem, RecordStore store, long fromId, long toId, Pattern pattern) throws IOException {
    toId = Math.min(toId, store.getHighId());
    try (StoreChannel channel = fileSystem.open(store.getStorageFileName(), "r")) {
        int recordSize = store.getRecordSize();
        ByteBuffer buf = ByteBuffer.allocate(recordSize);
        for (long i = fromId; i <= toId; i++) {
            buf.clear();
            long offset = recordSize * i;
            int count = channel.read(buf, offset);
            if (count == -1) {
                break;
            }
            byte[] bytes = new byte[count];
            buf.clear();
            buf.get(bytes);
            String hex = DatatypeConverter.printHexBinary(bytes);
            int paddingNeeded = (recordSize * 2 - Math.max(count * 2, 0)) + 1;
            String format = "%s %6s 0x%08X %s%" + paddingNeeded + "s%s%n";
            String str;
            String use;
            try {
                AbstractBaseRecord record = RecordStore.getRecord(store, i, CHECK);
                use = record.inUse() ? "+" : "-";
                str = record.toString();
            } catch (InvalidRecordException e) {
                str = new String(bytes, 0, count, "ASCII");
                use = "?";
            }
            if (pattern == null || pattern.matcher(str).find()) {
                console.printf(format, use, i, offset, hex, " ", str);
            }
        }
    }
}
Also used : AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) ByteBuffer(java.nio.ByteBuffer) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException)

Example 14 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class RsdrMain method getLogCursor.

private static IOCursor<LogEntry> getLogCursor(FileSystemAbstraction fileSystem, String fname, NeoStores neoStores) throws IOException {
    File file = new File(neoStores.getStoreDir(), fname);
    StoreChannel fileChannel = fileSystem.open(file, "r");
    LogHeader logHeader = readLogHeader(ByteBuffer.allocateDirect(LOG_HEADER_SIZE), fileChannel, false, file);
    console.printf("Logical log version: %s with prev committed tx[%s]%n", logHeader.logVersion, logHeader.lastCommittedTxId);
    PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(fileChannel, logHeader.logVersion, logHeader.logFormatVersion);
    ReadableLogChannel logChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    return new LogEntryCursor(logEntryReader, logChannel);
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) File(java.io.File) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 15 with StoreChannel

use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.

the class RecoveryProtocol method writeHeader.

private static void writeHeader(FileSystemAbstraction fileSystem, File file, SegmentHeader header) throws IOException {
    try (StoreChannel channel = fileSystem.open(file, "rw")) {
        channel.position(0);
        PhysicalFlushableChannel writer = new PhysicalFlushableChannel(channel, SegmentHeader.SIZE);
        headerMarshal.marshal(header, writer);
        writer.prepareForFlush().flush();
    }
}
Also used : PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) StoreChannel(org.neo4j.io.fs.StoreChannel)

Aggregations

StoreChannel (org.neo4j.io.fs.StoreChannel)173 ByteBuffer (java.nio.ByteBuffer)65 Test (org.junit.jupiter.api.Test)52 Path (java.nio.file.Path)50 File (java.io.File)44 Test (org.junit.Test)42 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)26 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)25 IOException (java.io.IOException)24 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)13 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)13 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)13 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)13 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)11 InputStream (java.io.InputStream)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)8 HeapScopedBuffer (org.neo4j.io.memory.HeapScopedBuffer)8 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)8 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)8