Skip to content

Conversation

kezhuw
Copy link
Member

@kezhuw kezhuw commented Aug 21, 2025

Changes:

  1. Add new interface Zookeeper in o.a.z.client.
  2. Add ZooKeeper::builder to construct instance of ZooKeeper.
  3. Add ZooKeeperAdaptor to proxy interface methods to o.a.z.ZooKeeper instance to keep abi compatibility.

@kezhuw kezhuw force-pushed the ZOOKEEPER-4968-ZooKeeper-interfaces-to-cover-client-operations branch from 902d71c to c0b40d1 Compare August 21, 2025 12:00
Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the benefit of this change?
Are we going to have a separate ZooKeeper client maven module at some point?

import org.apache.zookeeper.data.ClientInfo;
import org.apache.zookeeper.data.Stat;

class ZooKeeperAdaptor implements ZooKeeper {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some javadoc?

@@ -79,7 +78,7 @@ public void testBuildClient() throws Exception {
@Test
public void testBuildAdminClient() throws Exception {
BlockingQueue<WatchedEvent> events = new LinkedBlockingQueue<>();
ZooKeeper zk = new ZooKeeperBuilder(hostPort, Duration.ofMillis(1000))
ZooKeeper zk = ZooKeeper.builder(hostPort, Duration.ofMillis(1000))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return interface should be ZooKeeperAdmin.

Changes:
1. Add new interface `Zookeeper` in `o.a.z.client`.
2. Add `ZooKeeper::builder` to construct instance of `ZooKeeper`.
3. Add `ZooKeeperAdaptor` to proxy interface methods to `o.a.z.ZooKeeper`
   instance to keep abi compatibility.
@kezhuw kezhuw force-pushed the ZOOKEEPER-4968-ZooKeeper-interfaces-to-cover-client-operations branch from c0b40d1 to 0b3e3cb Compare August 23, 2025 06:50
Copy link
Member Author

@kezhuw kezhuw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the benefit of this change ?

My initial motivations:

  1. Refactoring ZooKeeper to o.a.zookeeper.client in a smooth way to accomodate possible future migration to java module. By introducing interface in o.a.zookeeper.client and also bridges to Watcher, WatchedEvent, etc., we can migrate all client side operation to package o.a.zookeeper.client without breaking anything. It might not be worth though if we are going to migrate to java module in one step without deprecation phase.
  2. A chance to rethink/refactor some of apis. Say, for getSessionId to return typed session id with custom toString or refactor watcher system to solve ZOOKEEPER-4625.

I think an interface for client side operations is also good for community as it is easy to do proxy/intercept/enhance things than concrete class, and more importantly it comes from official zookeeper package so the community could share their builds with each other.

Are we going to have a separate ZooKeeper client maven module at some point?

I have put effort on this. See:

  1. mail: https://lists.apache.org/thread/j4hg8bh6y3rjg5hlzrtnod52t7xz18hv
  2. draft pr: #2307
  3. continue work: https://github.com/kezhuw/zookeeper/commits/ZOOKEEPER-233-split-server-jar/


/**
* Adaptor to bridge {@link org.apache.zookeeper.ZooKeeper} to implement {@link ZooKeeper} while not introducing
* abi compatibility issue.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a breaking change in abi level to implement ZooKeeper for org.apache.zookeeper.ZooKeeper.

Adaptor is also good if we want to modify behavior slightly.

*
* @since 3.5.0
*/
void removeWatches(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is cheating since ZOOKEEPER-1910, see ZOOKEEPER-4625.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference with the earlier api is,

(1)this won't remove the given watcher from the server set even if the watcher set is empty, but it will remove the reference from the zkclient. This api will invoke a call to server and maintain orderly execution as earlier. IMHO sending to server is required to handle packet in-flight cases.
(2)null watcher is not allowed, client will validate and throw IllegalArgumentException.

We are now have persistent watcher now, it will continue event delivery until removed. If we are going to use new interface, it is a chance for us to reevaluate this api.

*
* @return current session id
*/
long getSessionId();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to return typed session id with custom toString, so we don't have to use Long.toHexString everytime in logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants