use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.
the class StatementOperationsTestHelper method mockedState.
public static KernelStatement mockedState(final TransactionState txState) {
KernelStatement state = mock(KernelStatement.class);
Locks.Client locks = mock(Locks.Client.class);
try {
IndexReader indexReader = mock(IndexReader.class);
when(indexReader.query(Matchers.isA(IndexQuery.ExactPredicate.class))).thenReturn(PrimitiveLongCollections.emptyIterator());
StorageStatement storageStatement = mock(StorageStatement.class);
when(storageStatement.getIndexReader(Matchers.any())).thenReturn(indexReader);
when(state.getStoreStatement()).thenReturn(storageStatement);
} catch (IndexNotFoundKernelException | IndexNotApplicableKernelException e) {
throw new Error(e);
}
when(state.txState()).thenReturn(txState);
when(state.hasTxStateWithChanges()).thenAnswer(invocation -> txState.hasChanges());
when(state.locks()).thenReturn(new SimpleStatementLocks(locks));
when(state.readOperations()).thenReturn(mock(ReadOperations.class));
return state;
}
use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.
the class DirectNonUniqueIndexSampler method result.
@Override
public IndexSample result() {
try {
// lucene index needs to be flushed to be sure that reader will see all the data :(
luceneIndex.flush();
luceneIndex.maybeRefreshBlocking();
try (IndexReader indexReader = luceneIndex.getIndexReader()) {
IndexSampler sampler = indexReader.createSampler();
return sampler.sampleIndex();
} catch (IOException | IndexNotFoundKernelException e) {
throw new RuntimeException(e);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method validateNoExistingNodeWithExactValues.
private void validateNoExistingNodeWithExactValues(KernelStatement state, UniquenessConstraintDescriptor constraint, ExactPredicate[] propertyValues, long modifiedNode) throws ConstraintValidationException {
try {
NewIndexDescriptor index = constraint.ownedIndexDescriptor();
assertIndexOnline(state, index);
int labelId = index.schema().getLabelId();
state.locks().optimistic().acquireExclusive(state.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelId, propertyValues));
long existing = entityReadOperations.nodeGetFromUniqueIndexSeek(state, index, propertyValues);
if (existing != NO_SUCH_NODE && existing != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(existing, NO_SUCH_NODE, OrderedPropertyValues.of(propertyValues)));
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e);
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.
the class Schema method sampleIndexes.
private void sampleIndexes(Label[] labels, String property, boolean sampleAll, boolean forceSample) throws ShellException {
IndexingService indexingService = getServer().getDb().getDependencyResolver().resolveDependency(IndexingService.class);
if (indexingService == null) {
throw new ShellException("Internal error: failed to resolve IndexingService");
}
IndexSamplingMode samplingMode = getSamplingMode(forceSample);
// Trigger sampling for all indices
if (sampleAll) {
indexingService.triggerIndexSampling(samplingMode);
return;
}
validateLabelsAndProperty(labels, property);
Statement statement = getServer().getStatement();
int labelKey = statement.readOperations().labelGetForName(labels[0].name());
int propertyKey = statement.readOperations().propertyKeyGetForName(property);
if (labelKey == -1) {
throw new ShellException("No label associated with '" + labels[0].name() + "' was found");
}
if (propertyKey == -1) {
throw new ShellException("No property associated with '" + property + "' was found");
}
try {
indexingService.triggerIndexSampling(SchemaDescriptorFactory.forLabel(labelKey, propertyKey), samplingMode);
} catch (IndexNotFoundKernelException e) {
throw new ShellException(e.getMessage());
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.
the class BuiltInProcedures method listIndexes.
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ)
public Stream<IndexResult> listIndexes() throws ProcedureException {
try (Statement statement = tx.acquireStatement()) {
ReadOperations operations = statement.readOperations();
TokenNameLookup tokens = new StatementTokenNameLookup(operations);
List<NewIndexDescriptor> indexes = asList(operations.indexesGetAll());
Set<NewIndexDescriptor> uniqueIndexes = asSet(operations.uniqueIndexesGetAll());
indexes.addAll(uniqueIndexes);
indexes.sort(Comparator.comparing(a -> a.userDescription(tokens)));
ArrayList<IndexResult> result = new ArrayList<>();
for (NewIndexDescriptor index : indexes) {
try {
String type;
if (uniqueIndexes.contains(index)) {
type = IndexType.NODE_UNIQUE_PROPERTY.typeName();
} else {
type = IndexType.NODE_LABEL_PROPERTY.typeName();
}
result.add(new IndexResult("INDEX ON " + index.schema().userDescription(tokens), operations.indexGetState(index).toString(), type));
} catch (IndexNotFoundKernelException e) {
throw new ProcedureException(Status.Schema.IndexNotFound, e, "No index on ", index.userDescription(tokens));
}
}
return result.stream();
}
}
Aggregations