|
|
@@ -23,7 +23,7 @@ import (
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
|
- etcdErr "github.com/coreos/etcd/error"
|
|
|
+ "github.com/coreos/etcd/etcdserver/v2error"
|
|
|
"github.com/coreos/etcd/pkg/types"
|
|
|
|
|
|
"github.com/jonboulle/clockwork"
|
|
|
@@ -120,7 +120,7 @@ func (s *store) Index() uint64 {
|
|
|
// If recursive is true, it will return all the content under the node path.
|
|
|
// If sorted is true, it will sort the content by keys.
|
|
|
func (s *store) Get(nodePath string, recursive, sorted bool) (*Event, error) {
|
|
|
- var err *etcdErr.Error
|
|
|
+ var err *v2error.Error
|
|
|
|
|
|
s.worldLock.RLock()
|
|
|
defer s.worldLock.RUnlock()
|
|
|
@@ -160,7 +160,7 @@ func (s *store) Get(nodePath string, recursive, sorted bool) (*Event, error) {
|
|
|
// If the node has already existed, create will fail.
|
|
|
// If any node on the path is a file, create will fail.
|
|
|
func (s *store) Create(nodePath string, dir bool, value string, unique bool, expireOpts TTLOptionSet) (*Event, error) {
|
|
|
- var err *etcdErr.Error
|
|
|
+ var err *v2error.Error
|
|
|
|
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
|
@@ -189,7 +189,7 @@ func (s *store) Create(nodePath string, dir bool, value string, unique bool, exp
|
|
|
|
|
|
// Set creates or replace the node at nodePath.
|
|
|
func (s *store) Set(nodePath string, dir bool, value string, expireOpts TTLOptionSet) (*Event, error) {
|
|
|
- var err *etcdErr.Error
|
|
|
+ var err *v2error.Error
|
|
|
|
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
|
@@ -207,7 +207,7 @@ func (s *store) Set(nodePath string, dir bool, value string, expireOpts TTLOptio
|
|
|
|
|
|
// Get prevNode value
|
|
|
n, getErr := s.internalGet(nodePath)
|
|
|
- if getErr != nil && getErr.ErrorCode != etcdErr.EcodeKeyNotFound {
|
|
|
+ if getErr != nil && getErr.ErrorCode != v2error.EcodeKeyNotFound {
|
|
|
err = getErr
|
|
|
return nil, err
|
|
|
}
|
|
|
@@ -260,7 +260,7 @@ func getCompareFailCause(n *node, which int, prevValue string, prevIndex uint64)
|
|
|
func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint64,
|
|
|
value string, expireOpts TTLOptionSet) (*Event, error) {
|
|
|
|
|
|
- var err *etcdErr.Error
|
|
|
+ var err *v2error.Error
|
|
|
|
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
|
@@ -279,7 +279,7 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
|
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
// we do not allow the user to change "/"
|
|
|
if s.readonlySet.Contains(nodePath) {
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
}
|
|
|
|
|
|
n, err := s.internalGet(nodePath)
|
|
|
@@ -287,7 +287,7 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
|
|
|
return nil, err
|
|
|
}
|
|
|
if n.IsDir() { // can only compare and swap file
|
|
|
- err = etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, s.CurrentIndex)
|
|
|
+ err = v2error.NewError(v2error.EcodeNotFile, nodePath, s.CurrentIndex)
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
@@ -295,7 +295,7 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
|
|
|
// Command will be executed, only if both of the tests are successful.
|
|
|
if ok, which := n.Compare(prevValue, prevIndex); !ok {
|
|
|
cause := getCompareFailCause(n, which, prevValue, prevIndex)
|
|
|
- err = etcdErr.NewError(etcdErr.EcodeTestFailed, cause, s.CurrentIndex)
|
|
|
+ err = v2error.NewError(v2error.EcodeTestFailed, cause, s.CurrentIndex)
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
@@ -333,7 +333,7 @@ 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) {
|
|
|
- var err *etcdErr.Error
|
|
|
+ var err *v2error.Error
|
|
|
|
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
|
@@ -352,7 +352,7 @@ func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
|
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
// we do not allow the user to change "/"
|
|
|
if s.readonlySet.Contains(nodePath) {
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
}
|
|
|
|
|
|
// recursive implies dir
|
|
|
@@ -394,7 +394,7 @@ func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
|
|
|
}
|
|
|
|
|
|
func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex uint64) (*Event, error) {
|
|
|
- var err *etcdErr.Error
|
|
|
+ var err *v2error.Error
|
|
|
|
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
|
@@ -417,14 +417,14 @@ func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex ui
|
|
|
return nil, err
|
|
|
}
|
|
|
if n.IsDir() { // can only compare and delete file
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, s.CurrentIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeNotFile, nodePath, s.CurrentIndex)
|
|
|
}
|
|
|
|
|
|
// If both of the prevValue and prevIndex are given, we will test both of them.
|
|
|
// Command will be executed, only if both of the tests are successful.
|
|
|
if ok, which := n.Compare(prevValue, prevIndex); !ok {
|
|
|
cause := getCompareFailCause(n, which, prevValue, prevIndex)
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeTestFailed, cause, s.CurrentIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeTestFailed, cause, s.CurrentIndex)
|
|
|
}
|
|
|
|
|
|
// update etcd index
|
|
|
@@ -467,11 +467,11 @@ func (s *store) Watch(key string, recursive, stream bool, sinceIndex uint64) (Wa
|
|
|
}
|
|
|
|
|
|
// walk walks all the nodePath and apply the walkFunc on each directory
|
|
|
-func (s *store) walk(nodePath string, walkFunc func(prev *node, component string) (*node, *etcdErr.Error)) (*node, *etcdErr.Error) {
|
|
|
+func (s *store) walk(nodePath string, walkFunc func(prev *node, component string) (*node, *v2error.Error)) (*node, *v2error.Error) {
|
|
|
components := strings.Split(nodePath, "/")
|
|
|
|
|
|
curr := s.Root
|
|
|
- var err *etcdErr.Error
|
|
|
+ var err *v2error.Error
|
|
|
|
|
|
for i := 1; i < len(components); i++ {
|
|
|
if len(components[i]) == 0 { // ignore empty string
|
|
|
@@ -491,7 +491,7 @@ 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, expireOpts TTLOptionSet) (*Event, error) {
|
|
|
- var err *etcdErr.Error
|
|
|
+ var err *v2error.Error
|
|
|
|
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
|
@@ -510,7 +510,7 @@ func (s *store) Update(nodePath string, newValue string, expireOpts TTLOptionSet
|
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
// we do not allow the user to change "/"
|
|
|
if s.readonlySet.Contains(nodePath) {
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
}
|
|
|
|
|
|
currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1
|
|
|
@@ -521,7 +521,7 @@ func (s *store) Update(nodePath string, newValue string, expireOpts TTLOptionSet
|
|
|
}
|
|
|
if n.IsDir() && len(newValue) != 0 {
|
|
|
// if the node is a directory, we cannot update value to non-empty
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeNotFile, nodePath, currIndex)
|
|
|
}
|
|
|
|
|
|
if expireOpts.Refresh {
|
|
|
@@ -561,7 +561,7 @@ func (s *store) Update(nodePath string, newValue string, expireOpts TTLOptionSet
|
|
|
}
|
|
|
|
|
|
func (s *store) internalCreate(nodePath string, dir bool, value string, unique, replace bool,
|
|
|
- expireTime time.Time, action string) (*Event, *etcdErr.Error) {
|
|
|
+ expireTime time.Time, action string) (*Event, *v2error.Error) {
|
|
|
|
|
|
currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1
|
|
|
|
|
|
@@ -573,7 +573,7 @@ func (s *store) internalCreate(nodePath string, dir bool, value string, unique,
|
|
|
|
|
|
// we do not allow the user to change "/"
|
|
|
if s.readonlySet.Contains(nodePath) {
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", currIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeRootROnly, "/", currIndex)
|
|
|
}
|
|
|
|
|
|
// Assume expire times that are way in the past are
|
|
|
@@ -603,13 +603,13 @@ func (s *store) internalCreate(nodePath string, dir bool, value string, unique,
|
|
|
if n != nil {
|
|
|
if replace {
|
|
|
if n.IsDir() {
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeNotFile, nodePath, currIndex)
|
|
|
}
|
|
|
e.PrevNode = n.Repr(false, false, s.clock)
|
|
|
|
|
|
n.Remove(false, false, nil)
|
|
|
} else {
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeNodeExist, nodePath, currIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeNodeExist, nodePath, currIndex)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -642,13 +642,13 @@ func (s *store) internalCreate(nodePath string, dir bool, value string, unique,
|
|
|
}
|
|
|
|
|
|
// InternalGet gets the node of the given nodePath.
|
|
|
-func (s *store) internalGet(nodePath string) (*node, *etcdErr.Error) {
|
|
|
+func (s *store) internalGet(nodePath string) (*node, *v2error.Error) {
|
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
|
|
|
- walkFunc := func(parent *node, name string) (*node, *etcdErr.Error) {
|
|
|
+ walkFunc := func(parent *node, name string) (*node, *v2error.Error) {
|
|
|
|
|
|
if !parent.IsDir() {
|
|
|
- err := etcdErr.NewError(etcdErr.EcodeNotDir, parent.Path, s.CurrentIndex)
|
|
|
+ err := v2error.NewError(v2error.EcodeNotDir, parent.Path, s.CurrentIndex)
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
@@ -657,7 +657,7 @@ func (s *store) internalGet(nodePath string) (*node, *etcdErr.Error) {
|
|
|
return child, nil
|
|
|
}
|
|
|
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeKeyNotFound, path.Join(parent.Path, name), s.CurrentIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeKeyNotFound, path.Join(parent.Path, name), s.CurrentIndex)
|
|
|
}
|
|
|
|
|
|
f, err := s.walk(nodePath, walkFunc)
|
|
|
@@ -707,7 +707,7 @@ func (s *store) DeleteExpiredKeys(cutoff time.Time) {
|
|
|
// If it is a directory, this function will return the pointer to that node.
|
|
|
// If it does not exist, this function will create a new directory and return the pointer to that node.
|
|
|
// If it is a file, this function will return error.
|
|
|
-func (s *store) checkDir(parent *node, dirName string) (*node, *etcdErr.Error) {
|
|
|
+func (s *store) checkDir(parent *node, dirName string) (*node, *v2error.Error) {
|
|
|
node, ok := parent.Children[dirName]
|
|
|
|
|
|
if ok {
|
|
|
@@ -715,7 +715,7 @@ func (s *store) checkDir(parent *node, dirName string) (*node, *etcdErr.Error) {
|
|
|
return node, nil
|
|
|
}
|
|
|
|
|
|
- return nil, etcdErr.NewError(etcdErr.EcodeNotDir, node.Path, s.CurrentIndex)
|
|
|
+ return nil, v2error.NewError(v2error.EcodeNotDir, node.Path, s.CurrentIndex)
|
|
|
}
|
|
|
|
|
|
n := newDir(s, path.Join(parent.Path, dirName), s.CurrentIndex+1, parent, Permanent)
|