-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
recover lessor before recovering mvcc store and transactionally revoke leases #6098
Changes from 4 commits
29a077b
4d59b6f
75c06ca
bd62b0a
d69d438
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,13 +43,18 @@ var ( | |
|
||
type LeaseID int64 | ||
|
||
// RangeDeleter defines an interface with DeleteRange method. | ||
// RangeDeleter defines an interface with Txn and DeleteRange method. | ||
// We define this interface only for lessor to limit the number | ||
// of methods of mvcc.KV to what lessor actually needs. | ||
// | ||
// Having a minimum interface makes testing easy. | ||
type RangeDeleter interface { | ||
DeleteRange(key, end []byte) (int64, int64) | ||
// TxnBegin see comments on mvcc.KV | ||
TxnBegin() int64 | ||
// TxnEnd see comments on mvcc.KV | ||
TxnEnd(txnID int64) error | ||
// TxnDeleteRange see comments on mvcc.KV | ||
TxnDeleteRange(txnID int64, key, end []byte) (n, rev int64, err error) | ||
} | ||
|
||
// Lessor owns leases. It can grant, revoke, renew and modify leases for lessee. | ||
|
@@ -219,15 +224,27 @@ func (le *lessor) Revoke(id LeaseID) error { | |
le.mu.Unlock() | ||
|
||
if le.rd != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. |
||
tid := le.rd.TxnBegin() | ||
for item := range l.itemSet { | ||
le.rd.DeleteRange([]byte(item.Key), nil) | ||
_, _, err := le.rd.TxnDeleteRange(tid, []byte(item.Key), nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
le.mu.Lock() | ||
defer le.mu.Unlock() | ||
delete(le.leaseMap, l.ID) | ||
l.removeFrom(le.b) | ||
le.mu.Lock() | ||
defer le.mu.Unlock() | ||
delete(le.leaseMap, l.ID) | ||
// lease deletion needs to be in the same backend transcation with the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/transcation/transaction |
||
// 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) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
@@ -456,9 +473,7 @@ func (l Lease) persistTo(b backend.Backend) { | |
func (l Lease) removeFrom(b backend.Backend) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems simple enough to inline now since it's only used in one place There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. |
||
key := int64ToBytes(int64(l.ID)) | ||
|
||
b.BatchTx().Lock() | ||
b.BatchTx().UnsafeDelete(leaseBucketName, key) | ||
b.BatchTx().Unlock() | ||
} | ||
|
||
// refresh refreshes the expiry of the lease. | ||
|
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.
short comment about why lessor is recovered before kv?
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.
sure.