use of org.neo4j.dbms.database.DatabaseContext in project neo4j by neo4j.
the class DatabaseAvailabilityIT method restartedDatabaseIsAvailable.
@Test
void restartedDatabaseIsAvailable() {
DependencyResolver dependencyResolver = database.getDependencyResolver();
DatabaseManager<?> databaseManager = getDatabaseManager(dependencyResolver);
DatabaseContext databaseContext = databaseManager.getDatabaseContext(defaultNamedDatabaseId).get();
Database database = databaseContext.database();
executeTransactionOnDefaultDatabase();
database.stop();
assertThrows(DatabaseShutdownException.class, () -> this.database.beginTx());
database.start();
executeTransactionOnDefaultDatabase();
}
use of org.neo4j.dbms.database.DatabaseContext in project neo4j by neo4j.
the class DatabaseAvailabilityIT method stoppedDatabaseIsNotAvailable.
@Test
void stoppedDatabaseIsNotAvailable() {
DependencyResolver dependencyResolver = database.getDependencyResolver();
DatabaseManager<?> databaseManager = getDatabaseManager(dependencyResolver);
DatabaseContext databaseContext = databaseManager.getDatabaseContext(defaultNamedDatabaseId).get();
databaseContext.database().stop();
assertThrows(DatabaseShutdownException.class, () -> database.beginTx());
}
use of org.neo4j.dbms.database.DatabaseContext in project neo4j by neo4j.
the class DatabaseAvailabilityIT method anyOfDatabaseUnavailabilityIsGlobalUnavailability.
@Test
void anyOfDatabaseUnavailabilityIsGlobalUnavailability() {
AvailabilityRequirement outerSpaceRequirement = () -> "outer space";
DependencyResolver dependencyResolver = database.getDependencyResolver();
DatabaseManager<?> databaseManager = getDatabaseManager(dependencyResolver);
CompositeDatabaseAvailabilityGuard compositeGuard = dependencyResolver.resolveDependency(CompositeDatabaseAvailabilityGuard.class);
assertTrue(compositeGuard.isAvailable());
DatabaseContext systemContext = databaseManager.getDatabaseContext(NAMED_SYSTEM_DATABASE_ID).get();
DatabaseContext defaultContext = databaseManager.getDatabaseContext(defaultNamedDatabaseId).get();
AvailabilityGuard systemGuard = systemContext.dependencies().resolveDependency(DatabaseAvailabilityGuard.class);
systemGuard.require(outerSpaceRequirement);
assertFalse(compositeGuard.isAvailable());
systemGuard.fulfill(outerSpaceRequirement);
assertTrue(compositeGuard.isAvailable());
AvailabilityGuard defaultGuard = defaultContext.dependencies().resolveDependency(DatabaseAvailabilityGuard.class);
defaultGuard.require(outerSpaceRequirement);
assertFalse(compositeGuard.isAvailable());
defaultGuard.fulfill(outerSpaceRequirement);
assertTrue(compositeGuard.isAvailable());
}
use of org.neo4j.dbms.database.DatabaseContext in project neo4j by neo4j.
the class BuiltInDbmsProcedures method listTransactions.
@SystemProcedure
@Description("List all transactions currently executing at this instance that are visible to the user.")
@Procedure(name = "dbms.listTransactions", mode = DBMS)
public Stream<TransactionStatusResult> listTransactions() throws InvalidArgumentsException {
ZoneId zoneId = getConfiguredTimeZone();
List<TransactionStatusResult> result = new ArrayList<>();
for (DatabaseContext databaseContext : getDatabaseManager().registeredDatabases().values()) {
if (databaseContext.database().isStarted()) {
DatabaseScope dbScope = new DatabaseScope(databaseContext.database().getNamedDatabaseId().name());
Map<KernelTransactionHandle, Optional<QuerySnapshot>> handleQuerySnapshotsMap = new HashMap<>();
for (KernelTransactionHandle tx : getExecutingTransactions(databaseContext)) {
String username = tx.subject().username();
var action = new AdminActionOnResource(SHOW_TRANSACTION, dbScope, new UserSegment(username));
if (isSelfOrAllows(username, action)) {
handleQuerySnapshotsMap.put(tx, tx.executingQuery().map(ExecutingQuery::snapshot));
}
}
TransactionDependenciesResolver transactionBlockerResolvers = new TransactionDependenciesResolver(handleQuerySnapshotsMap);
for (KernelTransactionHandle tx : handleQuerySnapshotsMap.keySet()) {
result.add(new TransactionStatusResult(databaseContext.databaseFacade().databaseName(), tx, transactionBlockerResolvers, handleQuerySnapshotsMap, zoneId));
}
}
}
return result.stream();
}
use of org.neo4j.dbms.database.DatabaseContext 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();
}
Aggregations