Search in sources :

Example 26 with PhysicalTransactionRepresentation

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

the class CoreBootstrapper method appendNullTransactionLogEntryToSetRaftIndexToMinusOne.

private void appendNullTransactionLogEntryToSetRaftIndexToMinusOne() throws IOException {
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    ReadOnlyLogVersionRepository logVersionRepository = new ReadOnlyLogVersionRepository(pageCache, storeDir);
    ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore(pageCache, storeDir);
    PhysicalLogFile logFile = new PhysicalLogFile(fs, logFiles, Long.MAX_VALUE, /*don't rotate*/
    () -> readOnlyTransactionIdStore.getLastClosedTransactionId() - 1, logVersionRepository, new Monitors().newMonitor(PhysicalLogFile.Monitor.class), new LogHeaderCache(10));
    long dummyTransactionId;
    try (Lifespan lifespan = new Lifespan(logFile)) {
        FlushableChannel channel = logFile.getWriter();
        TransactionLogWriter writer = new TransactionLogWriter(new LogEntryWriter(channel));
        long lastCommittedTransactionId = readOnlyTransactionIdStore.getLastCommittedTransactionId();
        PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(Collections.emptyList());
        byte[] txHeaderBytes = LogIndexTxHeaderEncoding.encodeLogIndexAsTxHeader(-1);
        tx.setHeader(txHeaderBytes, -1, -1, -1, lastCommittedTransactionId, -1, -1);
        dummyTransactionId = lastCommittedTransactionId + 1;
        writer.append(tx, dummyTransactionId);
        channel.prepareForFlush().flush();
    }
    File neoStoreFile = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    MetaDataStore.setRecord(pageCache, neoStoreFile, LAST_TRANSACTION_ID, dummyTransactionId);
}
Also used : PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadOnlyTransactionIdStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore) FlushableChannel(org.neo4j.kernel.impl.transaction.log.FlushableChannel) Monitors(org.neo4j.kernel.monitoring.Monitors) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) ReadOnlyLogVersionRepository(org.neo4j.kernel.impl.transaction.log.ReadOnlyLogVersionRepository) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 27 with PhysicalTransactionRepresentation

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

the class TransactionRepresentationFactory method nextTransaction.

TransactionToApply nextTransaction(long txId) {
    PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(createRandomCommands());
    TransactionHeaderInformation headerInfo = DEFAULT.create();
    representation.setHeader(headerInfo.getAdditionalHeader(), headerInfo.getMasterId(), headerInfo.getAuthorId(), headerInfo.getAuthorId(), txId, currentTimeMillis(), 42);
    return new TransactionToApply(representation);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionHeaderInformation(org.neo4j.kernel.impl.api.TransactionHeaderInformation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 28 with PhysicalTransactionRepresentation

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

the class TransactionRecordStateTest method transaction.

private TransactionRepresentation transaction(TransactionRecordState recordState) throws TransactionFailureException {
    List<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(commands);
    transaction.setHeader(new byte[0], 0, 0, 0, 0, 0, 0);
    return transaction;
}
Also used : StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 29 with PhysicalTransactionRepresentation

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

the class TransactionRecordStateTest method shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage.

@Test
public void shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage() throws Exception {
    /* There was an issue where GIVEN:
         *
         *   Legend: () = node, [] = property record
         *
         *   ()-->[0:block{size:1}]
         *
         * WHEN adding a new property record in front of if, not changing any data in that record i.e:
         *
         *   ()-->[1:block{size:4}]-->[0:block{size:1}]
         *
         * The state of property record 0 would be that it had loaded value records for that block,
         * but those value records weren't heavy, so writing that record to the log would fail
         * w/ an assertion data != null.
         */
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    int nodeId = 0;
    recordState.nodeCreate(nodeId);
    int index = 0;
    // will require a block of size 1
    recordState.nodeAddProperty(nodeId, index, string(70));
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    int index2 = 1;
    // will require a block of size 4
    recordState.nodeAddProperty(nodeId, index2, string(40));
    // THEN
    PhysicalTransactionRepresentation representation = transactionRepresentationOf(recordState);
    representation.accept(command -> ((Command) command).handle(new CommandVisitor.Adapter() {

        @Override
        public boolean visitPropertyCommand(PropertyCommand command) throws IOException {
            verifyPropertyRecord(command.getBefore());
            verifyPropertyRecord(command.getAfter());
            return false;
        }

        private void verifyPropertyRecord(PropertyRecord record) {
            if (record.getPrevProp() != Record.NO_NEXT_PROPERTY.intValue()) {
                for (PropertyBlock block : record) {
                    assertTrue(block.isLight());
                }
            }
        }
    }));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 30 with PhysicalTransactionRepresentation

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

the class TransactionRecordStateTest method transactionRepresentationOf.

private PhysicalTransactionRepresentation transactionRepresentationOf(TransactionRecordState writeTransaction) throws TransactionFailureException {
    List<StorageCommand> commands = new ArrayList<>();
    writeTransaction.extractCommands(commands);
    PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
    tx.setHeader(new byte[0], 0, 0, 0, 0, 0, 0);
    return tx;
}
Also used : StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) 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