Browse Source

fix(mod/lock): Use CreatedIndex in the first node to watch

ModifiedIndex in the lock directory is not incremented and the event
store has only 1000 histories for now.

Acquiring a lock is not queued while (index - ModifiedIndex) > 1000 and
prevIndex exists.
TANABE Ken-ichi 12 years ago
parent
commit
1273875a00
1 changed files with 7 additions and 1 deletions
  1. 7 1
      mod/lock/v2/acquire_handler.go

+ 7 - 1
mod/lock/v2/acquire_handler.go

@@ -164,7 +164,6 @@ func (h *handler) watch(keypath string, index int, closeChan <- chan bool) error
 		if err != nil {
 			return fmt.Errorf("lock watch lookup error: %s", err.Error())
 		}
-		waitIndex := resp.Node.ModifiedIndex
 		nodes := lockNodes{resp.Node.Nodes}
 		prevIndex := nodes.PrevIndex(index)
 
@@ -174,6 +173,13 @@ func (h *handler) watch(keypath string, index int, closeChan <- chan bool) error
 		}
 
 		// Watch previous index until it's gone.
+		waitIndex := resp.Node.ModifiedIndex
+
+		// Since event store has only 1000 histories we should use first node's CreatedIndex if available
+		if firstNode := nodes.First(); firstNode != nil {
+			waitIndex = firstNode.CreatedIndex
+		}
+
 		_, err = h.client.Watch(path.Join(keypath, strconv.Itoa(prevIndex)), waitIndex, false, nil, stopWatchChan)
 		if err == etcd.ErrWatchStoppedByUser {
 			return fmt.Errorf("lock watch closed")