Repository navigation
Conversation
kezhuw
left a comment
There was a problem hiding this comment.
I think the problem resides in constructor of ZooKeeper. We should give clientConfig a no null ZKClientConfig there to not misuse it. But the change is good anyway.
zookeeper/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Lines 1139 to 1147 in 777b372
|
|
||
| private long getRefreshInterval() { | ||
| private long getRefreshInterval(final ZKClientConfig clientConfig) { | ||
| final ZKClientConfig config = clientConfig == null ? new ZKClientConfig() : clientConfig; |
There was a problem hiding this comment.
Shall we construct a ZKClientConfig if none provided and pass it to HostConnectionManager ? So the two see a consistent view of client config.
There was a problem hiding this comment.
Thanks, done in b08df25. DnsSrvHostProvider now creates the ZKClientConfig once when none is given and hands the same instance to HostConnectionManager and the refresh interval lookup. As you suggested in the review, the ZooKeeper constructor now also passes its non-null clientConfig to HostProviderFactory, so the client and the host provider see the same config.
DnsSrvHostProviderreceives the client'sZKClientConfig, andZKClientConfigcopieszookeeper.hostProvider.dnsSrvRefreshIntervalSecondsfrom the system properties like the other client settings, but the refresh interval was read withLong.getLong(). A value set in a client config file or withZKClientConfig.setProperty()was ignored, so the provider kept refreshing every 60 seconds (or used whatever the system property said).The interval is now read from the given
ZKClientConfig, falling back to a newZKClientConfigwhen none is passed, the same wayHostConnectionManagerdoes. The system property keeps working becauseZKClientConfigis initialized from it.Behaviour changes, both limited to this new 3.10.0 provider:
NumberFormatException, consistent with how a negative value is rejected and howzookeeper.request.timeoutis handled.Testing
DnsSrvHostProviderTest#testRefreshIntervalFromClientConfig(interval1inZKClientConfig, expects a periodic lookup) and#testRefreshIntervalNegativeInClientConfig(-1inZKClientConfigis rejected) fail without the fix and pass with it. The existing system property tests still pass.org.apache.zookeeper.client.*Test,HostProviderSelectionTest,StaticHostProviderTest,ConnectStringParserTestandCustomHostProviderTestpass; checkstyle and spotbugs report no issues.new ZooKeeper("dns-srv://...", ..., new ZKClientConfig(configFile)), where the file sets the interval to 1, sent 1 SRV query during a 3.5 second session before the fix and 4 (one per second) after it.