-
Notifications
You must be signed in to change notification settings - Fork 7.3k
ZOOKEEPER-4956: Provide a HostProvider that uses DNS SRV record for dynamic server discovery #2320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ynamic server discovery Author: Li Wang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are the changes of StaticHostProvider
?
final String absoluteDnsName = trimmedDnsName.endsWith(".") ? trimmedDnsName : trimmedDnsName + "."; | ||
|
||
try { | ||
Name.fromString(absoluteDnsName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do a lookup immediately in order to validate that the DNS name has valid SRV record.
* | ||
* @return the initialized Timer or null if refresh interval is 0 or negative | ||
*/ | ||
private Timer initializeDnsRefreshTimer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this internal caching thing at all in ZooKeeper. DNS has its own multi-layer caching logic in the IP stack of the operating system and at the DNS resolver servers. Just query the SRV entry every time you run out of available servers and DNS will take care of the rest. There's not much benefit in caching something which is already cached in the host's memory.
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* HostConnectionManager handles the complex connection management and reconfiguration logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather explain the connection management logic in detail in Javadoc. "handles complex logic" is meaningless.
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>dnsjava</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there standard Java API for this which is not third party?
* HostConnectionManager handles the complex connection management and reconfiguration logic | ||
*/ | ||
@InterfaceAudience.Private | ||
public final class HostConnectionManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be the common abstract class for both implementations. Doing it with inheritance might be simpler than this composition where you just forward the calls to Connection Manager.
The existing ZooKeeper client architecture relies on StaticHostProvider, which lacks auto service discovery capabilities and must wait for external mechanisms to push server list updates, either through manual configuration changes or reconfig notifications.
This PR provides a HostProvider implementation that performs dynamic service discovery based on DNS SRV record. The following is a summary of the changes: