use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class Operations method assertTokenAndRelationshipPropertyIndexesSupported.
private void assertTokenAndRelationshipPropertyIndexesSupported(String message) {
KernelVersion currentStoreVersion = kernelVersionRepository.kernelVersion();
if (currentStoreVersion.isAtLeast(KernelVersion.VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED)) {
// new or upgraded store, good to go
return;
}
// store version is old
KernelVersion currentDbmsVersion = dbmsRuntimeRepository.getVersion().kernelVersion();
if (currentDbmsVersion.isAtLeast(KernelVersion.VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED)) {
// we will double check kernel version during commit
return;
}
throw new UnsupportedOperationException(format("%s Version was %s, but required version for operation is %s. Please upgrade dbms using 'dbms.upgrade()'.", message, currentDbmsVersion.name(), KernelVersion.VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED.name()));
}
use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class IntegrityValidator method validateSchemaRule.
void validateSchemaRule(SchemaRule schemaRule) throws TransactionFailureException {
Preconditions.checkState(indexValidator != null, "No index validator installed");
KernelVersion currentVersion = neoStores.getMetaDataStore().kernelVersion();
if (currentVersion.isLessThan(VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED)) {
if (schemaRule instanceof IndexDescriptor) {
IndexDescriptor index = (IndexDescriptor) schemaRule;
if (index.isTokenIndex() || isBtreeRelationshipPropertyIndex(index)) {
throw new TransactionFailureException(Status.General.UpgradeRequired, "Index operation on index '%s' not allowed. " + "Required kernel version for this transaction is %s, but actual version was %s.", index, VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED.name(), currentVersion.name());
}
}
}
if (schemaRule instanceof ConstraintDescriptor) {
ConstraintDescriptor constraint = (ConstraintDescriptor) schemaRule;
if (constraint.isIndexBackedConstraint()) {
long ownedIndex = constraint.asIndexBackedConstraint().ownedIndexId();
try {
indexValidator.validateIndex(ownedIndex);
} catch (KernelException e) {
// and have recovery performed. It's the safest bet to avoid loosing data.
throw new TransactionFailureException(Status.Transaction.TransactionValidationFailed, e, "Index validation of " + schemaRule + " failed, specifically for its owned index " + ownedIndex, e);
}
}
}
}
use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class DatabaseUpgradeTransactionIT method assertUpgradeTransactionInOrder.
private void assertUpgradeTransactionInOrder(KernelVersion from, KernelVersion to, long fromTxId) throws Exception {
LogicalTransactionStore lts = db.getDependencyResolver().resolveDependency(LogicalTransactionStore.class);
ArrayList<KernelVersion> transactionVersions = new ArrayList<>();
ArrayList<CommittedTransactionRepresentation> transactions = new ArrayList<>();
try (TransactionCursor transactionCursor = lts.getTransactions(fromTxId + 1)) {
while (transactionCursor.next()) {
CommittedTransactionRepresentation representation = transactionCursor.get();
transactions.add(representation);
transactionVersions.add(representation.getStartEntry().getVersion());
}
}
// at least upgrade transaction and the triggering transaction
assertThat(transactionVersions).hasSizeGreaterThanOrEqualTo(2);
// Sorted means everything is in order
assertThat(transactionVersions).isSortedAccordingTo(Comparator.comparingInt(KernelVersion::version));
// First should be "from" version
assertThat(transactionVersions.get(0)).isEqualTo(from);
// And last the "to" version
assertThat(transactionVersions.get(transactionVersions.size() - 1)).isEqualTo(to);
CommittedTransactionRepresentation upgradeTransaction = transactions.get(transactionVersions.indexOf(to));
PhysicalTransactionRepresentation physicalRep = (PhysicalTransactionRepresentation) upgradeTransaction.getTransactionRepresentation();
physicalRep.accept(element -> {
assertThat(element).isInstanceOf(Command.MetaDataCommand.class);
return true;
});
}
use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class DatabaseUpgradeTransactionHandlerTest method doATransaction.
private void doATransaction(boolean doSomeSleeping) {
if (!listenerUnregistered && listener != null) {
try {
Object state = listener.beforeCommit(mock(TransactionData.class), mock(KernelTransaction.class), mock(GraphDatabaseService.class));
KernelVersion currentKernelVersion = this.currentKernelVersion;
if (doSomeSleeping) {
// This sleep is an enabler for upgrade vs transactions race, makes this way more likely to trigger
Thread.sleep(ThreadLocalRandom.current().nextInt(3));
}
registeredTransactions.add(new RegisteredTransaction(currentKernelVersion, false));
// At this point we cannot assert on a comparison between dbms runtime version and kernel version
listener.afterCommit(mock(TransactionData.class), state, mock(GraphDatabaseService.class));
} catch (Exception e) {
ExceptionUtils.throwAsUncheckedException(e);
}
}
}
use of org.neo4j.kernel.KernelVersion in project neo4j by neo4j.
the class DatabaseUpgradeTransactionHandlerTest method init.
private void init(KernelVersion initialKernelVersion, DbmsRuntimeVersion initialDbmsRuntimeVersion) {
setKernelVersion(initialKernelVersion);
setDbmsRuntime(initialDbmsRuntimeVersion);
StorageEngine storageEngine = mock(StorageEngine.class);
doAnswer(inv -> {
KernelVersion toKernelVersion = inv.getArgument(0, KernelVersion.class);
registeredTransactions.add(new RegisteredTransaction(toKernelVersion, true));
return List.of(new FakeKernelVersionUpgradeCommand(toKernelVersion));
}).when(storageEngine).createUpgradeCommands(any(), any());
DbmsRuntimeRepository dbmsRuntimeRepository = mock(DbmsRuntimeRepository.class);
doAnswer(inv -> currentDbmsRuntimeVersion).when(dbmsRuntimeRepository).getVersion();
KernelVersionRepository kernelVersionRepository = this::getKernelVersion;
DatabaseTransactionEventListeners databaseTransactionEventListeners = mock(DatabaseTransactionEventListeners.class);
doAnswer(inv -> listener = inv.getArgument(0, InternalTransactionEventListener.class)).when(databaseTransactionEventListeners).registerTransactionEventListener(any());
doAnswer(inv -> listenerUnregistered = true).when(databaseTransactionEventListeners).unregisterTransactionEventListener(any());
DatabaseUpgradeTransactionHandler handler = new DatabaseUpgradeTransactionHandler(storageEngine, dbmsRuntimeRepository, kernelVersionRepository, databaseTransactionEventListeners, lock, logProvider);
handler.registerUpgradeListener(commands -> setKernelVersion(((FakeKernelVersionUpgradeCommand) commands.iterator().next()).version));
}
Aggregations