use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInDbmsProcedures method killQueries.
@SystemProcedure
@Description("Kill all transactions executing a query with any of the given query ids.")
@Procedure(name = "dbms.killQueries", mode = DBMS)
public Stream<QueryTerminationResult> killQueries(@Name("ids") List<String> idTexts) throws InvalidArgumentsException {
DatabaseManager<DatabaseContext> databaseManager = getDatabaseManager();
DatabaseIdRepository databaseIdRepository = databaseManager.databaseIdRepository();
Map<Long, QueryId> queryIds = new HashMap<>(idTexts.size());
for (String idText : idTexts) {
QueryId id = QueryId.parse(idText);
queryIds.put(id.internalId(), id);
}
List<QueryTerminationResult> result = new ArrayList<>(queryIds.size());
for (FabricTransaction tx : getFabricTransactions()) {
for (ExecutingQuery query : getActiveFabricQueries(tx)) {
QueryId givenQueryId = queryIds.remove(query.internalQueryId());
if (givenQueryId != null) {
result.add(killFabricQueryTransaction(givenQueryId, tx, query));
}
}
}
for (Map.Entry<NamedDatabaseId, DatabaseContext> databaseEntry : databaseManager.registeredDatabases().entrySet()) {
NamedDatabaseId databaseId = databaseEntry.getKey();
DatabaseContext databaseContext = databaseEntry.getValue();
if (databaseContext.database().isStarted()) {
for (KernelTransactionHandle tx : getExecutingTransactions(databaseContext)) {
if (tx.executingQuery().isPresent()) {
QueryId givenQueryId = queryIds.remove(tx.executingQuery().get().internalQueryId());
if (givenQueryId != null) {
result.add(killQueryTransaction(givenQueryId, tx, databaseId));
}
}
}
}
}
// Add error about the rest
for (QueryId queryId : queryIds.values()) {
result.add(new QueryFailedTerminationResult(queryId, "n/a", "No Query found with this id"));
}
return result.stream();
}
use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInDbmsProcedures method setTXMetaData.
@Description("Attaches a map of data to the transaction. The data will be printed when listing queries, and " + "inserted into the query log.")
@Procedure(name = "tx.setMetaData", mode = DBMS)
public void setTXMetaData(@Name(value = "data") Map<String, Object> data) {
int totalCharSize = data.entrySet().stream().mapToInt(e -> e.getKey().length() + ((e.getValue() != null) ? e.getValue().toString().length() : 0)).sum();
if (totalCharSize >= HARD_CHAR_LIMIT) {
throw new IllegalArgumentException(format("Invalid transaction meta-data, expected the total number of chars for " + "keys and values to be less than %d, got %d", HARD_CHAR_LIMIT, totalCharSize));
}
InternalTransaction internalTransaction = (InternalTransaction) this.transaction;
graph.getDependencyResolver().resolveDependency(TransactionManager.class).findTransactionContaining(internalTransaction).ifPresentOrElse(parent -> parent.setMetaData(data), () -> internalTransaction.setMetaData(data));
}
use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInDbmsProcedures method upgrade.
@Admin
@SystemProcedure
@Description("Upgrade the system database schema if it is not the current schema.")
@Procedure(name = "dbms.upgrade", mode = WRITE)
public Stream<SystemGraphComponentUpgradeResult> upgrade() throws ProcedureException {
if (!callContext.isSystemDatabase()) {
throw new ProcedureException(ProcedureCallFailed, "This is an administration command and it should be executed against the system database: dbms.upgrade");
}
SystemGraphComponents versions = systemGraphComponents;
SystemGraphComponent.Status status = versions.detect(transaction);
// New components are not currently initialised in cluster deployment when new binaries are booted on top of an existing database.
// This is a known shortcoming of the lifecycle and a state transfer from UNINITIALIZED to CURRENT must be supported
// as a workaround until it is fixed.
var upgradableStatuses = List.of(REQUIRES_UPGRADE, UNINITIALIZED);
if (upgradableStatuses.contains(status)) {
ArrayList<String> failed = new ArrayList<>();
versions.forEach(component -> {
SystemGraphComponent.Status initialStatus = component.detect(transaction);
if (upgradableStatuses.contains(initialStatus)) {
try {
component.upgradeToCurrent(graph);
} catch (Exception e) {
failed.add(String.format("[%s] %s", component.componentName(), e.getMessage()));
}
}
});
String upgradeResult = failed.isEmpty() ? "Success" : "Failed: " + String.join(", ", failed);
return Stream.of(new SystemGraphComponentUpgradeResult(versions.detect(transaction).name(), upgradeResult));
} else {
return Stream.of(new SystemGraphComponentUpgradeResult(status.name(), status.resolution()));
}
}
use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInDbmsProcedures method listConnections.
@SystemProcedure
@Description("List all accepted network connections at this instance that are visible to the user.")
@Procedure(name = "dbms.listConnections", mode = DBMS)
public Stream<ListConnectionResult> listConnections() {
NetworkConnectionTracker connectionTracker = getConnectionTracker();
ZoneId timeZone = getConfiguredTimeZone();
return connectionTracker.activeConnections().stream().filter(connection -> isAdminOrSelf(connection.username())).map(connection -> new ListConnectionResult(connection, timeZone));
}
use of org.neo4j.procedure.Description in project neo4j by neo4j.
the class BuiltInDbmsProcedures method listFunctions.
@Deprecated(since = "4.3.0", forRemoval = true)
@SystemProcedure
@Description("List all functions in the DBMS.")
@Procedure(name = "dbms.functions", mode = DBMS, deprecatedBy = "SHOW FUNCTIONS command")
public Stream<FunctionResult> listFunctions() {
DependencyResolver resolver = graph.getDependencyResolver();
QueryExecutionEngine queryExecutionEngine = resolver.resolveDependency(QueryExecutionEngine.class);
List<FunctionInformation> providedLanguageFunctions = queryExecutionEngine.getProvidedLanguageFunctions();
var globalProcedures = resolver.resolveDependency(GlobalProcedures.class);
// gets you all functions provided by the query language
Stream<FunctionResult> languageFunctions = providedLanguageFunctions.stream().map(FunctionResult::new);
// gets you all non-aggregating functions that are registered in the db (incl. those from libs like apoc)
Stream<FunctionResult> loadedFunctions = globalProcedures.getAllNonAggregatingFunctions().map(f -> new FunctionResult(f, false));
// gets you all aggregation functions that are registered in the db (incl. those from libs like apoc)
Stream<FunctionResult> loadedAggregationFunctions = globalProcedures.getAllAggregatingFunctions().map(f -> new FunctionResult(f, true));
return Stream.concat(Stream.concat(languageFunctions, loadedFunctions), loadedAggregationFunctions).sorted(Comparator.comparing(a -> a.name));
}
Aggregations