use of org.neo4j.kernel.database.NamedDatabaseId in project neo4j by neo4j.
the class CommunityDatabaseStateProcedureTest method shouldReturnEmptyErrorForNoError.
@Test
void shouldReturnEmptyErrorForNoError() throws ProcedureException {
// given
var existing = idRepository.getRaw("existing");
Map<NamedDatabaseId, DatabaseState> states = Map.of(existing, new CommunityDatabaseState(existing, true, false, null));
var stateService = new StubDatabaseStateService(states, CommunityDatabaseState::unknown);
var procedure = procedure(stateService);
// when
var result = procedure.apply(mock(Context.class), new AnyValue[] { stringValue(existing.name()) }, mock(ResourceTracker.class));
var returned = Arrays.asList(result.next());
// then
assertEquals(4, returned.size(), "Procedure result should have 4 columns: role, address, state and error message");
var roleColumn = stringValue("standalone");
var addressColumn = stringValue("localhost:7687");
var statusColumn = stringValue("online");
var errorColumn = stringValue("");
assertEquals(Arrays.asList(roleColumn, addressColumn, statusColumn, errorColumn), returned, "Error column should be empty");
}
use of org.neo4j.kernel.database.NamedDatabaseId in project neo4j by neo4j.
the class BookmarksParserV4 method parseBookmarks.
private List<Bookmark> parseBookmarks(ListValue bookmarks) throws BookmarkParsingException {
var maxSystemDbTxId = ABSENT_BOOKMARK_ID;
NamedDatabaseId userDbId = null;
var maxUserDbTxId = ABSENT_BOOKMARK_ID;
List<String> customBookmarkStrings = new ArrayList<>();
for (var bookmark : bookmarks) {
if (bookmark != Values.NO_VALUE) {
var bookmarkString = toBookmarkString(bookmark);
if (customBookmarkFormatParser.isCustomBookmark(bookmarkString)) {
customBookmarkStrings.add(bookmarkString);
} else {
var parsedBookmark = parse(bookmarkString);
if (NAMED_SYSTEM_DATABASE_ID.equals(parsedBookmark.namedDatabaseId)) {
maxSystemDbTxId = Math.max(maxSystemDbTxId, parsedBookmark.txId);
} else {
if (userDbId == null) {
userDbId = parsedBookmark.namedDatabaseId;
} else {
assertSameDatabaseId(userDbId, parsedBookmark.namedDatabaseId, bookmarks);
}
maxUserDbTxId = Math.max(maxUserDbTxId, parsedBookmark.txId);
}
}
}
}
if (customBookmarkStrings.isEmpty()) {
return buildBookmarks(NAMED_SYSTEM_DATABASE_ID, maxSystemDbTxId, userDbId, maxUserDbTxId);
}
List<Bookmark> customBookmarks;
try {
customBookmarks = customBookmarkFormatParser.parse(customBookmarkStrings);
} catch (Exception e) {
throw BookmarkParsingException.newInvalidBookmarkError("Parsing of supplied bookmarks failed with message: " + e.getMessage(), e);
}
if (maxSystemDbTxId != ABSENT_BOOKMARK_ID) {
customBookmarks.add(new BookmarkWithDatabaseId(maxSystemDbTxId, NAMED_SYSTEM_DATABASE_ID));
}
if (maxUserDbTxId != ABSENT_BOOKMARK_ID) {
customBookmarks.add(new BookmarkWithDatabaseId(maxUserDbTxId, userDbId));
}
return customBookmarks;
}
use of org.neo4j.kernel.database.NamedDatabaseId 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();
}
Aggregations