mgao0 commented on code in PR #2409:
URL: https://github.com/apache/helix/pull/2409#discussion_r1143998522
##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -394,4 +414,69 @@ public byte[] serialize(T data, String path) {
public T deserialize(byte[] bytes, String path) {
return _zkClient.deserialize(bytes, path);
}
+
+ /**
+ * A clean up method called when connect state change or MetaClient is
closing.
+ * @param cancel If we want to cancel the reconnect monitor thread.
+ * @param close If we want to close ZkClient.
+ */
+ private void cleanUpAndClose(boolean cancel, boolean close) {
Review Comment:
Nit: It is already well explained in your comment, but it would be better if
the method signature is something like `private void cleanUpAndClose(boolean
cancelMonitor, boolean closeZKClient)`.
##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -394,4 +414,69 @@ public byte[] serialize(T data, String path) {
public T deserialize(byte[] bytes, String path) {
return _zkClient.deserialize(bytes, path);
}
+
+ /**
+ * A clean up method called when connect state change or MetaClient is
closing.
+ * @param cancel If we want to cancel the reconnect monitor thread.
+ * @param close If we want to close ZkClient.
+ */
+ private void cleanUpAndClose(boolean cancel, boolean close) {
+ _zkClientConnectionMutex.lock();
+
+ if (close && !_zkClient.isClosed()) {
+ _zkClient.close();
+ LOG.info("ZkClient is closed");
+ }
+
+ if (cancel && _reconnectMonitorFuture != null) {
+ _reconnectMonitorFuture.cancel(true);
Review Comment:
Cancel the future before closing zk client?
##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -266,18 +279,25 @@ public void asyncSet(String key, T data, int version,
AsyncCallback.StatCallback
@Override
public void connect() {
- // TODO: throws IllegalStateException when already connected
try {
+ _zkClientConnectionMutex.lock();
_zkClient.connect(_initConnectionTimeout, _zkClient);
+ // register this client as state change listener to react to ZkClient
EXPIRED event.
+ // When ZkClient has expired connection to ZK, it sill auto reconnect
until ZkClient
+ // is closed or connection re-established.
+ // We will need to close ZkClient when user set retry connection timeout.
+ _zkClient.subscribeStateChanges(this);
Review Comment:
Curious: Does this state change event going into the event queue with other
type of events? Let's say if zk client connection is expired, other events
(such as child change or data change) processing will fail because meta client
cannot read zk now, will this block the queue so that zk state change event
never gets to be processed? I saw that there is a method
setAsyncExecPoolSize(), wondering is this how we prevent this kind of situation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]