Skip to content
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

lease: Lookup non-blocking with concurrent Grant/Revoke #9229

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type Lessor interface {
// lessor implements Lessor interface.
// TODO: use clockwork for testability.
type lessor struct {
mu sync.Mutex
mu sync.RWMutex

// demotec is set when the lessor is the primary.
// demotec will be closed if the lessor is demoted.
Expand Down Expand Up @@ -311,8 +311,8 @@ func (le *lessor) Renew(id LeaseID) (int64, error) {
}

func (le *lessor) Lookup(id LeaseID) *Lease {
le.mu.Lock()
defer le.mu.Unlock()
le.mu.RLock()
defer le.mu.RUnlock()
return le.leaseMap[id]
}

Expand All @@ -326,9 +326,9 @@ func (le *lessor) unsafeLeases() []*Lease {
}

func (le *lessor) Leases() []*Lease {
le.mu.Lock()
le.mu.RLock()
ls := le.unsafeLeases()
le.mu.Unlock()
le.mu.RUnlock()
return ls
}

Expand Down Expand Up @@ -422,9 +422,9 @@ func (le *lessor) Attach(id LeaseID, items []LeaseItem) error {
}

func (le *lessor) GetLease(item LeaseItem) LeaseID {
le.mu.Lock()
le.mu.RLock()
id := le.itemMap[item]
le.mu.Unlock()
le.mu.RUnlock()
return id
}

Expand Down Expand Up @@ -477,11 +477,11 @@ func (le *lessor) runLoop() {
// rate limit
revokeLimit := leaseRevokeRate / 2

le.mu.Lock()
le.mu.RLock()
if le.isPrimary() {
ls = le.findExpiredLeases(revokeLimit)
}
le.mu.Unlock()
le.mu.RUnlock()

if len(ls) != 0 {
select {
Expand Down