client/v3: add ResumeMutex to concurrency package - #22384
avanish-garg wants to merge 1 commit into
Conversation
concurrency.Election already has ResumeElection, for reconstructing an election handle after a process restart (paired with Session's WithLease option for a surviving lease). Mutex had no equivalent, so a restarted process holding a lock had no way to get a working *Mutex handle back for it -- it could only start over with a fresh Lock() call. ResumeMutex mirrors ResumeElection's shape exactly: given a session, the same key prefix, and the previously-observed owner key/revision, it reconstructs a Mutex that IsOwner() and Unlock() work correctly against. Signed-off-by: Avanish Garg <gargavanish@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: avanish-garg The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @avanish-garg. Thanks for your PR. I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
cc @ptabor @fuweid — both of you have prior commits in |
Fixes #22382
Problem
concurrency.ElectionhasResumeElection, for reconstructing an election handle aftera process restart (used together with
Session'sWithLeaseoption for a survivinglease).
concurrency.Mutexhas no equivalent -- a restarted process that was holding alock has no way to get a working
*Mutexhandle back for it; it can only start over witha fresh
Lock()call, losing the distinction between "I already own this lock" and "Ineed to compete for it."
Change
ResumeMutex(s *Session, pfx, myKey string, myRev int64) *Mutex, mirroringResumeElection's exact shape and doc-comment style.TestResumeMutextotests/integration/clientv3/concurrency/mutex_test.go,mirroring the existing
TestResumeElectionpattern: locks a mutex, reconstructs asecond
*Mutexhandle purely from the session + observed key/revision (simulating aprocess restart), and verifies
IsOwner()still recognizes it as the owner andUnlock()correctly deletes the real server-side key.Mutex'smyKey/myRevfields are structurally identical toElection'sleaderKey/leaderRev, andIsOwner()/Unlock()only depend on those two values beingset correctly -- they have no dependency on which constructor produced them, so this is a
small, mechanical port of a pattern already proven for
Election.Verified:
go build ./client/v3/...,go vet ./client/v3/concurrency/...clean, fullexisting concurrency integration test suite passes alongside the new test (11/11,
including
TestResumeElection,TestMutexLockSessionExpired,TestMutexUnlock, and thepackage's
Example*tests).