Search in sources :

Example 1 with ReadPastEndException

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

the class LogTruncationTest method assertHandlesLogTruncation.

private void assertHandlesLogTruncation(Command cmd) throws IOException {
    inMemoryChannel.reset();
    cmd.serialize(inMemoryChannel);
    int bytesSuccessfullyWritten = inMemoryChannel.writerPosition();
    try {
        StorageCommand command = serialization.read(inMemoryChannel);
        assertEquals(cmd, command);
    } catch (Exception e) {
        throw new AssertionError("Failed to deserialize " + cmd + ", because: ", e);
    }
    bytesSuccessfullyWritten--;
    while (bytesSuccessfullyWritten-- > 0) {
        inMemoryChannel.reset();
        cmd.serialize(inMemoryChannel);
        inMemoryChannel.truncateTo(bytesSuccessfullyWritten);
        Command command = null;
        try {
            command = serialization.read(inMemoryChannel);
        } catch (ReadPastEndException e) {
            assertNull(command, "Deserialization did not detect log truncation!" + "Record: " + cmd + ", deserialized: " + command);
        }
    }
}
Also used : RelationshipCountsCommand(org.neo4j.internal.recordstorage.Command.RelationshipCountsCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) NodeCountsCommand(org.neo4j.internal.recordstorage.Command.NodeCountsCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) IOException(java.io.IOException) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException)

Example 2 with ReadPastEndException

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

the class TokenScanWriteMonitor method dumpFile.

private static long dumpFile(FileSystemAbstraction fs, Path file, Dumper dumper, TxFilter txFilter, long session) throws IOException {
    try (ReadableChannel channel = new ReadAheadChannel<>(fs.read(file), new NativeScopedBuffer(DEFAULT_READ_AHEAD_SIZE, INSTANCE))) {
        long range = -1;
        int tokenId = -1;
        long flush = 0;
        // noinspection InfiniteLoopStatement
        while (true) {
            byte type = channel.get();
            switch(type) {
                case TYPE_RANGE:
                    range = channel.getLong();
                    tokenId = channel.getInt();
                    if (txFilter != null) {
                        txFilter.clear();
                    }
                    break;
                case TYPE_PREPARE_ADD:
                case TYPE_PREPARE_REMOVE:
                    dumpPrepare(dumper, type, channel, range, tokenId, txFilter, session, flush);
                    break;
                case TYPE_MERGE_ADD:
                case TYPE_MERGE_REMOVE:
                    dumpMerge(dumper, type, channel, range, tokenId, txFilter, session, flush);
                    break;
                case TYPE_FLUSH:
                    flush++;
                    break;
                case TYPE_SESSION_END:
                    session++;
                    flush = 0;
                    break;
                default:
                    System.out.println("Unknown type " + type + " at " + ((ReadAheadChannel) channel).position());
                    break;
            }
        }
    } catch (ReadPastEndException e) {
    // This is OK. we're done with this file
    }
    return session;
}
Also used : ReadableChannel(org.neo4j.io.fs.ReadableChannel) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) ReadAheadChannel(org.neo4j.io.fs.ReadAheadChannel) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException)

Example 3 with ReadPastEndException

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

the class VersionAwareLogEntryReader method readLogEntry.

@Override
public LogEntry readLogEntry(ReadableClosablePositionAwareChecksumChannel channel) throws IOException {
    try {
        while (true) {
            channel.getCurrentPosition(positionMarker);
            byte versionCode = channel.get();
            if (versionCode == 0) {
                // and we report that we reach end of record stream from our point of view
                if (channel instanceof PositionableChannel) {
                    resetChannelPosition(channel);
                } else {
                    throw new IllegalStateException("Log reader expects positionable channel to be able to reset offset. Current channel: " + channel);
                }
                return null;
            }
            if (parserSet == null || parserSet.getIntroductionVersion().version() != versionCode) {
                try {
                    parserSet = LogEntryParserSets.parserSet(KernelVersion.getForVersion(versionCode));
                } catch (IllegalArgumentException e) {
                    throw new UnsupportedLogVersionException(String.format("Log file contains entries with prefix %d, and the lowest supported prefix is %s. This " + "indicates that the log files originates from an older version of neo4j, which we don't support " + "migrations from.", versionCode, KernelVersion.V2_3));
                }
                // a new checksum segment if we change version parser.
                if (channel instanceof PositionableChannel) {
                    resetChannelPosition(channel);
                    channel.beginChecksum();
                    channel.get();
                }
            }
            byte typeCode = channel.get();
            LogEntryParser entryReader;
            LogEntry entry;
            try {
                entryReader = parserSet.select(typeCode);
                entry = entryReader.parse(parserSet.getIntroductionVersion(), channel, positionMarker, commandReaderFactory);
            } catch (ReadPastEndException e) {
                // Make these exceptions slip by straight out to the outer handler
                throw e;
            } catch (Exception e) {
                // Tag all other exceptions with log position and other useful information
                LogPosition position = positionMarker.newPosition();
                withMessage(e, e.getMessage() + ". At position " + position + " and entry version " + versionCode);
                throwIfInstanceOf(e, UnsupportedLogVersionException.class);
                throw new IOException(e);
            }
            verifyChecksumChain(entry);
            return entry;
        }
    } catch (ReadPastEndException e) {
        return null;
    }
}
Also used : PositionableChannel(org.neo4j.io.fs.PositionableChannel) IOException(java.io.IOException) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException) IOException(java.io.IOException) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 4 with ReadPastEndException

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

the class LoggingIndexedIdGeneratorMonitor method dumpFile.

private static void dumpFile(FileSystemAbstraction fs, Path path, Dumper dumper) throws IOException {
    dumper.path(path);
    try (var channel = new ReadAheadChannel<>(fs.read(path), new NativeScopedBuffer(DEFAULT_READ_AHEAD_SIZE, INSTANCE))) {
        while (true) {
            byte typeByte = channel.get();
            if (typeByte < 0 || typeByte >= TYPES.length) {
                System.out.println("Unknown type " + typeByte + " at " + channel.position());
                continue;
            }
            Type type = TYPES[typeByte];
            long time = channel.getLong();
            switch(type) {
                case CLEARING_CACHE:
                case CLEARED_CACHE:
                case CLOSED:
                    dumper.type(type, time);
                    break;
                case ALLOCATE_HIGH:
                case ALLOCATE_REUSED:
                case CACHED:
                case MARK_USED:
                case MARK_DELETED:
                case MARK_FREE:
                case MARK_RESERVED:
                case MARK_UNRESERVED:
                case MARK_DELETED_AND_FREE:
                case NORMALIZED:
                case BRIDGED:
                    dumper.typeAndId(type, time, channel.getLong());
                    break;
                case OPENED:
                case CHECKPOINT:
                    dumper.typeAndTwoIds(type, time, channel.getLong(), channel.getLong());
                    break;
                default:
                    System.out.println("Unknown type " + type + " at " + channel.position());
                    break;
            }
        }
    } catch (ReadPastEndException e) {
    // This is OK. we're done with this file
    }
}
Also used : NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) ReadAheadChannel(org.neo4j.io.fs.ReadAheadChannel) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException)

Example 5 with ReadPastEndException

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

the class TransactionRecordStateTest method readFromChannel.

@SuppressWarnings("InfiniteLoopStatement")
private static CommandsToApply readFromChannel(ReadableLogChannel channel) throws IOException {
    CommandReader reader = LogCommandSerializationV4_0.INSTANCE;
    List<StorageCommand> commands = new ArrayList<>();
    try {
        while (true) {
            commands.add(reader.read(channel));
        }
    } catch (ReadPastEndException e) {
    // reached the end
    }
    return new GroupOfCommands(commands.toArray(new StorageCommand[0]));
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException)

Aggregations

ReadPastEndException (org.neo4j.io.fs.ReadPastEndException)5 IOException (java.io.IOException)2 ReadAheadChannel (org.neo4j.io.fs.ReadAheadChannel)2 NativeScopedBuffer (org.neo4j.io.memory.NativeScopedBuffer)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ArrayList (java.util.ArrayList)1 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)1 NodeCountsCommand (org.neo4j.internal.recordstorage.Command.NodeCountsCommand)1 RelationshipCountsCommand (org.neo4j.internal.recordstorage.Command.RelationshipCountsCommand)1 PositionableChannel (org.neo4j.io.fs.PositionableChannel)1 ReadableChannel (org.neo4j.io.fs.ReadableChannel)1 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)1 CommandReader (org.neo4j.storageengine.api.CommandReader)1