Skip to content

Commit

Permalink
Use Optional instead nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
losipiuk committed Apr 9, 2022
1 parent 5b37ed2 commit 3af4343
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class ClusterMemoryManager
private long lastTimeNotOutOfMemory = System.nanoTime();

@GuardedBy("this")
private KillTarget lastKillTarget;
private Optional<KillTarget> lastKillTarget = Optional.empty();

@Inject
public ClusterMemoryManager(
Expand Down Expand Up @@ -269,7 +269,7 @@ private synchronized void callOomKiller(Iterable<QueryExecution> runningQueries)
// See comments in isQueryGone for why chosenQuery might be absent.
chosenQuery.get().fail(new TrinoException(CLUSTER_OUT_OF_MEMORY, "Query killed because the cluster is out of memory. Please try again in a few minutes."));
queriesKilledDueToOutOfMemory.incrementAndGet();
lastKillTarget = killTarget.get();
lastKillTarget = killTarget;
logQueryKill(queryId, nodeMemoryInfosByNode);
}
}
Expand All @@ -288,7 +288,7 @@ private synchronized void callOomKiller(Iterable<QueryExecution> runningQueries)
// only record tasks actually killed
ImmutableSet<TaskId> killedTasks = killedTasksBuilder.build();
if (!killedTasks.isEmpty()) {
lastKillTarget = KillTarget.selectedTasks(killedTasks);
lastKillTarget = Optional.of(KillTarget.selectedTasks(killedTasks));
logTasksKill(killedTasks, nodeMemoryInfosByNode);
}
}
Expand All @@ -298,15 +298,15 @@ private synchronized void callOomKiller(Iterable<QueryExecution> runningQueries)
@GuardedBy("this")
private boolean isLastKillTargetGone(Iterable<QueryExecution> runningQueries)
{
if (lastKillTarget == null) {
if (lastKillTarget.isEmpty()) {
return true;
}

if (lastKillTarget.isWholeQuery()) {
return isQueryGone(lastKillTarget.getQuery());
if (lastKillTarget.get().isWholeQuery()) {
return isQueryGone(lastKillTarget.get().getQuery());
}

return areTasksGone(lastKillTarget.getTasks(), runningQueries);
return areTasksGone(lastKillTarget.get().getTasks(), runningQueries);
}

private boolean isQueryGone(QueryId killedQuery)
Expand All @@ -316,7 +316,7 @@ private boolean isQueryGone(QueryId killedQuery)
// Even if the weak references to the leaked queries are GCed in the ClusterMemoryLeakDetector, it will mark the same queries
// as leaked in its next run, and eventually the ClusterMemoryManager will make progress.
if (memoryLeakDetector.wasQueryPossiblyLeaked(killedQuery)) {
lastKillTarget = null;
lastKillTarget = Optional.empty();
return true;
}

Expand Down

0 comments on commit 3af4343

Please sign in to comment.