Skip to content

Commit bc91be9

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

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ public void shutdown() throws InterruptedException {
347347
try {
348348
flush();
349349

350+
while (!entryLocationIndex.compareAndSetCompacting(false, true)) {
351+
Thread.sleep(100);
352+
}
350353
gcThread.shutdown();
351354
entryLogger.close();
352355

0 commit comments

Comments
 (0)