use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldCreateEqualNodePropertyUpdatesOnRecoveryOfCreatedNode.
@Test
public void shouldCreateEqualNodePropertyUpdatesOnRecoveryOfCreatedNode() throws Exception {
/* There was an issue where recovering a tx where a node with a label and a property
* was created resulted in two exact copies of NodePropertyUpdates. */
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
int labelId = 5, propertyKeyId = 7;
// -- an index
long ruleId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
SchemaRule rule = indexRule(ruleId, forLabel(labelId, propertyKeyId), PROVIDER_DESCRIPTOR);
recordState.createSchemaRule(rule);
apply(neoStores, recordState);
// -- and a tx creating a node with that label and property key
recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
recordState.addLabelToNode(labelId, nodeId);
recordState.nodeAddProperty(nodeId, propertyKeyId, "Neo");
// WHEN
PhysicalTransactionRepresentation transaction = transactionRepresentationOf(recordState);
NodePropertyCommandsExtractor extractor = new NodePropertyCommandsExtractor();
transaction.accept(extractor);
// THEN
// -- later recovering that tx, there should be only one update
assertTrue(extractor.containsAnyNodeOrPropertyUpdate());
PrimitiveLongSet recoveredNodeIds = Primitive.longSet();
recoveredNodeIds.addAll(extractor.nodeCommandsById().iterator());
recoveredNodeIds.addAll(extractor.propertyCommandsByNodeIds().iterator());
assertEquals(1, recoveredNodeIds.size());
assertEquals(nodeId, recoveredNodeIds.iterator().next());
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class LogTruncationTest method assertHandlesLogTruncation.
private void assertHandlesLogTruncation(Command cmd) throws IOException {
inMemoryChannel.reset();
writer.serialize(new PhysicalTransactionRepresentation(Arrays.asList(cmd)));
int bytesSuccessfullyWritten = inMemoryChannel.writerPosition();
try {
LogEntry logEntry = logEntryReader.readLogEntry(inMemoryChannel);
StorageCommand command = ((LogEntryCommand) logEntry).getXaCommand();
assertEquals(cmd, command);
} catch (Exception e) {
throw new AssertionError("Failed to deserialize " + cmd.toString() + ", because: ", e);
}
bytesSuccessfullyWritten--;
while (bytesSuccessfullyWritten-- > 0) {
inMemoryChannel.reset();
writer.serialize(new PhysicalTransactionRepresentation(Arrays.asList(cmd)));
inMemoryChannel.truncateTo(bytesSuccessfullyWritten);
LogEntry deserialized = logEntryReader.readLogEntry(inMemoryChannel);
assertNull("Deserialization did not detect log truncation!" + "Record: " + cmd + ", deserialized: " + deserialized, deserialized);
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class TxPullResponseEncodeDecodeTest method newCommittedTransactionRepresentation.
private CommittedTransactionRepresentation newCommittedTransactionRepresentation() {
final long arbitraryRecordId = 27L;
Command.NodeCommand command = new Command.NodeCommand(new NodeRecord(arbitraryRecordId), new NodeRecord(arbitraryRecordId));
PhysicalTransactionRepresentation physicalTransactionRepresentation = new PhysicalTransactionRepresentation(asList(new LogEntryCommand(command).getXaCommand()));
physicalTransactionRepresentation.setHeader(new byte[] {}, 0, 0, 0, 0, 0, 0);
LogEntryStart startEntry = new LogEntryStart(0, 0, 0L, 0L, new byte[] {}, LogPosition.UNSPECIFIED);
OnePhaseCommit commitEntry = new OnePhaseCommit(42, 0);
return new CommittedTransactionRepresentation(startEntry, physicalTransactionRepresentation, commitEntry);
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class ProtocolTest method shouldSerializeAndDeserializeTransactionRepresentation.
@Test
public void shouldSerializeAndDeserializeTransactionRepresentation() throws Exception {
// GIVEN
PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(justOneNode());
byte[] additionalHeader = "extra".getBytes();
int masterId = 1, authorId = 2;
long timeStarted = 12345, lastTxWhenStarted = 12, timeCommitted = timeStarted + 10;
transaction.setHeader(additionalHeader, masterId, authorId, timeStarted, lastTxWhenStarted, timeCommitted, -1);
Protocol.TransactionSerializer serializer = new Protocol.TransactionSerializer(transaction);
ChannelBuffer buffer = new ChannelBufferWrapper(new InMemoryClosableChannel());
// WHEN serializing the transaction
serializer.write(buffer);
// THEN deserializing the same transaction should yield the same data.
// ... remember that this deserializer doesn't read the data source name string. Read it manually here
assertEquals(NeoStoreDataSource.DEFAULT_DATA_SOURCE_NAME, Protocol.readString(buffer));
VersionAwareLogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
TransactionRepresentation readTransaction = new Protocol.TransactionRepresentationDeserializer(reader).read(buffer, ByteBuffer.allocate(1000));
assertArrayEquals(additionalHeader, readTransaction.additionalHeader());
assertEquals(masterId, readTransaction.getMasterId());
assertEquals(authorId, readTransaction.getAuthorId());
assertEquals(timeStarted, readTransaction.getTimeStarted());
assertEquals(lastTxWhenStarted, readTransaction.getLatestCommittedTxWhenStarted());
assertEquals(timeCommitted, readTransaction.getTimeCommitted());
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation in project neo4j by neo4j.
the class TransactionBatchCommitterTest method tx.
private TransactionToApply tx(long id, long commitTimestamp) {
PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(emptyList());
representation.setHeader(new byte[0], 0, 0, commitTimestamp - 10, id - 1, commitTimestamp, 0);
return new TransactionToApply(representation, id);
}
Aggregations