Skip to content

[fix][meta] Track explicitly acquired underreplicated ledger locks - #26670

Open
void-ptr974 wants to merge 1 commit into
apache:masterfrom
void-ptr974:fix/bk-explicit-underreplication-locks
Open

void-ptr974 wants to merge 1 commit into
apache:masterfrom
void-ptr974:fix/bk-explicit-underreplication-locks

Conversation

@void-ptr974

Copy link
Copy Markdown
Contributor

Motivation

PulsarLedgerUnderreplicationManager.acquireUnderreplicatedLedger() creates an ephemeral lock but does not register it in heldLocks. Both releaseUnderreplicatedLedger() and close() rely on that map, so an explicitly acquired lock remains after the caller releases or closes the manager. Other managers continue to treat the ledger as locked, particularly when the metadata store is shared and its session remains open.

Explicit acquisition is also used for mutual exclusion without claiming a pending underreplication task. Tracking these locks must not allow markLedgerReplicated() to delete a task that the caller did not obtain through the replication queue.

Modifications

  • Register explicitly acquired locks only after acquisition succeeds.
  • Represent the underreplication record version as Optional<Long>, following the native BookKeeper distinction between an explicit lock and a lock acquired with a task version.
  • Keep the actual version for poll/get acquisition. Only delete an underreplication record when that version is present; explicit locks are still released in the existing finally block.
  • Add six regression tests covering explicit release, close with a shared live store, marking with/without an existing record, failed contenders, and a failed duplicate acquisition preserving a previously polled record version.

Verifying this change

Before the fix, the new tests produced 8 failures across Memory and real ZooKeeper because explicitly acquired locks remained after release/close/mark. The 4 failed-acquisition protection cases passed on the original implementation.

Post-fix validation, with automatic retries disabled and no failed or skipped tests:

  • macOS / JDK 25: 40 cases passed across Memory, real ZooKeeper, MockZooKeeper and RocksDB. This includes the six new tests and existing locking, release, task completion and record updates while a task is locked.
  • Linux x86_64 / JDK 21 / Docker: all 117 cases in LedgerUnderreplicationManagerTest passed, including all five providers and real Oxia. This includes 30 new regression cases and 87 existing cases, including multiple managers acquiring and releasing locks.
  • quickCheck and sanityCheck passed, covering repository-wide license/style checks and main/test source compilation.

Full underreplication manager suite on Linux with Docker:

TEST_METADATA_PROVIDERS=Memory,ZooKeeper,MockZooKeeper,RocksDB,Oxia ./gradlew :pulsar-metadata:test \
  --tests 'org.apache.pulsar.metadata.bookkeeper.LedgerUnderreplicationManagerTest' \
  -PtestRetryCount=0 -PtestFailFast=false --max-workers=4 --console=plain

Does this pull request potentially affect one of the following parts:

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Register explicit locks after successful acquisition so release and close
can remove them while a shared metadata store remains open. Distinguish
these locks from polled tasks with an optional underreplication record
version, preventing explicit acquisition from authorizing task deletion.

Cover release, shared-store close, record preservation, failed contenders,
and preservation of a polled version after a failed duplicate acquisition.

Assisted-by: Codex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants