use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class MadeUpServerImplementation method transaction.
private TransactionRepresentation transaction(long txId) {
Collection<StorageCommand> commands = new ArrayList<>();
NodeRecord node = new NodeRecord(txId);
node.setInUse(true);
commands.add(new NodeCommand(new NodeRecord(txId), node));
PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands);
transaction.setHeader(new byte[0], 0, 0, 0, 0, 0, 0);
return transaction;
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class ReplicatedTokenStateMachine method applyToStore.
private int applyToStore(Collection<StorageCommand> commands, long logIndex) throws NoSuchEntryException {
int tokenId = extractTokenId(commands);
PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(commands);
representation.setHeader(encodeLogIndexAsTxHeader(logIndex), 0, 0, 0, 0L, 0L, 0);
try (LockGroup ignored = new LockGroup()) {
commitProcess.commit(new TransactionToApply(representation), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL);
} catch (TransactionFailureException e) {
throw new RuntimeException(e);
}
return tokenId;
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class RaftContentByteBufferMarshalTest method txSerializationShouldNotResultInExcessZeroes.
@Test
public void txSerializationShouldNotResultInExcessZeroes() throws Exception {
/*
* This test ensures that the buffer used to serialize a transaction and then extract the byte array for
* sending over the wire is trimmed properly. Not doing so will result in sending too many trailing garbage
* (zeroes) that will be ignored from the other side, as zeros are interpreted as null entries from the
* LogEntryReader and stop the deserialization process.
* The test creates a single transaction which has just a header, no commands. That should amount to 40 bytes
* as ReplicatedTransactionFactory.TransactionSerializer.write() makes it out at the time of this writing. If
* that code changes, this test will break.
*/
byte[] extraHeader = new byte[0];
PhysicalTransactionRepresentation txIn = new PhysicalTransactionRepresentation(new ArrayList<>());
txIn.setHeader(extraHeader, -1, -1, 0, 0, 0, 0);
// when
ReplicatedTransaction in = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(txIn);
// then
assertEquals(40, in.getTxBytes().length);
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class LegacyLogEntryWriter method writeAllLogEntries.
public void writeAllLogEntries(LogVersionedStoreChannel channel, IOCursor<LogEntry> cursor) throws IOException {
try (PositionAwarePhysicalFlushableChannel writable = new PositionAwarePhysicalFlushableChannel(channel)) {
final LogEntryWriter writer = factory.apply(writable);
List<StorageCommand> commands = new ArrayList<>();
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
final LogEntryStart startEntry = entry.as();
writer.writeStartEntry(startEntry.getMasterId(), startEntry.getLocalId(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), startEntry.getAdditionalHeader());
} else if (entry instanceof LogEntryCommit) {
if (!commands.isEmpty()) {
writer.serialize(new PhysicalTransactionRepresentation(commands));
commands = new ArrayList<>();
}
final LogEntryCommit commitEntry = (LogEntryCommit) entry;
writer.writeCommitEntry(commitEntry.getTxId(), commitEntry.getTimeWritten());
} else if (entry instanceof LogEntryCommand) {
commands.add(((LogEntryCommand) entry).getXaCommand());
} else {
throw new IllegalStateException("Unknown entry: " + entry);
}
}
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class CoreReplicatedContentMarshalTest method shouldMarshalTransactionReferenceWithMissingHeader.
@Test
public void shouldMarshalTransactionReferenceWithMissingHeader() throws Exception {
ByteBuf buffer = Unpooled.buffer();
PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(Collections.emptyList());
ReplicatedContent replicatedTx = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(representation);
assertMarshalingEquality(buffer, replicatedTx);
}
Aggregations