mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
store: fix index data race
This commit is contained in:
parent
7adb765660
commit
8ea840c19a
@ -101,7 +101,7 @@ func (n *node) IsDir() bool {
|
|||||||
// If the receiver node is not a key-value pair, a "Not A File" error will be returned.
|
// If the receiver node is not a key-value pair, a "Not A File" error will be returned.
|
||||||
func (n *node) Read() (string, *etcdErr.Error) {
|
func (n *node) Read() (string, *etcdErr.Error) {
|
||||||
if n.IsDir() {
|
if n.IsDir() {
|
||||||
return "", etcdErr.NewError(etcdErr.EcodeNotFile, "", n.store.Index())
|
return "", etcdErr.NewError(etcdErr.EcodeNotFile, "", n.store.CurrentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
return n.Value, nil
|
return n.Value, nil
|
||||||
@ -111,7 +111,7 @@ func (n *node) Read() (string, *etcdErr.Error) {
|
|||||||
// If the receiver node is a directory, a "Not A File" error will be returned.
|
// If the receiver node is a directory, a "Not A File" error will be returned.
|
||||||
func (n *node) Write(value string, index uint64) *etcdErr.Error {
|
func (n *node) Write(value string, index uint64) *etcdErr.Error {
|
||||||
if n.IsDir() {
|
if n.IsDir() {
|
||||||
return etcdErr.NewError(etcdErr.EcodeNotFile, "", n.store.Index())
|
return etcdErr.NewError(etcdErr.EcodeNotFile, "", n.store.CurrentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
n.Value = value
|
n.Value = value
|
||||||
@ -143,7 +143,7 @@ func (n *node) ExpirationAndTTL() (*time.Time, int64) {
|
|||||||
// If the receiver node is not a directory, a "Not A Directory" error will be returned.
|
// If the receiver node is not a directory, a "Not A Directory" error will be returned.
|
||||||
func (n *node) List() ([]*node, *etcdErr.Error) {
|
func (n *node) List() ([]*node, *etcdErr.Error) {
|
||||||
if !n.IsDir() {
|
if !n.IsDir() {
|
||||||
return nil, etcdErr.NewError(etcdErr.EcodeNotDir, "", n.store.Index())
|
return nil, etcdErr.NewError(etcdErr.EcodeNotDir, "", n.store.CurrentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes := make([]*node, len(n.Children))
|
nodes := make([]*node, len(n.Children))
|
||||||
@ -161,7 +161,7 @@ func (n *node) List() ([]*node, *etcdErr.Error) {
|
|||||||
// On success, it returns the file node
|
// On success, it returns the file node
|
||||||
func (n *node) GetChild(name string) (*node, *etcdErr.Error) {
|
func (n *node) GetChild(name string) (*node, *etcdErr.Error) {
|
||||||
if !n.IsDir() {
|
if !n.IsDir() {
|
||||||
return nil, etcdErr.NewError(etcdErr.EcodeNotDir, n.Path, n.store.Index())
|
return nil, etcdErr.NewError(etcdErr.EcodeNotDir, n.Path, n.store.CurrentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
child, ok := n.Children[name]
|
child, ok := n.Children[name]
|
||||||
@ -179,7 +179,7 @@ func (n *node) GetChild(name string) (*node, *etcdErr.Error) {
|
|||||||
// error will be returned
|
// error will be returned
|
||||||
func (n *node) Add(child *node) *etcdErr.Error {
|
func (n *node) Add(child *node) *etcdErr.Error {
|
||||||
if !n.IsDir() {
|
if !n.IsDir() {
|
||||||
return etcdErr.NewError(etcdErr.EcodeNotDir, "", n.store.Index())
|
return etcdErr.NewError(etcdErr.EcodeNotDir, "", n.store.CurrentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, name := path.Split(child.Path)
|
_, name := path.Split(child.Path)
|
||||||
@ -187,7 +187,7 @@ func (n *node) Add(child *node) *etcdErr.Error {
|
|||||||
_, ok := n.Children[name]
|
_, ok := n.Children[name]
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
return etcdErr.NewError(etcdErr.EcodeNodeExist, "", n.store.Index())
|
return etcdErr.NewError(etcdErr.EcodeNodeExist, "", n.store.CurrentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
n.Children[name] = child
|
n.Children[name] = child
|
||||||
@ -201,13 +201,13 @@ func (n *node) Remove(dir, recursive bool, callback func(path string)) *etcdErr.
|
|||||||
if n.IsDir() {
|
if n.IsDir() {
|
||||||
if !dir {
|
if !dir {
|
||||||
// cannot delete a directory without recursive set to true
|
// cannot delete a directory without recursive set to true
|
||||||
return etcdErr.NewError(etcdErr.EcodeNotFile, n.Path, n.store.Index())
|
return etcdErr.NewError(etcdErr.EcodeNotFile, n.Path, n.store.CurrentIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(n.Children) != 0 && !recursive {
|
if len(n.Children) != 0 && !recursive {
|
||||||
// cannot delete a directory if it is not empty and the operation
|
// cannot delete a directory if it is not empty and the operation
|
||||||
// is not recursive
|
// is not recursive
|
||||||
return etcdErr.NewError(etcdErr.EcodeDirNotEmpty, n.Path, n.store.Index())
|
return etcdErr.NewError(etcdErr.EcodeDirNotEmpty, n.Path, n.store.CurrentIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ func (s *store) Version() int {
|
|||||||
|
|
||||||
// Retrieves current of the store
|
// Retrieves current of the store
|
||||||
func (s *store) Index() uint64 {
|
func (s *store) Index() uint64 {
|
||||||
|
s.worldLock.RLock()
|
||||||
|
defer s.worldLock.RUnlock()
|
||||||
return s.CurrentIndex
|
return s.CurrentIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user