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));
}
}
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++;
}
}
}
}
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;
});
}
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;
}
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);
}
Aggregations