go-zookeeper / zk

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

Enhance HostProvider to update host provider on retryStart occurrence #107

Open ChenHaoHu opened 1 year ago

ChenHaoHu commented 1 year ago

This pull request aims to enhance the functionality of the HostProvider by adding the hostProvider.UpdateServerList function. The goal is to update the host provider when the retryStart condition occurs twice.

During runtime, when the client is connecting to the ZooKeeper server, it is crucial to handle scenarios where the server undergoes a service restart. In such cases, the IP addresses of the ZooKeeper server may change, rendering the previously resolved IP addresses invalid. Currently, the client only selects an IP address from the initial resolution and does not perform subsequent DNS resolutions. As a result, the client continuously attempts to connect to an invalid IP.

In my specific case, we have a ZooKeeper deployment based on Kubernetes using a headless service. Consequently, when ZooKeeper restarts, the IP addresses can change, leading to connection issues.

By introducing the hostProvider.UpdateServerList function, we ensure that the host provider is updated when the retryStart condition occurs twice. This enables the client to handle changes in the ZooKeeper server's IP addresses effectively and avoid attempting connections to invalid IPs.

Overall, this enhancement addresses the issue of connection failures due to ZooKeeper service restarts and provides a more robust and reliable connection mechanism. The UpdateServerList function in the DNSHostProvider plays a vital role in re-resolving the previously configured domain name information, ensuring accurate and up-to-date IP address resolutions.

Your feedback and suggestions are greatly appreciated.

Thank you for your time and consideration.

Best regards, ChenHaoHu

ChenHaoHu commented 1 year ago

The HostProvider interface design is referenced from http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/client/HostProvider.java?view=markup#l70