Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public ListenableFuture<Void> createQuery(QueryId queryId, Span querySpan, Slug
requireNonNull(sessionContext, "sessionContext is null");
requireNonNull(query, "query is null");
checkArgument(!query.isEmpty(), "query must not be empty string");
checkArgument(queryTracker.tryGetQuery(queryId).isEmpty(), "query %s already exists", queryId);
checkArgument(!queryTracker.hasQuery(queryId), "query %s already exists", queryId);

// It is important to return a future implementation which ignores cancellation request.
// Using NonCancellationPropagatingFuture is not enough; it does not propagate cancel to wrapped future
Expand Down Expand Up @@ -295,7 +295,7 @@ public long getRunningQueries()

public boolean isQueryRegistered(QueryId queryId)
{
return queryTracker.tryGetQuery(queryId).isPresent();
return queryTracker.hasQuery(queryId);
}

public DispatchQuery getQuery(QueryId queryId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ QueryInfo getFullQueryInfo(QueryId queryId)
QueryState getQueryState(QueryId queryId)
throws NoSuchElementException;

boolean hasQuery(QueryId queryId);

/**
* Updates the client heartbeat time, to prevent the query from be automatically purged.
* If the query does not exist, the call is ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public T getQuery(QueryId queryId)
.orElseThrow(() -> new NoSuchElementException(queryId.toString()));
}

public boolean hasQuery(QueryId queryId)
{
requireNonNull(queryId, "queryId is null");
return queries.containsKey(queryId);
}

public Optional<T> tryGetQuery(QueryId queryId)
{
requireNonNull(queryId, "queryId is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ public QueryState getQueryState(QueryId queryId)
return queryTracker.getQuery(queryId).getState();
}

@Override
public boolean hasQuery(QueryId queryId)
{
return queryTracker.hasQuery(queryId);
}

@Override
public void recordHeartbeat(QueryId queryId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ public ExecutingStatementResource(
try {
for (QueryId queryId : queries.keySet()) {
// forget about this query if the query manager is no longer tracking it
try {
queryManager.getQueryState(queryId);
}
catch (NoSuchElementException e) {
// query is no longer registered
if (!queryManager.hasQuery(queryId)) {
Query query = queries.remove(queryId);
if (query != null) {
query.dispose();
Expand Down