-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: init PgElection #5201
feat: init PgElection #5201
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
} | ||
|
||
async fn resign(&self) -> Result<()> { | ||
todo!() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponding todo!
to EtcdElection
.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5201 +/- ##
==========================================
- Coverage 84.07% 83.81% -0.26%
==========================================
Files 1181 1181
Lines 219334 219343 +9
==========================================
- Hits 184405 183848 -557
- Misses 34929 35495 +566 |
The cool part of this advisory lock is it's got unlocked when the connection is down. So I think we don't need to manually unlock it. And in order to acquire the lock, each metasrv node should call |
Initially I think there might be situations that a metasrv holds the lock but fails to renew the lease. Since we can think holding the lock itself indicates the metasrv is still alive, we can remove the lease/expire-time part of campaign/leader value and check the lock as heartbeat instead? update: The problem may lie in that the lease mechanism and the advisory lock are overlapped at some point: we can both check the lease/expire-time, or check the advisory lock to check the leadership. We can choose one of them or use them all. |
Conclusion from offline discussion:
|
Split to multiple patches. See #5209 for the first part |
I hereby agree to the terms of the GreptimeDB CLA.
Refer to a related PR or issue link (optional)
What's changed and what's your intention?
As title. Details:
For election, candidates try acquire advisory lock regularly.
If successful, the candidate is the leader. Leader should keep alive by update leader value's expire time and acquire lock multiple times. If failed once, step down.
Edge case:
IDLE_SESSION_TIMEOUT
, the lock is released and the campaign restart.IDLE_SESSION_TIMEOUT
, it will:IDLE_SESSION_TIMEOUT
and comes back.IDLE_SESSION_TIMEOUT
is longer than theMETA_LEASE_TIME
is the key that this case happens only if case 1 happens.If not successful, the candidate is a follower. Follower should check the leader value's expire time and acquire lock multiple times. If the leader value expired, delete the value and re-init a campaign. If get the lock, just become the leader.
For registering candidates, just regularly register themselves with expire time.
Checklist