Explorar o código

lease: unlock before another batch operation

Xiang Li %!s(int64=10) %!d(string=hai) anos
pai
achega
f22ea70c14
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      lease/lessor.go

+ 3 - 1
lease/lessor.go

@@ -191,7 +191,6 @@ func (le *lessor) get(id LeaseID) *lease {
 func (le *lessor) initAndRecover() {
 func (le *lessor) initAndRecover() {
 	tx := le.b.BatchTx()
 	tx := le.b.BatchTx()
 	tx.Lock()
 	tx.Lock()
-	defer tx.Unlock()
 
 
 	tx.UnsafeCreateBucket(leaseBucketName)
 	tx.UnsafeCreateBucket(leaseBucketName)
 	_, vs := tx.UnsafeRange(leaseBucketName, int64ToBytes(0), int64ToBytes(math.MaxInt64), 0)
 	_, vs := tx.UnsafeRange(leaseBucketName, int64ToBytes(0), int64ToBytes(math.MaxInt64), 0)
@@ -200,6 +199,7 @@ func (le *lessor) initAndRecover() {
 		var lpb leasepb.Lease
 		var lpb leasepb.Lease
 		err := lpb.Unmarshal(vs[i])
 		err := lpb.Unmarshal(vs[i])
 		if err != nil {
 		if err != nil {
+			tx.Unlock()
 			panic("failed to unmarshal lease proto item")
 			panic("failed to unmarshal lease proto item")
 		}
 		}
 		id := LeaseID(lpb.ID)
 		id := LeaseID(lpb.ID)
@@ -211,6 +211,8 @@ func (le *lessor) initAndRecover() {
 			expiry: minExpiry(time.Now(), time.Now().Add(time.Second*time.Duration(lpb.TTL))),
 			expiry: minExpiry(time.Now(), time.Now().Add(time.Second*time.Duration(lpb.TTL))),
 		}
 		}
 	}
 	}
+	tx.Unlock()
+
 	le.b.ForceCommit()
 	le.b.ForceCommit()
 }
 }