From a842f3e92cbe7c9a99f72567af19b8f7c4ce7e82 Mon Sep 17 00:00:00 2001 From: erobot Date: Mon, 4 Dec 2023 11:46:02 +0800 Subject: [PATCH] Fix a slow gc thread shutdown when compacting (#4127) Descriptions of the changes in this PR: ### Motivation Fix a slow gc thread shutdown when compacting. The problem here is that the stop flag `running` has been moved after `compacting.compareAndSet`. When `running` is not set to false, entry log continues to compact one after one and the shutdown thread is hard to set the `compacting`. ### Changes Set `running` to false first and then check `compacting`. Master Issue: #4126 --- .../org/apache/bookkeeper/bookie/GarbageCollectorThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java index d5cde9b4343..bc55af1fe2a 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/GarbageCollectorThread.java @@ -679,6 +679,7 @@ public synchronized void shutdown() throws InterruptedException { if (!this.running) { return; } + this.running = false; LOG.info("Shutting down GarbageCollectorThread"); throttler.cancelledAcquire(); @@ -688,7 +689,6 @@ public synchronized void shutdown() throws InterruptedException { Thread.sleep(100); } - this.running = false; // Interrupt GC executor thread gcExecutor.shutdownNow(); try {