Skip to content

Add an operation lease framework backed by ZooKeeper ephemeral nodes - #20381

Draft
J-HowHuang wants to merge 1 commit into
apache:masterfrom
J-HowHuang:pinot-operation-lease
Draft

J-HowHuang wants to merge 1 commit into
apache:masterfrom
J-HowHuang:pinot-operation-lease

Conversation

@J-HowHuang

@J-HowHuang J-HowHuang commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds an operation lease framework to pinot-common: an advisory, exclusive right to run one operation, held as an EPHEMERAL ZNode in the Helix property store. It lets replicas (or any other components) that would run the same work on a shared resource agree that one of them does it while the others wait for it, skip it, or do something else.

  • PinotOperationLeaseUtils: tryAcquire, awaitRelease (watch-based, no polling, bounded by a max wait), getLeaseInfo and forceRelease. A lease is named by a table and an opaque, caller-built key. The key becomes one ZNode under /OPERATION_LEASES/<tableNameWithType>/; the framework validates ZNode name rules and hashes keys over 1 KB (sha256-<hex>, with the full key kept in the node data). Each method also takes a full property store path, for a caller that keeps an existing ZNode.
  • PinotOperationLease (AutoCloseable): isHeld / checkOwnership compare the ZNode's ephemeral owner with the manager's current session, so a session expiry ends the lease on both sides. release is idempotent and never deletes a ZNode created by another session.
  • ZooKeeper errors are thrown, not swallowed, so each caller decides whether to do the work without a lease or skip it.
  • The lease is advisory: it saves duplicate work but does not fence a holder that stalls past its session timeout. What to do while a lease is held, and how to tell that an operation is done, are left to the caller.
  • PinotHelixResourceManager removes a table's lease directory when the table is deleted.

No existing code path takes a lease yet.

Testing

PinotOperationLeaseUtilsTest (13 tests, embedded ZooKeeper, one session per simulated instance): only one instance holds a lease; release lets another acquire and never deletes another session's lease; a session end releases the lease and a session change ends it; awaitRelease wakes on release and returns at once when free; acquire fails while disconnected; forceRelease on a missing lease; table deletion removes held leases; full-path leases; key validation and hashing of long keys.

@J-HowHuang J-HowHuang added extension-point Adds or modifies an extension/SPI point feature New functionality labels Nov 25, 2026
@J-HowHuang
J-HowHuang marked this pull request as draft November 25, 2026 03:32
@J-HowHuang
J-HowHuang force-pushed the pinot-operation-lease branch from 77aaa1a to b763bac Compare November 25, 2026 03:33
@codecov-commenter

codecov-commenter commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.78912% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.48%. Comparing base (38f0081) to head (b763bac).

Files with missing lines Patch % Lines
...e/pinot/common/lease/PinotOperationLeaseUtils.java 70.90% 25 Missing and 7 partials ⚠️
...apache/pinot/common/lease/PinotOperationLease.java 76.92% 5 Missing and 1 partial ⚠️
...ache/pinot/common/metadata/ZKMetadataProvider.java 71.42% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             master   #20381    +/-   ##
==========================================
  Coverage     71.47%   71.48%            
  Complexity     1639     1639            
==========================================
  Files          3615     3618     +3     
  Lines        244521   244668   +147     
  Branches      39767    39788    +21     
==========================================
+ Hits         174764   174891   +127     
- Misses        56572    56580     +8     
- Partials      13185    13197    +12     
Flag Coverage Δ
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 0.00% <ø> (ø)
java-25 71.48% <72.78%> (+<0.01%) ⬆️
lane-a 100.00% <ø> (ø)
lane-b 0.00% <ø> (ø)
temurin 71.48% <72.78%> (+<0.01%) ⬆️
unittests 71.47% <72.78%> (+<0.01%) ⬆️
unittests1 61.23% <72.41%> (+0.01%) ⬆️
unittests2 42.95% <3.40%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

extension-point Adds or modifies an extension/SPI point feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants