use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class SchemaImpl method awaitIndexesOnline.
private boolean awaitIndexesOnline(Iterable<IndexDescriptor> indexes, Function<IndexDescriptor, String> describe, long duration, TimeUnit unit, boolean bubbleNotFound) {
Stopwatch startTime = Stopwatch.start();
do {
boolean allOnline = true;
SchemaRead schemaRead = transaction.schemaRead();
for (IndexDescriptor index : indexes) {
if (index == IndexDescriptor.NO_INDEX) {
allOnline = false;
break;
}
try {
InternalIndexState indexState = schemaRead.indexGetState(index);
if (indexState == InternalIndexState.POPULATING) {
allOnline = false;
break;
}
if (indexState == InternalIndexState.FAILED) {
String cause = schemaRead.indexGetFailure(index);
String message = "Index " + describe.apply(index) + " entered a " + indexState + " state. Please see database logs.";
message = IndexPopulationFailure.appendCauseOfFailure(message, cause);
throw new IllegalStateException(message);
}
} catch (IndexNotFoundKernelException e) {
if (bubbleNotFound) {
throw newIndexNotFoundException(descriptorToDefinition(transaction.tokenRead(), index), e);
}
// Weird that the index vanished, but we'll just wait and see if it comes back until we time out.
allOnline = false;
break;
}
}
if (allOnline) {
return false;
}
sleepIgnoreInterrupt();
} while (!startTime.hasTimedOut(duration, unit));
return true;
}
use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class SchemaImpl method getIndexState.
@Override
public IndexState getIndexState(final IndexDefinition index) {
try {
transaction.assertOpen();
SchemaRead schemaRead = transaction.schemaRead();
IndexDescriptor reference = getIndexReference(schemaRead, transaction.tokenRead(), (IndexDefinitionImpl) index);
InternalIndexState indexState = schemaRead.indexGetState(reference);
switch(indexState) {
case POPULATING:
return POPULATING;
case ONLINE:
return ONLINE;
case FAILED:
return FAILED;
default:
throw new IllegalArgumentException(String.format("Illegal index state %s", indexState));
}
} catch (KernelException e) {
throw newIndexNotFoundException(index, e);
}
}
use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class SchemaImpl method getIndexes.
@Override
public Iterable<IndexDefinition> getIndexes(RelationshipType relationshipType) {
transaction.assertOpen();
TokenRead tokenRead = transaction.tokenRead();
SchemaRead schemaRead = transaction.schemaRead();
List<IndexDefinition> definitions = new ArrayList<>();
int relationshipTypeId = tokenRead.relationshipType(relationshipType.name());
if (relationshipTypeId == TokenRead.NO_TOKEN) {
return emptyList();
}
Iterator<IndexDescriptor> indexes = schemaRead.indexesGetForRelationshipType(relationshipTypeId);
addDefinitions(definitions, tokenRead, IndexDescriptor.sortByType(indexes));
return definitions;
}
use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class KernelTransactionAssertOpenTest method shouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations.
@ParameterizedTest
@MethodSource("parameters")
void shouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations(String name, Operation transactionOperation) throws KernelException {
KernelTransaction transaction = newTransaction(AnonymousContext.write());
Read read = transaction.dataRead();
Write write = transaction.dataWrite();
SchemaRead schemaRead = transaction.schemaRead();
transaction.commit();
assertThrows(NotInTransactionException.class, () -> transactionOperation.operate(read, write, schemaRead));
}
use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class IndexIT method addIndexRuleInATransaction.
@Test
void addIndexRuleInATransaction() throws Exception {
// GIVEN
SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction();
// WHEN
IndexDescriptor expectedRule = schemaWriteOperations.indexCreate(schema, "my index");
commit();
// THEN
SchemaRead schemaRead = newTransaction().schemaRead();
assertEquals(asSet(expectedRule), asSet(schemaRead.indexesGetForLabel(labelId)));
assertEquals(expectedRule, Iterators.single(schemaRead.index(schema)));
commit();
}
Aggregations