recursive zk delete
This commit is contained in:
parent
f3f6466730
commit
3a6a060b2e
|
@ -112,6 +112,19 @@ func testBackend(t *testing.T, b Backend) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Make a nested entry
|
||||
e = &Entry{Key: "foo/bar", Value: []byte("baz")}
|
||||
err = b.Put(e)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Delete with children should work
|
||||
err = b.Delete("foo")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testBackend_ListPrefix(t *testing.T, b Backend) {
|
||||
|
|
|
@ -88,6 +88,26 @@ func (c *ZookeeperBackend) ensurePath(path string, value []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// deletePath is a helper that will recursively delete
|
||||
// a given path
|
||||
func (c *ZookeeperBackend) deletePath(path string) error {
|
||||
children, _, _ := c.client.Children(path)
|
||||
|
||||
for _, childPath := range children {
|
||||
err := c.deletePath(path + "/" + childPath)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := c.client.Delete(path, -1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Put is used to insert or update an entry
|
||||
func (c *ZookeeperBackend) Put(entry *Entry) error {
|
||||
defer metrics.MeasureSince([]string{"zookeeper", "put"}, time.Now())
|
||||
|
@ -136,7 +156,7 @@ func (c *ZookeeperBackend) Delete(key string) error {
|
|||
|
||||
// Delete the full path
|
||||
fullPath := c.path + key
|
||||
err := c.client.Delete(fullPath, -1)
|
||||
err := c.deletePath(fullPath)
|
||||
|
||||
// Mask if the node does not exist
|
||||
if err == zk.ErrNoNode {
|
||||
|
|
Loading…
Reference in a new issue