Skip to content

Commit

Permalink
lease: do lease delection in the kv txn
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 authored and gyuho committed Aug 19, 2016
1 parent 07e421d commit 404415b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,20 @@ func (le *lessor) Revoke(id LeaseID) error {
}
}

le.mu.Lock()
defer le.mu.Unlock()
delete(le.leaseMap, l.ID)
// lease deletion needs to be in the same backend transcation with the
// kv deletion. Or we might end up with not executing the revoke or not
// deleting the keys if etcdserver fails in between.
l.removeFrom(le.b)

err := le.rd.TxnEnd(tid)
if err != nil {
panic(err)
}
}

le.mu.Lock()
defer le.mu.Unlock()
delete(le.leaseMap, l.ID)
l.removeFrom(le.b)

return nil
}

Expand Down Expand Up @@ -460,9 +463,7 @@ func (l Lease) persistTo(b backend.Backend) {
func (l Lease) removeFrom(b backend.Backend) {
key := int64ToBytes(int64(l.ID))

b.BatchTx().Lock()
b.BatchTx().UnsafeDelete(leaseBucketName, key)
b.BatchTx().Unlock()
}

// refresh refreshes the expiry of the lease. It extends the expiry at least
Expand Down

0 comments on commit 404415b

Please sign in to comment.