use of org.neo4j.exceptions.KernelException 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.exceptions.KernelException in project neo4j by neo4j.
the class TransactionImpl method nodesByLabelAndProperties.
private ResourceIterator<Node> nodesByLabelAndProperties(KernelTransaction transaction, int labelId, PropertyIndexQuery.ExactPredicate... queries) {
Read read = transaction.dataRead();
if (isInvalidQuery(labelId, queries)) {
return emptyResourceIterator();
}
int[] propertyIds = getPropertyIds(queries);
IndexDescriptor index = findUsableMatchingCompositeIndex(transaction, SchemaDescriptor.forLabel(labelId, propertyIds), propertyIds, () -> transaction.schemaRead().indexesGetForLabel(labelId));
if (index != IndexDescriptor.NO_INDEX) {
try {
NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker());
IndexReadSession indexSession = read.indexReadSession(index);
read.nodeIndexSeek(indexSession, cursor, unconstrained(), getReorderedIndexQueries(index.schema().getPropertyIds(), queries));
return new CursorIterator<>(cursor, NodeIndexCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
} catch (KernelException e) {
// weird at this point but ignore and fallback to a label scan
}
}
return getNodesByLabelAndPropertyWithoutPropertyIndex(transaction, labelId, queries);
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class TransactionImpl method nodesByLabelAndProperty.
private ResourceIterator<Node> nodesByLabelAndProperty(KernelTransaction transaction, int labelId, PropertyIndexQuery query) {
Read read = transaction.dataRead();
if (query.propertyKeyId() == TokenRead.NO_TOKEN || labelId == TokenRead.NO_TOKEN) {
return emptyResourceIterator();
}
var index = findUsableMatchingIndex(transaction, SchemaDescriptor.forLabel(labelId, query.propertyKeyId()));
if (index != IndexDescriptor.NO_INDEX) {
// Ha! We found an index - let's use it to find matching nodes
try {
NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker());
IndexReadSession indexSession = read.indexReadSession(index);
read.nodeIndexSeek(indexSession, cursor, unconstrained(), query);
return new CursorIterator<>(cursor, NodeIndexCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
} catch (KernelException e) {
// weird at this point but ignore and fallback to a label scan
}
}
return getNodesByLabelAndPropertyWithoutPropertyIndex(transaction, labelId, query);
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class TransactionImpl method getNodesByLabelAndPropertyWithoutPropertyIndex.
private ResourceIterator<Node> getNodesByLabelAndPropertyWithoutPropertyIndex(KernelTransaction ktx, int labelId, PropertyIndexQuery... queries) {
var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.NODE));
if (index != IndexDescriptor.NO_INDEX) {
try {
var session = ktx.dataRead().tokenReadSession(index);
var cursor = ktx.cursors().allocateNodeLabelIndexCursor(ktx.cursorContext());
ktx.dataRead().nodeLabelScan(session, cursor, unconstrained(), new TokenPredicate(labelId));
var nodeCursor = ktx.cursors().allocateNodeCursor(ktx.cursorContext());
var propertyCursor = ktx.cursors().allocatePropertyCursor(ktx.cursorContext(), ktx.memoryTracker());
return new NodeLabelPropertyIterator(ktx.dataRead(), cursor, nodeCursor, propertyCursor, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker, queries);
} catch (KernelException e) {
// ignore, fallback to all node scan
}
}
return getNodesByLabelAndPropertyViaAllNodesScan(ktx, labelId, queries);
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class DatabaseManagementServiceFactory method setupProcedures.
/**
* Creates and registers the systems procedures, including those which belong to a particular edition.
* N.B. This method takes a {@link DatabaseManager} as an unused parameter *intentionally*, in
* order to enforce that the databaseManager must be constructed first.
*/
@SuppressWarnings("unused")
private static void setupProcedures(GlobalModule globalModule, AbstractEditionModule editionModule, DatabaseManager<?> databaseManager) {
Supplier<GlobalProcedures> procedureInitializer = () -> {
Config globalConfig = globalModule.getGlobalConfig();
Path proceduresDirectory = globalConfig.get(GraphDatabaseSettings.plugin_dir);
LogService logService = globalModule.getLogService();
Log internalLog = logService.getInternalLog(GlobalProcedures.class);
Log proceduresLog = logService.getUserLog(GlobalProcedures.class);
ProcedureConfig procedureConfig = new ProcedureConfig(globalConfig);
Edition neo4jEdition = globalModule.getDbmsInfo().edition;
SpecialBuiltInProcedures builtInProcedures = new SpecialBuiltInProcedures(Version.getNeo4jVersion(), neo4jEdition.toString());
GlobalProceduresRegistry globalProcedures = new GlobalProceduresRegistry(builtInProcedures, proceduresDirectory, internalLog, procedureConfig);
globalProcedures.registerType(Node.class, NTNode);
globalProcedures.registerType(NodeValue.class, NTNode);
globalProcedures.registerType(Relationship.class, NTRelationship);
globalProcedures.registerType(RelationshipValue.class, NTRelationship);
globalProcedures.registerType(org.neo4j.graphdb.Path.class, NTPath);
globalProcedures.registerType(PathValue.class, NTPath);
globalProcedures.registerType(Geometry.class, NTGeometry);
globalProcedures.registerType(Point.class, NTPoint);
globalProcedures.registerType(PointValue.class, NTPoint);
// Below components are not public API, but are made available for internal
// procedures to call, and to provide temporary workarounds for the following
// patterns:
// - Batch-transaction imports (GDAPI, needs to be real and passed to background processing threads)
// - Group-transaction writes (same pattern as above, but rather than splitting large transactions,
// combine lots of small ones)
// - Bleeding-edge performance (KernelTransaction, to bypass overhead of working with Core API)
globalProcedures.registerComponent(DependencyResolver.class, Context::dependencyResolver, false);
globalProcedures.registerComponent(KernelTransaction.class, ctx -> ctx.internalTransaction().kernelTransaction(), false);
globalProcedures.registerComponent(GraphDatabaseAPI.class, Context::graphDatabaseAPI, false);
globalProcedures.registerComponent(SystemGraphComponents.class, ctx -> globalModule.getSystemGraphComponents(), false);
globalProcedures.registerComponent(ValueMapper.class, Context::valueMapper, true);
// Register injected public API components
globalProcedures.registerComponent(Log.class, ctx -> proceduresLog, true);
globalProcedures.registerComponent(Transaction.class, new ProcedureTransactionProvider(), true);
globalProcedures.registerComponent(org.neo4j.procedure.TerminationGuard.class, new TerminationGuardProvider(), true);
globalProcedures.registerComponent(SecurityContext.class, Context::securityContext, true);
globalProcedures.registerComponent(ProcedureCallContext.class, Context::procedureCallContext, true);
globalProcedures.registerComponent(FulltextAdapter.class, ctx -> ctx.dependencyResolver().resolveDependency(FulltextAdapter.class), true);
globalProcedures.registerComponent(GraphDatabaseService.class, ctx -> new GraphDatabaseFacade((GraphDatabaseFacade) ctx.graphDatabaseAPI(), new ProcedureLoginContextTransformer(ctx)), true);
globalProcedures.registerComponent(DataCollector.class, ctx -> ctx.dependencyResolver().resolveDependency(DataCollector.class), false);
// Edition procedures
try {
editionModule.registerProcedures(globalProcedures, procedureConfig, globalModule, databaseManager);
} catch (KernelException e) {
internalLog.error("Failed to register built-in edition procedures at start up: " + e.getMessage());
}
globalModule.getGlobalLife().add(globalProcedures);
return globalProcedures;
};
GlobalProcedures procedures = tryResolveOrCreate(GlobalProcedures.class, globalModule.getExternalDependencyResolver(), procedureInitializer);
if (procedures instanceof Consumer) {
((Consumer) procedures).accept(procedureInitializer);
}
globalModule.getGlobalDependencies().satisfyDependency(procedures);
}
Aggregations