Skip to content

Commit

Permalink
Nullify DriverFactory#operatorFactories on noMoreDrivers
Browse files Browse the repository at this point in the history
It can happen that operator factories live longer than operators
what can cause that considerable amount of memory is not freed.
  • Loading branch information
radek authored and sopel39 committed Apr 26, 2024
1 parent 1d9e86e commit 0aadb15
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import io.trino.sql.planner.plan.PlanNodeId;
import jakarta.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -32,13 +33,13 @@ public class DriverFactory
private final int pipelineId;
private final boolean inputDriver;
private final boolean outputDriver;
private final List<OperatorFactory> operatorFactories;
private final Optional<PlanNodeId> sourceId;
private final OptionalInt driverInstances;

// must synchronize between createDriver() and noMoreDrivers(), but isNoMoreDrivers() is safe without synchronizing
@GuardedBy("this")
private volatile boolean noMoreDrivers;
private volatile List<OperatorFactory> operatorFactories;

public DriverFactory(int pipelineId, boolean inputDriver, boolean outputDriver, List<OperatorFactory> operatorFactories, OptionalInt driverInstances)
{
Expand Down Expand Up @@ -88,6 +89,7 @@ public OptionalInt getDriverInstances()
return driverInstances;
}

@Nullable
public List<OperatorFactory> getOperatorFactories()
{
return operatorFactories;
Expand Down Expand Up @@ -143,6 +145,7 @@ public synchronized void noMoreDrivers()
for (OperatorFactory operatorFactory : operatorFactories) {
operatorFactory.noMoreOperators();
}
operatorFactories = null;
noMoreDrivers = true;
}

Expand Down

0 comments on commit 0aadb15

Please sign in to comment.