Browse Source

*: rename lease.DeleteableRange to lease.RangeDeleter

Xiang Li 10 years ago
parent
commit
f01c8188f8
3 changed files with 18 additions and 19 deletions
  1. 13 14
      lease/lessor.go
  2. 4 4
      lease/lessor_test.go
  3. 1 1
      storage/kvstore.go

+ 13 - 14
lease/lessor.go

@@ -45,21 +45,21 @@ var (
 
 
 type LeaseID int64
 type LeaseID int64
 
 
-// DeleteableRange defines an interface with DeleteRange method.
+// RangeDeleter defines an interface with DeleteRange method.
 // We define this interface only for lessor to limit the number
 // We define this interface only for lessor to limit the number
 // of methods of storage.KV to what lessor actually needs.
 // of methods of storage.KV to what lessor actually needs.
 //
 //
 // Having a minimum interface makes testing easy.
 // Having a minimum interface makes testing easy.
-type DeleteableRange interface {
+type RangeDeleter interface {
 	DeleteRange(key, end []byte) (int64, int64)
 	DeleteRange(key, end []byte) (int64, int64)
 }
 }
 
 
 // A Lessor is the owner of leases. It can grant, revoke, renew and modify leases for lessee.
 // A Lessor is the owner of leases. It can grant, revoke, renew and modify leases for lessee.
 type Lessor interface {
 type Lessor interface {
-	// SetDeleteableRange sets the DeleteableRange to the Lessor.
+	// SetDeleteableRange sets the RangeDeleter to the Lessor.
 	// Lessor deletes the items in the revoked or expired lease from the
 	// Lessor deletes the items in the revoked or expired lease from the
-	// the set DeleteableRange.
-	SetDeleteableRange(dr DeleteableRange)
+	// the set RangeDeleter.
+	SetRangeDeleter(dr RangeDeleter)
 
 
 	// Grant grants a lease that expires at least after TTL seconds.
 	// Grant grants a lease that expires at least after TTL seconds.
 	Grant(ttl int64) *Lease
 	Grant(ttl int64) *Lease
@@ -115,10 +115,9 @@ type lessor struct {
 	// FindExpired and Renew should be the most frequent operations.
 	// FindExpired and Renew should be the most frequent operations.
 	leaseMap map[LeaseID]*Lease
 	leaseMap map[LeaseID]*Lease
 
 
-	// A DeleteableRange the lessor operates on.
 	// When a lease expires, the lessor will delete the
 	// When a lease expires, the lessor will delete the
-	// leased range (or key) from the DeleteableRange.
-	dr DeleteableRange
+	// leased range (or key) by the RangeDeleter.
+	rd RangeDeleter
 
 
 	// backend to persist leases. We only persist lease ID and expiry for now.
 	// backend to persist leases. We only persist lease ID and expiry for now.
 	// The leased items can be recovered by iterating all the keys in kv.
 	// The leased items can be recovered by iterating all the keys in kv.
@@ -154,11 +153,11 @@ func newLessor(lessorID uint8, b backend.Backend) *lessor {
 	return l
 	return l
 }
 }
 
 
-func (le *lessor) SetDeleteableRange(dr DeleteableRange) {
+func (le *lessor) SetRangeDeleter(rd RangeDeleter) {
 	le.mu.Lock()
 	le.mu.Lock()
 	defer le.mu.Unlock()
 	defer le.mu.Unlock()
 
 
-	le.dr = dr
+	le.rd = rd
 }
 }
 
 
 // TODO: when lessor is under high load, it should give out lease
 // TODO: when lessor is under high load, it should give out lease
@@ -196,9 +195,9 @@ func (le *lessor) Revoke(id LeaseID) error {
 		return ErrLeaseNotFound
 		return ErrLeaseNotFound
 	}
 	}
 
 
-	if le.dr != nil {
+	if le.rd != nil {
 		for item := range l.itemSet {
 		for item := range l.itemSet {
-			le.dr.DeleteRange([]byte(item.Key), nil)
+			le.rd.DeleteRange([]byte(item.Key), nil)
 		}
 		}
 	}
 	}
 
 
@@ -270,12 +269,12 @@ func (le *lessor) Attach(id LeaseID, items []LeaseItem) error {
 	return nil
 	return nil
 }
 }
 
 
-func (le *lessor) Recover(b backend.Backend, dr DeleteableRange) {
+func (le *lessor) Recover(b backend.Backend, rd RangeDeleter) {
 	le.mu.Lock()
 	le.mu.Lock()
 	defer le.mu.Unlock()
 	defer le.mu.Unlock()
 
 
 	le.b = b
 	le.b = b
-	le.dr = dr
+	le.rd = rd
 	le.leaseMap = make(map[LeaseID]*Lease)
 	le.leaseMap = make(map[LeaseID]*Lease)
 
 
 	le.initAndRecover()
 	le.initAndRecover()

+ 4 - 4
lease/lessor_test.go

@@ -68,10 +68,10 @@ func TestLessorRevoke(t *testing.T) {
 	defer os.RemoveAll(dir)
 	defer os.RemoveAll(dir)
 	defer be.Close()
 	defer be.Close()
 
 
-	fd := &fakeDeleteable{}
+	fd := &fakeDeleter{}
 
 
 	le := newLessor(1, be)
 	le := newLessor(1, be)
-	le.SetDeleteableRange(fd)
+	le.SetRangeDeleter(fd)
 
 
 	// grant a lease with long term (100 seconds) to
 	// grant a lease with long term (100 seconds) to
 	// avoid early termination during the test.
 	// avoid early termination during the test.
@@ -157,11 +157,11 @@ func TestLessorRecover(t *testing.T) {
 	}
 	}
 }
 }
 
 
-type fakeDeleteable struct {
+type fakeDeleter struct {
 	deleted []string
 	deleted []string
 }
 }
 
 
-func (fd *fakeDeleteable) DeleteRange(key, end []byte) (int64, int64) {
+func (fd *fakeDeleter) DeleteRange(key, end []byte) (int64, int64) {
 	fd.deleted = append(fd.deleted, string(key)+"_"+string(end))
 	fd.deleted = append(fd.deleted, string(key)+"_"+string(end))
 	return 0, 0
 	return 0, 0
 }
 }

+ 1 - 1
storage/kvstore.go

@@ -81,7 +81,7 @@ func NewStore(b backend.Backend, le lease.Lessor) *store {
 	}
 	}
 
 
 	if s.le != nil {
 	if s.le != nil {
-		s.le.SetDeleteableRange(s)
+		s.le.SetRangeDeleter(s)
 	}
 	}
 
 
 	tx := s.b.BatchTx()
 	tx := s.b.BatchTx()