I have this simple code that tries to delete all the nodes recursively. The code does not produce errors, but at the same time, the nodes aren't deleted. Note: There may be more than 1 active users accessing this node (and this may be the reason for not able to delete)...
Code:
package main
import (
"fmt"
"time"
"github.com/samuel/go-zookeeper/zk"
)
// Patroni Config
const (
PATRONI_SCOPE = "blueplanet"
PATRONI_CLUSTER = "postgres"
ROOT = "/" + PATRONI_SCOPE + "/" + PATRONI_CLUSTER
)
// paths are held to be deleted.
var paths []string = []string{ROOT}
// Main
func main() {
c, _, e := zk.Connect([]string{"172.16.0.18"}, time.Second)
if e != nil {
return
}
defer c.Close()
countIndex := 1
totalCount := 1
for i := countIndex - 1; i < totalCount; i++ {
path := paths[i]
children, _, e := c.Children(path)
if e == nil && len(children) != 0 {
new_children := []string{}
for _, v := range children {
new_children = append(new_children, path+"/"+v)
}
paths = append(paths, new_children...)
totalCount += len(children)
}
}
// reverse path so that we have children first, then its next level parents and so on.
for i := len(paths)/2 - 1; i >= 0; i-- {
opp := len(paths) - 1 - i
paths[i], paths[opp] = paths[opp], paths[i]
}
// start deleting the nodes
for _, v := range paths {
if err := c.Delete(v, -1); err != nil && err != zk.ErrNoNode {
fmt.Printf("Delete returned error:%+v %+v", v, err)
} else {
fmt.Println("path deleted :", v)
}
}
return
}
I have this simple code that tries to delete all the nodes recursively. The code does not produce errors, but at the same time, the nodes aren't deleted. Note: There may be more than 1 active users accessing this node (and this may be the reason for not able to delete)... Code:
Running the executable:
Now go to ZK and check the nodes:
The zk nodes are still present