From f22ea70c14d9cf5fbeb0462e6478761405fc972e Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 7 Jan 2016 10:20:58 -0800 Subject: [PATCH] lease: unlock before another batch operation --- lease/lessor.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lease/lessor.go b/lease/lessor.go index 3c9333268..fe32371cb 100644 --- a/lease/lessor.go +++ b/lease/lessor.go @@ -191,7 +191,6 @@ func (le *lessor) get(id LeaseID) *lease { func (le *lessor) initAndRecover() { tx := le.b.BatchTx() tx.Lock() - defer tx.Unlock() tx.UnsafeCreateBucket(leaseBucketName) _, vs := tx.UnsafeRange(leaseBucketName, int64ToBytes(0), int64ToBytes(math.MaxInt64), 0) @@ -200,6 +199,7 @@ func (le *lessor) initAndRecover() { var lpb leasepb.Lease err := lpb.Unmarshal(vs[i]) if err != nil { + tx.Unlock() panic("failed to unmarshal lease proto item") } 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))), } } + tx.Unlock() + le.b.ForceCommit() }