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