go-zookeeper / zk

Native ZooKeeper client for Go
BSD 3-Clause "New" or "Revised" License
512 stars 130 forks source link

Add deleteall command implementation to the client #52

Open yonasstephen opened 3 years ago

yonasstephen commented 3 years ago

Add a deleteall implementation to the client. It is especially useful in test to teardown the test nodes. Right now if the nodes have children, using the client, we need to delete recursively. Else would get ErrNotEmpty. I briefly looked at the implementation and this seems to be the start where we can add: https://github.com/go-zookeeper/zk/blob/master/constants.go#L202. Happy to pull a PR if there is a guide on this. Thanks!

nemith commented 3 years ago

It is pretty trivial to implement this yourself, perhaps we can have utility functions but I don't think it should be high priority.

deleteAll is not an operation, that map you are referencing is mapping the operations on the wire (the zookeeper protocol) to a name. deleteall is not defined by a zk operation and instead is just implemented as GetChilderen and many Delete calls. You can wrap it in a Multi to get an atomic delete.

Note the Java client doesn't provide a deleteall method. It is only implemented by the cli.

I think they may be best for a utility package zkutil to match the Java implementation and not added as a method on the client. The expectations should be that a method on the client does a roundtrip to the server and not hide implementations.

nemith commented 3 years ago

For reference: ZKUtil in Java: https://github.com/apache/zookeeper/blob/1c92a1f950d5efd2956fe85c6b9c843648b7a6e8/zookeeper-server/src/main/java/org/apache/zookeeper/ZKUtil.java