diff --git a/lease/lessor.go b/lease/lessor.go index 45c8c2520128..fc030805bdb0 100644 --- a/lease/lessor.go +++ b/lease/lessor.go @@ -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,8 +224,17 @@ func (le *lessor) Revoke(id LeaseID) error { le.mu.Unlock() if le.rd != nil { + 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) + } + } + + err := le.rd.TxnEnd(tid) + if err != nil { + panic(err) } } diff --git a/lease/lessor_test.go b/lease/lessor_test.go index 946e8c03b696..adc682c81743 100644 --- a/lease/lessor_test.go +++ b/lease/lessor_test.go @@ -225,9 +225,17 @@ type fakeDeleter struct { deleted []string } -func (fd *fakeDeleter) DeleteRange(key, end []byte) (int64, int64) { +func (fd *fakeDeleter) TxnBegin() int64 { + return 0 +} + +func (fd *fakeDeleter) TxnEnd(txnID int64) error { + return nil +} + +func (fd *fakeDeleter) TxnDeleteRange(tid int64, key, end []byte) (int64, int64, error) { fd.deleted = append(fd.deleted, string(key)+"_"+string(end)) - return 0, 0 + return 0, 0, nil } func NewTestBackend(t *testing.T) (string, backend.Backend) {