use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInDbmsProcedures method listQueries.
@SystemProcedure
@Description("List all queries currently executing at this instance that are visible to the user.")
@Procedure(name = "dbms.listQueries", mode = DBMS)
public Stream<QueryStatusResult> listQueries() throws InvalidArgumentsException {
ZoneId zoneId = getConfiguredTimeZone();
List<QueryStatusResult> result = new ArrayList<>();
for (FabricTransaction tx : getFabricTransactions()) {
for (ExecutingQuery query : getActiveFabricQueries(tx)) {
String username = query.username();
var action = new AdminActionOnResource(SHOW_TRANSACTION, ALL, new UserSegment(username));
if (isSelfOrAllows(username, action)) {
result.add(new QueryStatusResult(query, (InternalTransaction) transaction, zoneId, "none"));
}
}
}
for (DatabaseContext databaseContext : getDatabaseManager().registeredDatabases().values()) {
if (databaseContext.database().isStarted()) {
DatabaseScope dbScope = new DatabaseScope(databaseContext.database().getNamedDatabaseId().name());
for (KernelTransactionHandle tx : getExecutingTransactions(databaseContext)) {
if (tx.executingQuery().isPresent()) {
ExecutingQuery query = tx.executingQuery().get();
// Include both the executing query and any previous queries (parent queries of nested query) in the result.
while (query != null) {
String username = query.username();
var action = new AdminActionOnResource(SHOW_TRANSACTION, dbScope, new UserSegment(username));
if (isSelfOrAllows(username, action)) {
result.add(new QueryStatusResult(query, (InternalTransaction) transaction, zoneId, databaseContext.databaseFacade().databaseName()));
}
query = query.getPreviousQuery();
}
}
}
}
}
return result.stream();
}
use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInDbmsProcedures method killTransactions.
@SystemProcedure
@Description("Kill transactions with provided ids.")
@Procedure(name = "dbms.killTransactions", mode = DBMS)
public Stream<TransactionMarkForTerminationResult> killTransactions(@Name("ids") List<String> transactionIds) throws InvalidArgumentsException {
requireNonNull(transactionIds);
log.warn("User %s trying to kill transactions: %s.", securityContext.subject().username(), transactionIds.toString());
DatabaseManager<DatabaseContext> databaseManager = getDatabaseManager();
DatabaseIdRepository databaseIdRepository = databaseManager.databaseIdRepository();
Map<NamedDatabaseId, Set<TransactionId>> byDatabase = new HashMap<>();
for (String idText : transactionIds) {
TransactionId id = TransactionId.parse(idText);
Optional<NamedDatabaseId> namedDatabaseId = databaseIdRepository.getByName(id.database());
namedDatabaseId.ifPresent(databaseId -> byDatabase.computeIfAbsent(databaseId, ignore -> new HashSet<>()).add(id));
}
Map<String, KernelTransactionHandle> handles = new HashMap<>(transactionIds.size());
for (Map.Entry<NamedDatabaseId, Set<TransactionId>> entry : byDatabase.entrySet()) {
NamedDatabaseId databaseId = entry.getKey();
var dbScope = new DatabaseScope(databaseId.name());
Optional<DatabaseContext> maybeDatabaseContext = databaseManager.getDatabaseContext(databaseId);
if (maybeDatabaseContext.isPresent()) {
Set<TransactionId> txIds = entry.getValue();
DatabaseContext databaseContext = maybeDatabaseContext.get();
for (KernelTransactionHandle tx : getExecutingTransactions(databaseContext)) {
String username = tx.subject().username();
var action = new AdminActionOnResource(TERMINATE_TRANSACTION, dbScope, new UserSegment(username));
if (!isSelfOrAllows(username, action)) {
continue;
}
TransactionId txIdRepresentation = new TransactionId(databaseId.name(), tx.getUserTransactionId());
if (txIds.contains(txIdRepresentation)) {
handles.put(txIdRepresentation.toString(), tx);
}
}
}
}
return transactionIds.stream().map(id -> terminateTransaction(handles, id));
}
use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInProcedures method schemaStatements.
@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("List all statements for creating and dropping existing indexes and constraints. " + "Note that only index types introduced before Neo4j 4.3 are included.")
@Procedure(name = "db.schemaStatements", mode = READ, deprecatedBy = "SHOW INDEXES YIELD * command and SHOW CONSTRAINTS YIELD * command")
public Stream<SchemaStatementResult> schemaStatements() throws ProcedureException {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
final TokenRead tokenRead = kernelTransaction.tokenRead();
return SchemaStatementProcedure.createSchemaStatementResults(schemaRead, tokenRead).stream();
}
use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInProcedures method createUniquePropertyConstraint.
@Deprecated(since = "4.2.0", forRemoval = true)
@Description("Create a named unique property constraint. Backing index will use specified index provider and configuration (optional). " + "Yield: name, labels, properties, providerName, status")
@Procedure(name = "db.createUniquePropertyConstraint", mode = SCHEMA, deprecatedBy = "CREATE CONSTRAINT ... IS UNIQUE command")
public Stream<SchemaIndexInfo> createUniquePropertyConstraint(@Name("constraintName") String constraintName, @Name("labels") List<String> labels, @Name("properties") List<String> properties, @Name("providerName") String providerName, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws ProcedureException {
IndexProcedures indexProcedures = indexProcedures();
final IndexProviderDescriptor indexProviderDescriptor = getIndexProviderDescriptor(providerName);
return indexProcedures.createUniquePropertyConstraint(constraintName, labels, properties, indexProviderDescriptor, config);
}
use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInProcedures method listRelationshipTypes.
@SystemProcedure
@Description("List all available relationship types in the database.")
@Procedure(name = "db.relationshipTypes", mode = READ)
public Stream<RelationshipTypeResult> listRelationshipTypes() {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
AccessMode mode = kernelTransaction.securityContext().mode();
TokenRead tokenRead = kernelTransaction.tokenRead();
List<RelationshipTypeResult> relTypesInUse;
try (KernelTransaction.Revertable ignore = kernelTransaction.overrideWith(SecurityContext.AUTH_DISABLED)) {
// Get all relTypes that are in use as seen by a super user
relTypesInUse = stream(RELATIONSHIP_TYPES.inUse(kernelTransaction)).filter(type -> mode.allowsTraverseRelType(tokenRead.relationshipType(type.name()))).map(RelationshipTypeResult::new).collect(Collectors.toList());
}
return relTypesInUse.stream();
}
Aggregations