use of org.neo4j.storageengine.api.StorageCommand 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.storageengine.api.StorageCommand in project neo4j by neo4j.
the class CheckTxLogs method scan.
private <C extends Command, R extends AbstractBaseRecord> boolean scan(PhysicalLogFiles logFiles, InconsistenciesHandler handler, CheckType<C, R> check, boolean checkTxIds) throws IOException {
out.println("Checking logs for " + check.name() + " inconsistencies");
CommittedRecords<R> state = new CommittedRecords<>(check);
List<CommandAndLogVersion> txCommands = new ArrayList<>();
boolean validLogs = true;
long commandsRead = 0;
long lastSeenTxId = BASE_TX_ID;
try (LogEntryCursor logEntryCursor = LogTestUtils.openLogs(fs, logFiles)) {
while (logEntryCursor.next()) {
LogEntry entry = logEntryCursor.get();
if (entry instanceof LogEntryCommand) {
StorageCommand command = ((LogEntryCommand) entry).getXaCommand();
if (check.commandClass().isInstance(command)) {
long logVersion = logEntryCursor.getCurrentLogVersion();
txCommands.add(new CommandAndLogVersion(command, logVersion));
}
} else if (entry instanceof LogEntryCommit) {
long txId = ((LogEntryCommit) entry).getTxId();
if (checkTxIds) {
validLogs &= checkNoDuplicatedTxsInTheLog(lastSeenTxId, txId, handler);
lastSeenTxId = txId;
}
for (CommandAndLogVersion txCommand : txCommands) {
validLogs &= checkAndHandleInconsistencies(txCommand, check, state, txId, handler);
}
txCommands.clear();
}
commandsRead++;
}
}
out.println("Processed " + commandsRead + " commands");
out.println(state);
if (!txCommands.isEmpty()) {
out.println("Found " + txCommands.size() + " uncommitted commands at the end.");
for (CommandAndLogVersion txCommand : txCommands) {
validLogs &= checkAndHandleInconsistencies(txCommand, check, state, -1, handler);
}
txCommands.clear();
}
return validLogs;
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class LegacyLogEntryWriter method writeAllLogEntries.
public void writeAllLogEntries(LogVersionedStoreChannel channel, IOCursor<LogEntry> cursor) throws IOException {
try (PositionAwarePhysicalFlushableChannel writable = new PositionAwarePhysicalFlushableChannel(channel)) {
final LogEntryWriter writer = factory.apply(writable);
List<StorageCommand> commands = new ArrayList<>();
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
final LogEntryStart startEntry = entry.as();
writer.writeStartEntry(startEntry.getMasterId(), startEntry.getLocalId(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), startEntry.getAdditionalHeader());
} else if (entry instanceof LogEntryCommit) {
if (!commands.isEmpty()) {
writer.serialize(new PhysicalTransactionRepresentation(commands));
commands = new ArrayList<>();
}
final LogEntryCommit commitEntry = (LogEntryCommit) entry;
writer.writeCommitEntry(commitEntry.getTxId(), commitEntry.getTimeWritten());
} else if (entry instanceof LogEntryCommand) {
commands.add(((LogEntryCommand) entry).getXaCommand());
} else {
throw new IllegalStateException("Unknown entry: " + entry);
}
}
}
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class PhysicalTransactionRepresentation method toString.
@Override
public String toString() {
StringBuilder builder = new StringBuilder(getClass().getSimpleName() + "[");
builder.append("masterId:" + masterId + ",");
builder.append("authorId:" + authorId + ",");
builder.append("timeStarted:" + timeStarted + ",");
builder.append("latestCommittedTxWhenStarted:" + latestCommittedTxWhenStarted + ",");
builder.append("timeCommitted:" + timeCommitted + ",");
builder.append("lockSession:" + lockSessionIdentifier + ",");
builder.append("additionalHeader:" + Arrays.toString(additionalHeader));
for (StorageCommand command : commands) {
builder.append("\n" + command);
}
return builder.toString();
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class ReplicatedTokenHolderTest method mockedStorageEngine.
@SuppressWarnings("unchecked")
private StorageEngine mockedStorageEngine() throws Exception {
StorageEngine storageEngine = mock(StorageEngine.class);
doAnswer(invocation -> {
Collection<StorageCommand> target = invocation.getArgumentAt(0, Collection.class);
ReadableTransactionState txState = invocation.getArgumentAt(1, ReadableTransactionState.class);
txState.accept(new TxStateVisitor.Adapter() {
@Override
public void visitCreatedLabelToken(String name, int id) {
LabelTokenRecord before = new LabelTokenRecord(id);
LabelTokenRecord after = before.clone();
after.setInUse(true);
target.add(new Command.LabelTokenCommand(before, after));
}
});
return null;
}).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
StoreReadLayer readLayer = mock(StoreReadLayer.class);
when(readLayer.newStatement()).thenReturn(mock(StorageStatement.class));
when(storageEngine.storeReadLayer()).thenReturn(readLayer);
return storageEngine;
}
Aggregations