Browse Source

Merge branch 'mod-lock-fixes' of https://github.com/nabeken/etcd into nabeken-mod-lock-fixes

Conflicts:
	mod/lock/v2/acquire_handler.go
Ben Johnson 12 years ago
parent
commit
137f87c414
1 changed files with 12 additions and 3 deletions
  1. 12 3
      mod/lock/v2/acquire_handler.go

+ 12 - 3
mod/lock/v2/acquire_handler.go

@@ -146,14 +146,17 @@ func (h *handler) ttlKeepAlive(k string, value string, ttl int, stopChan chan bo
 func (h *handler) watch(keypath string, index int, closeChan <-chan bool) error {
 func (h *handler) watch(keypath string, index int, closeChan <-chan bool) error {
 	// Wrap close chan so we can pass it to Client.Watch().
 	// Wrap close chan so we can pass it to Client.Watch().
 	stopWatchChan := make(chan bool)
 	stopWatchChan := make(chan bool)
+	stopWrapChan := make(chan bool)
 	go func() {
 	go func() {
 		select {
 		select {
 		case <-closeChan:
 		case <-closeChan:
 			stopWatchChan <- true
 			stopWatchChan <- true
-		case <-stopWatchChan:
+		case <- stopWrapChan:
+			stopWatchChan <- true
+		case <- stopWatchChan:
 		}
 		}
 	}()
 	}()
-	defer close(stopWatchChan)
+	defer close(stopWrapChan)
 
 
 	for {
 	for {
 		// Read all nodes for the lock.
 		// Read all nodes for the lock.
@@ -161,7 +164,6 @@ func (h *handler) watch(keypath string, index int, closeChan <-chan bool) error
 		if err != nil {
 		if err != nil {
 			return fmt.Errorf("lock watch lookup error: %s", err.Error())
 			return fmt.Errorf("lock watch lookup error: %s", err.Error())
 		}
 		}
-		waitIndex := resp.Node.ModifiedIndex
 		nodes := lockNodes{resp.Node.Nodes}
 		nodes := lockNodes{resp.Node.Nodes}
 		prevIndex := nodes.PrevIndex(index)
 		prevIndex := nodes.PrevIndex(index)
 
 
@@ -171,6 +173,13 @@ func (h *handler) watch(keypath string, index int, closeChan <-chan bool) error
 		}
 		}
 
 
 		// Watch previous index until it's gone.
 		// 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)
 		_, err = h.client.Watch(path.Join(keypath, strconv.Itoa(prevIndex)), waitIndex, false, nil, stopWatchChan)
 		if err == etcd.ErrWatchStoppedByUser {
 		if err == etcd.ErrWatchStoppedByUser {
 			return fmt.Errorf("lock watch closed")
 			return fmt.Errorf("lock watch closed")