mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #804 from xiangli-cmu/fix_curr_index_race
fix(store): synchronize access to CurrentIndex
This commit is contained in:
commit
16d89c906b
@ -199,15 +199,15 @@ func getCompareFailCause(n *node, which int, prevValue string, prevIndex uint64)
|
||||
func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint64,
|
||||
value string, expireTime time.Time) (*Event, error) {
|
||||
|
||||
s.worldLock.Lock()
|
||||
defer s.worldLock.Unlock()
|
||||
|
||||
nodePath = path.Clean(path.Join("/", nodePath))
|
||||
// we do not allow the user to change "/"
|
||||
if nodePath == "/" {
|
||||
return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
||||
}
|
||||
|
||||
s.worldLock.Lock()
|
||||
defer s.worldLock.Unlock()
|
||||
|
||||
n, err := s.internalGet(nodePath)
|
||||
|
||||
if err != nil {
|
||||
@ -252,15 +252,15 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
|
||||
// Delete deletes the node at the given path.
|
||||
// If the node is a directory, recursive must be true to delete it.
|
||||
func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
|
||||
s.worldLock.Lock()
|
||||
defer s.worldLock.Unlock()
|
||||
|
||||
nodePath = path.Clean(path.Join("/", nodePath))
|
||||
// we do not allow the user to change "/"
|
||||
if nodePath == "/" {
|
||||
return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
||||
}
|
||||
|
||||
s.worldLock.Lock()
|
||||
defer s.worldLock.Unlock()
|
||||
|
||||
// recursive implies dir
|
||||
if recursive == true {
|
||||
dir = true
|
||||
@ -350,12 +350,12 @@ func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex ui
|
||||
}
|
||||
|
||||
func (s *store) Watch(key string, recursive, stream bool, sinceIndex uint64) (*Watcher, error) {
|
||||
key = path.Clean(path.Join("/", key))
|
||||
nextIndex := s.CurrentIndex + 1
|
||||
|
||||
s.worldLock.RLock()
|
||||
defer s.worldLock.RUnlock()
|
||||
|
||||
key = path.Clean(path.Join("/", key))
|
||||
nextIndex := s.CurrentIndex + 1
|
||||
|
||||
var w *Watcher
|
||||
var err *etcdErr.Error
|
||||
|
||||
@ -402,15 +402,15 @@ func (s *store) walk(nodePath string, walkFunc func(prev *node, component string
|
||||
// If the node is a file, the value and the ttl can be updated.
|
||||
// If the node is a directory, only the ttl can be updated.
|
||||
func (s *store) Update(nodePath string, newValue string, expireTime time.Time) (*Event, error) {
|
||||
s.worldLock.Lock()
|
||||
defer s.worldLock.Unlock()
|
||||
|
||||
nodePath = path.Clean(path.Join("/", nodePath))
|
||||
// we do not allow the user to change "/"
|
||||
if nodePath == "/" {
|
||||
return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
||||
}
|
||||
|
||||
s.worldLock.Lock()
|
||||
defer s.worldLock.Unlock()
|
||||
|
||||
currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1
|
||||
|
||||
n, err := s.internalGet(nodePath)
|
||||
|
Loading…
x
Reference in New Issue
Block a user