Search in sources :

Example 1 with RecordStorageCommandReaderFactory

use of org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory in project neo4j by neo4j.

the class IndexDefineCommandTest method shouldWriteIndexDefineCommandIfMapWithinShortRange.

@Test
public void shouldWriteIndexDefineCommandIfMapWithinShortRange() throws IOException {
    // GIVEN
    InMemoryClosableChannel channel = new InMemoryClosableChannel(10_000);
    IndexDefineCommand command = initIndexDefineCommand(300);
    // WHEN
    command.serialize(channel);
    // THEN
    CommandReader commandReader = new RecordStorageCommandReaderFactory().byVersion(LogEntryVersion.CURRENT.byteCode());
    IndexDefineCommand read = (IndexDefineCommand) commandReader.read(channel);
    assertEquals(command.getIndexNameIdRange(), read.getIndexNameIdRange());
    assertEquals(command.getKeyIdRange(), read.getKeyIdRange());
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 2 with RecordStorageCommandReaderFactory

use of org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory in project neo4j by neo4j.

the class TxPullResponseDecoder method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
    NetworkReadableClosableChannelNetty4 logChannel = new NetworkReadableClosableChannelNetty4(msg);
    StoreId storeId = StoreIdMarshal.INSTANCE.unmarshal(logChannel);
    LogEntryReader<NetworkReadableClosableChannelNetty4> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    PhysicalTransactionCursor<NetworkReadableClosableChannelNetty4> transactionCursor = new PhysicalTransactionCursor<>(logChannel, reader);
    transactionCursor.next();
    CommittedTransactionRepresentation tx = transactionCursor.get();
    if (tx != null) {
        out.add(new TxPullResponse(storeId, tx));
    }
}
Also used : PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) StoreId(org.neo4j.causalclustering.identity.StoreId) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)

Example 3 with RecordStorageCommandReaderFactory

use of org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory in project neo4j by neo4j.

the class ReplicatedTransactionFactory method read.

public static TransactionRepresentation read(NetworkReadableClosableChannelNetty4 channel, byte[] extraHeader) throws IOException {
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    int authorId = channel.getInt();
    int masterId = channel.getInt();
    long latestCommittedTxWhenStarted = channel.getLong();
    long timeStarted = channel.getLong();
    long timeCommitted = channel.getLong();
    int lockSessionId = channel.getInt();
    int headerLength = channel.getInt();
    byte[] header;
    if (headerLength == 0) {
        header = extraHeader;
    } else {
        header = new byte[headerLength];
    }
    channel.get(header, headerLength);
    LogEntryCommand entryRead;
    List<StorageCommand> commands = new LinkedList<>();
    while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
        commands.add(entryRead.getXaCommand());
    }
    PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
    tx.setHeader(header, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, lockSessionId);
    return tx;
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LinkedList(java.util.LinkedList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 4 with RecordStorageCommandReaderFactory

use of org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory in project neo4j by neo4j.

the class ReplicatedTokenRequestSerializer method extractCommands.

static Collection<StorageCommand> extractCommands(byte[] commandBytes) {
    ByteBuf txBuffer = Unpooled.wrappedBuffer(commandBytes);
    NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(txBuffer);
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    LogEntryCommand entryRead;
    List<StorageCommand> commands = new LinkedList<>();
    try {
        while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
            commands.add(entryRead.getXaCommand());
        }
    } catch (IOException e) {
        // TODO: Handle or throw.
        e.printStackTrace();
    }
    return commands;
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) LinkedList(java.util.LinkedList) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 5 with RecordStorageCommandReaderFactory

use of org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory in project neo4j by neo4j.

the class TransactionLogCatchUpWriterTest method verifyCheckpointInLog.

private void verifyCheckpointInLog() throws IOException {
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    final LatestCheckPointFinder checkPointFinder = new LatestCheckPointFinder(logFiles, fs, logEntryReader);
    LatestCheckPointFinder.LatestCheckPoint checkPoint = checkPointFinder.find(0);
    assertNotNull(checkPoint.checkPoint);
    assertTrue(checkPoint.commitsAfterCheckPoint);
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Aggregations

RecordStorageCommandReaderFactory (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory)5 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)4 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)3 LinkedList (java.util.LinkedList)2 NetworkReadableClosableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)2 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ByteBuf (io.netty.buffer.ByteBuf)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 StoreId (org.neo4j.causalclustering.identity.StoreId)1 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)1 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)1 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)1 PhysicalTransactionCursor (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1 LatestCheckPointFinder (org.neo4j.kernel.recovery.LatestCheckPointFinder)1 CommandReader (org.neo4j.storageengine.api.CommandReader)1