Search in sources :

Example 16 with PhysicalTransactionRepresentation

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());
}
Also used : PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NeoStores(org.neo4j.kernel.impl.store.NeoStores) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) NodePropertyCommandsExtractor(org.neo4j.kernel.impl.api.index.NodePropertyCommandsExtractor) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 17 with PhysicalTransactionRepresentation

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);
    }
}
Also used : LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) IOException(java.io.IOException)

Example 18 with PhysicalTransactionRepresentation

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);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 19 with PhysicalTransactionRepresentation

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());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 20 with PhysicalTransactionRepresentation

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);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Aggregations

PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)35 Test (org.junit.Test)15 StorageCommand (org.neo4j.storageengine.api.StorageCommand)9 ArrayList (java.util.ArrayList)7 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)6 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)5 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)5 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)4 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)4 ByteBuf (io.netty.buffer.ByteBuf)3 NetworkFlushableByteBuf (org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 Command (org.neo4j.kernel.impl.transaction.command.Command)3 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)3 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)3 ReplicatedTransaction (org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)2 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)2