Search in sources :

Example 1 with PhysicalTransactionCursor

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor 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 2 with PhysicalTransactionCursor

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor in project neo4j by neo4j.

the class TransactionLogCatchUpWriterTest method verifyTransactionsInLog.

private void verifyTransactionsInLog(long fromTxId, long endTxId) throws IOException {
    long expectedTxId = fromTxId;
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    LogVersionedStoreChannel versionedStoreChannel = PhysicalLogFile.openForVersion(logFiles, fs, 0, false);
    try (ReadableLogChannel channel = new ReadAheadLogChannel(versionedStoreChannel, LogVersionBridge.NO_MORE_CHANNELS, 1024)) {
        try (PhysicalTransactionCursor<ReadableLogChannel> txCursor = new PhysicalTransactionCursor<>(channel, new VersionAwareLogEntryReader<>())) {
            while (txCursor.next()) {
                CommittedTransactionRepresentation tx = txCursor.get();
                long txId = tx.getCommitEntry().getTxId();
                assertThat(expectedTxId, lessThanOrEqualTo(endTxId));
                assertEquals(expectedTxId, txId);
                expectedTxId++;
            }
        }
    }
}
Also used : PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 3 with PhysicalTransactionCursor

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor in project neo4j by neo4j.

the class TestLogPruning method transactionCount.

private int transactionCount() throws IOException {
    return aggregateLogData(version -> {
        int counter = 0;
        LogVersionBridge bridge = LogVersionBridge.NO_MORE_CHANNELS;
        LogVersionedStoreChannel versionedStoreChannel = files.getLogFile().openForVersion(version);
        try (ReadableLogChannel channel = new ReadAheadLogChannel(versionedStoreChannel, bridge, INSTANCE)) {
            try (PhysicalTransactionCursor physicalTransactionCursor = new PhysicalTransactionCursor(channel, new VersionAwareLogEntryReader(db.getDependencyResolver().resolveDependency(StorageEngineFactory.class).commandReaderFactory()))) {
                while (physicalTransactionCursor.next()) {
                    counter++;
                }
            }
        }
        return counter;
    });
}
Also used : PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) LogVersionBridge(org.neo4j.kernel.impl.transaction.log.LogVersionBridge) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)

Example 4 with PhysicalTransactionCursor

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor in project neo4j by neo4j.

the class RebuildFromLogs method findLastTransactionId.

private long findLastTransactionId(PhysicalLogFiles logFiles, long highestVersion) throws IOException {
    ReadableLogChannel logChannel = new ReadAheadLogChannel(PhysicalLogFile.openForVersion(logFiles, fs, highestVersion, false), NO_MORE_CHANNELS);
    long lastTransactionId = -1;
    LogEntryReader<ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader<>();
    try (IOCursor<CommittedTransactionRepresentation> cursor = new PhysicalTransactionCursor<>(logChannel, entryReader)) {
        while (cursor.next()) {
            lastTransactionId = cursor.get().getCommitEntry().getTxId();
        }
    }
    return lastTransactionId;
}
Also used : PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 5 with PhysicalTransactionCursor

use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor in project neo4j by neo4j.

the class Protocol method deserializeResponse.

public <PAYLOAD> Response<PAYLOAD> deserializeResponse(BlockingReadHandler<ChannelBuffer> reader, ByteBuffer input, long timeout, Deserializer<PAYLOAD> payloadDeserializer, ResourceReleaser channelReleaser, final LogEntryReader<ReadableClosablePositionAwareChannel> entryReader) throws IOException {
    final DechunkingChannelBuffer dechunkingBuffer = new DechunkingChannelBuffer(reader, timeout, internalProtocolVersion, applicationProtocolVersion);
    PAYLOAD response = payloadDeserializer.read(dechunkingBuffer, input);
    StoreId storeId = readStoreId(dechunkingBuffer, input);
    // Response type is what previously was a byte saying how many data sources there were in the
    // coming transaction stream response. For backwards compatibility we keep it as a byte and we introduce
    // the transaction obligation response type as -1
    byte responseType = dechunkingBuffer.readByte();
    if (responseType == TransactionObligationResponse.RESPONSE_TYPE) {
        // It is a transaction obligation response
        long obligationTxId = dechunkingBuffer.readLong();
        return new TransactionObligationResponse<>(response, storeId, obligationTxId, channelReleaser);
    }
    // It's a transaction stream in this response
    TransactionStream transactions = visitor -> {
        NetworkReadableClosableChannel channel = new NetworkReadableClosableChannel(dechunkingBuffer);
        try (PhysicalTransactionCursor<ReadableClosablePositionAwareChannel> cursor = new PhysicalTransactionCursor<>(channel, entryReader)) {
            while (cursor.next() && !visitor.visit(cursor.get())) {
            }
        }
    };
    return new TransactionStreamResponse<>(response, storeId, transactions, channelReleaser);
}
Also used : StoreId(org.neo4j.kernel.impl.store.StoreId) RecordFormat(org.neo4j.kernel.impl.store.format.RecordFormat) LengthFieldBasedFrameDecoder(org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) BlockingReadHandler(org.jboss.netty.handler.queue.BlockingReadHandler) StoreWriter(org.neo4j.com.storecopy.StoreWriter) IOException(java.io.IOException) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Channel(org.jboss.netty.channel.Channel) ByteBuffer(java.nio.ByteBuffer) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) List(java.util.List) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) LinkedList(java.util.LinkedList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) LengthFieldPrepender(org.jboss.netty.handler.codec.frame.LengthFieldPrepender) PhysicalTransactionCursor(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor) StoreId(org.neo4j.kernel.impl.store.StoreId)

Aggregations

PhysicalTransactionCursor (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionCursor)5 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)3 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)3 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)3 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)3 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 Channel (org.jboss.netty.channel.Channel)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 LengthFieldBasedFrameDecoder (org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder)1 LengthFieldPrepender (org.jboss.netty.handler.codec.frame.LengthFieldPrepender)1 BlockingReadHandler (org.jboss.netty.handler.queue.BlockingReadHandler)1 StoreId (org.neo4j.causalclustering.identity.StoreId)1 NetworkReadableClosableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)1 StoreWriter (org.neo4j.com.storecopy.StoreWriter)1