Skip to content
Open
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 @@ -69,8 +69,8 @@ public class ProcedureExecutor<Env> {
new ThreadGroup(ThreadName.CONFIG_NODE_PROCEDURE_WORKER.getName());

// Metrics may be scraped before init() and concurrently with initialization during a ConfigNode
// leader transition.
private volatile CopyOnWriteArrayList<WorkerThread> workerThreads;
// leader transition, so keep an always-present thread-safe list.
private final CopyOnWriteArrayList<WorkerThread> workerThreads = new CopyOnWriteArrayList<>();

private TimeoutExecutorThread<Env> timeoutExecutor;

Expand Down Expand Up @@ -132,7 +132,7 @@ public void init(int numThreads) {
new TimeoutExecutorThread<>(
this, threadGroup, ThreadName.CONFIG_NODE_WORKER_THREAD_MONITOR.getName());
workId.set(0);
workerThreads = new CopyOnWriteArrayList<>();
workerThreads.clear();
for (int i = 0; i < corePoolSize; i++) {
workerThreads.add(new WorkerThread(threadGroup));
}
Expand Down Expand Up @@ -1028,15 +1028,11 @@ protected void periodicExecute(Env env) {
}

public int getWorkerThreadCount() {
final CopyOnWriteArrayList<WorkerThread> workers = workerThreads;
return workers == null ? 0 : workers.size();
return workerThreads.size();
}

public long getActiveWorkerThreadCount() {
final CopyOnWriteArrayList<WorkerThread> workers = workerThreads;
return workers == null
? 0
: workers.stream().filter(worker -> worker.activeProcedure.get() != null).count();
return workerThreads.stream().filter(worker -> worker.activeProcedure.get() != null).count();
}

public boolean isRunning() {
Expand Down
Loading