Skip to content

Commit 560ace4

Browse files
committed
Fix core dumps triggered by rocksdb compacting when shutdown bk
1 parent 44607a0 commit 560ace4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Map.Entry;
2727
import java.util.Set;
2828
import java.util.concurrent.TimeUnit;
29+
import java.util.concurrent.atomic.AtomicBoolean;
30+
2931
import org.apache.bookkeeper.bookie.Bookie;
3032
import org.apache.bookkeeper.bookie.EntryLocation;
3133
import org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorage.Batch;
@@ -48,7 +50,7 @@ public class EntryLocationIndex implements Closeable {
4850
private final KeyValueStorage locationsDb;
4951
private final ConcurrentLongHashSet deletedLedgers = ConcurrentLongHashSet.newBuilder().build();
5052
private final EntryLocationIndexStats stats;
51-
private boolean isCompacting;
53+
private final AtomicBoolean compacting = new AtomicBoolean(false);
5254

5355
public EntryLocationIndex(ServerConfiguration conf, KeyValueStorageFactory storageFactory, String basePath,
5456
StatsLogger stats) throws IOException {
@@ -203,15 +205,21 @@ public String getEntryLocationDBPath() {
203205

204206
public void compact() throws IOException {
205207
try {
206-
isCompacting = true;
208+
if (!compacting.compareAndSet(false, true)) {
209+
return;
210+
}
207211
locationsDb.compact();
208212
} finally {
209-
isCompacting = false;
213+
compacting.set(false);
210214
}
211215
}
212216

213217
public boolean isCompacting() {
214-
return isCompacting;
218+
return compacting.get();
219+
}
220+
221+
public boolean compareAndSetCompacting(boolean expectedValue, boolean newValue) {
222+
return compacting.compareAndSet(expectedValue, newValue);
215223
}
216224

217225
public void removeOffsetFromDeletedLedgers() throws IOException {

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ public List<String> getEntryLocationDBPath() {
346346
public void shutdown() throws InterruptedException {
347347
try {
348348
flush();
349-
349+
while (!entryLocationIndex.compareAndSetCompacting(false, true)) {
350+
Thread.sleep(100);
351+
}
350352
gcThread.shutdown();
351353
entryLogger.close();
352354

0 commit comments

Comments
 (0)