use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class RecordStorageEngine method createCommands.
/**
* @throws TransactionFailureException if command generation fails or some prerequisite of some command didn't validate,
* for example if trying to delete a node that still has relationships.
* @throws CreateConstraintFailureException if this transaction was set to create a constraint and that failed.
* @throws ConstraintValidationException if this transaction was set to create a constraint and some data violates that constraint.
*/
@SuppressWarnings("resource")
@Override
public void createCommands(Collection<StorageCommand> commands, ReadableTransactionState txState, StorageReader storageReader, CommandCreationContext commandCreationContext, ResourceLocker locks, LockTracer lockTracer, long lastTransactionIdWhenStarted, TxStateVisitor.Decorator additionalTxStateVisitor, CursorContext cursorContext, MemoryTracker transactionMemoryTracker) throws KernelException {
if (txState != null) {
KernelVersion version = neoStores.getMetaDataStore().kernelVersion();
Preconditions.checkState(version.isAtLeast(KernelVersion.V4_2), "Can not write older version than %s. Requested %s", KernelVersion.V4_2, version);
// We can make this cast here because we expected that the storageReader passed in here comes from
// this storage engine itself, anything else is considered a bug. And we do know the inner workings
// of the storage statements that we create.
RecordStorageCommandCreationContext creationContext = (RecordStorageCommandCreationContext) commandCreationContext;
LogCommandSerialization serialization = RecordStorageCommandReaderFactory.INSTANCE.get(version);
TransactionRecordState recordState = creationContext.createTransactionRecordState(integrityValidator, lastTransactionIdWhenStarted, locks, lockTracer, serialization, lockVerificationFactory.create(locks, txState, neoStores, schemaRuleAccess));
// Visit transaction state and populate these record state objects
TxStateVisitor txStateVisitor = new TransactionToRecordStateVisitor(recordState, schemaState, schemaRuleAccess, constraintSemantics, cursorContext);
CountsRecordState countsRecordState = new CountsRecordState(serialization);
txStateVisitor = additionalTxStateVisitor.apply(txStateVisitor);
txStateVisitor = new TransactionCountingStateVisitor(txStateVisitor, storageReader, txState, countsRecordState, cursorContext);
try (TxStateVisitor visitor = txStateVisitor) {
txState.accept(visitor);
}
// Convert record state into commands
recordState.extractCommands(commands, transactionMemoryTracker);
countsRecordState.extractCommands(commands, transactionMemoryTracker);
// Verify sufficient locks
CommandLockVerification commandLockVerification = commandLockVerificationFactory.create(locks, txState, neoStores, schemaRuleAccess);
commandLockVerification.verifySufficientlyLocked(commands);
}
}
use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class RecordStorageEngine method createUpgradeCommands.
@Override
public List<StorageCommand> createUpgradeCommands(KernelVersion versionToUpgradeTo, InjectedNLIUpgradeCallback injectedNLIUpgradeCallback) {
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
KernelVersion currentVersion = metaDataStore.kernelVersion();
Preconditions.checkState(currentVersion.isAtLeast(KernelVersion.V4_2), "Upgrade transaction was introduced in %s and must be done from at least %s. Tried upgrading from %s to %s", KernelVersion.V4_3_D4, KernelVersion.V4_2, currentVersion, versionToUpgradeTo);
Preconditions.checkState(versionToUpgradeTo.isGreaterThan(currentVersion), "Can not downgrade from %s to %s", currentVersion, versionToUpgradeTo);
int id = MetaDataStore.Position.KERNEL_VERSION.id();
MetaDataRecord before = metaDataStore.newRecord();
before.setId(id);
before.initialize(true, currentVersion.version());
MetaDataRecord after = metaDataStore.newRecord();
after.setId(id);
after.initialize(true, versionToUpgradeTo.version());
// This command will be the first one in the "new" version, indicating the switch and writing it to the MetaDataStore
LogCommandSerialization serialization = RecordStorageCommandReaderFactory.INSTANCE.get(versionToUpgradeTo);
var commands = new ArrayList<StorageCommand>();
commands.add(new Command.MetaDataCommand(serialization, before, after));
// it in the schemaStore.
if (currentVersion.isLessThan(KernelVersion.VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED)) {
commands.add(createSchemaUpgradeCommand(serialization, injectedNLIUpgradeCallback));
}
return commands;
}
use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class NeoStoreTransactionApplier method visitMetaDataCommand.
@Override
public boolean visitMetaDataCommand(Command.MetaDataCommand command) throws IOException {
if (command.getAfter().getId() == MetaDataStore.Position.KERNEL_VERSION.id()) {
KernelVersion kernelVersion = KernelVersion.getForVersion(Numbers.safeCastLongToByte(command.getAfter().getValue()));
neoStores.getMetaDataStore().setKernelVersion(kernelVersion, cursorContext);
} else {
throw new UnsupportedOperationException("Unexpected meta data update " + command);
}
return false;
}
use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class DetachedCheckpointLogEntryParserTest method parseDetachedCheckpointRecord.
@Test
void parseDetachedCheckpointRecord() throws IOException {
KernelVersion version = KernelVersion.V4_3_D4;
var storeId = new StoreId(4, 5, 6, 7, 8);
var channel = new InMemoryClosableChannel();
int checkpointMillis = 3;
String checkpointDescription = "checkpoint";
byte[] bytes = Arrays.copyOf(checkpointDescription.getBytes(), 120);
// For version confusion, please read LogEntryParserSetV4_3 comments
var checkpoint = new LogEntryDetachedCheckpoint(version, new LogPosition(1, 2), checkpointMillis, storeId, checkpointDescription);
channel.putLong(checkpoint.getLogPosition().getLogVersion()).putLong(checkpoint.getLogPosition().getByteOffset()).putLong(checkpointMillis).putLong(storeId.getCreationTime()).putLong(storeId.getRandomId()).putLong(storeId.getStoreVersion()).putLong(storeId.getUpgradeTime()).putLong(storeId.getUpgradeTxId()).putShort((short) checkpointDescription.getBytes().length).put(bytes, bytes.length);
channel.putChecksum();
var checkpointParser = LogEntryParserSets.parserSet(version).select(DETACHED_CHECK_POINT);
LogEntry logEntry = checkpointParser.parse(version, channel, positionMarker, commandReader);
assertEquals(checkpoint, logEntry);
}
use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class TransactionLogsRecoveryTest method writeSomeDataWithVersion.
private void writeSomeDataWithVersion(Path file, Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException> visitor, KernelVersion version) throws IOException {
try (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileSystem.write(file), logVersion, CURRENT_LOG_FORMAT_VERSION, file, EMPTY_ACCESSOR);
PositionAwarePhysicalFlushableChecksumChannel writableLogChannel = new PositionAwarePhysicalFlushableChecksumChannel(versionedStoreChannel, new HeapScopedBuffer(1, KibiByte, INSTANCE))) {
writeLogHeader(writableLogChannel, new LogHeader(logVersion, 2L, StoreId.UNKNOWN));
writableLogChannel.beginChecksum();
Consumer<LogPositionMarker> consumer = marker -> {
try {
writableLogChannel.getCurrentPosition(marker);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
LogEntryWriter first = new LogEntryWriter(writableLogChannel, version);
visitor.visit(Pair.of(first, consumer));
}
}
Aggregations