🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

[Bug] Core dumps are triggered by rocksdb compacting when shutdown the bookkeeper #4705

Open

Description

@AnonHxy

BUG REPORT

Describe the bug

Core dumps are triggered rocksdb compacting when shutdown the bookkeeper process

[db-storage-cleanup-23-1:SingleDirectoryDbLedgerStorage@329] - Failed to trigger entry location index RocksDB compact
java.io.IOException: Error in RocksDB compact
    at org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageRocksDB.compact(KeyValueStorageRocksDB.java:415)
    at org.apache.bookkeeper.bookie.storage.ldb.EntryLocationIndex.compact(EntryLocationIndex.java:200)
    at org.apache.bookkeeper.bookie.storage.ldb.SingleDirectoryDbLedgerStorage.lambda$entryLocationCompact$6(SingleDirectoryDbLedgerStorage.java:327)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:833)
Caused by: org.rocksdb.RocksDBException: Database shutdown
    at org.rocksdb.RocksDB.compactRange(Native Method)
    at org.rocksdb.RocksDB.compactRange(RocksDB.java:3344)
    at org.rocksdb.RocksDB.compactRange(RocksDB.java:3319)
    at org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageRocksDB.compact(KeyValueStorageRocksDB.java:407)

To Reproduce

Steps to reproduce the behavior:

  1. Setting entryLocationCompactionInterval in bk_server.conf to enable entryLocationCompaction
  2. Start the bookkeeper
  3. Try to shutdown the bookkeeper when GarbageCollectorThread is running

Expected behavior

Bookkeeper process shutdown gracefully

Activity

  1. yangxianjungree commented on Aug 27, 2026

    @yangxianjungree

    We also hit shutdown crashes with entryLocationCompactionInterval enabled. Sharing what we observed; it looks related to this issue but is a different stack.

    The stack in the issue body is a caught RocksDBException: Database shutdown from entryLocationCompact → compactRange. In our environment the JVM SIGSEGV'd. The crashing thread was always db-storage-cleanup-* (the single-thread cleanupExecutor), and the Java frames were the checkpoint cleanup task queued on that executor, not compact:

    SingleDirectoryDbLedgerStorage.lambda$checkpoint$9
      → EntryLocationIndex.removeOffsetFromDeletedLedgers
          → RocksDBBatch.flush → RocksDB.write0          // locations DB
      // or
      → LedgerMetadataIndex.removeDeletedLedgers
          → KeyValueStorageRocksDB.delete → rocksdb_delete_helper  // ledgers DB
    

    What we saw:

    1. entryLocationCompact() submits a sync compactRange() onto cleanupExecutor and occupies that thread for a long time.
    2. checkpoint() / flush() finally submits a different task onto the same executor: removeOffsetFromDeletedLedgers() then removeDeletedLedgers(). That task sits in the ThreadPoolExecutor queue behind compact.
    3. SingleDirectoryDbLedgerStorage.shutdown() does cleanupExecutor.shutdown() + awaitTermination(1, SECONDS) (return value unused), then ledgerIndex.close() and entryLocationIndex.close().
    4. After compact's Java task returns, the queued checkpoint cleanup runs flush()/delete(). Those write paths are not covered by the closedLock that PR Fix the coredump that occurs when calling KeyValueStorageRocksDB.count after rocksdb has been closed #4581 added for count(). We then get a native write/delete vs close race. Compact widened the window; it was not the crashing frame.

    #4706 looks helpful for the compactRange vs close case in this issue. For our queued-checkpoint-cleanup SIGSEGV, we are not sure it would fix the scenario: close() waits on the compacting flag rather than draining cleanupExecutor, so after compact finishes the checkpoint cleanup task may still run, and ledgerIndex.close() still happens first. Happy to share more stacks if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions