Repository navigation
[KYUUBI #7838] Fix concurrent ZooKeeper service deregistration #7840
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
Open
zhangxinyao88
wants to merge
4
commits into
apache:master
Choose a base branch
from
zhangxinyao88:kyuubi-7838-ci-diagnostics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+130
−21
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a86f665
[KYUUBI #7838][CI] Capture JVM thread dumps when Spark CI stalls
zhangxinyao88 2bae575
[KYUUBI #7838] Fix concurrent ZooKeeper service deregistration
zhangxinyao88 1c7124f
Let explicit server shutdown drain sessions without a ZooKeeper callback
zhangxinyao88 5da066f
Clarify the session drain helper name
zhangxinyao88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,27 +230,33 @@ class ZookeeperDiscoveryClient(conf: KyuubiConf) extends DiscoveryClient { | |
| external: Boolean = false): Unit = { | ||
| val instance = serviceDiscovery.fe.connectionUrl | ||
| watcher = new DeRegisterWatcher(instance, serviceDiscovery) | ||
| serviceNode = createPersistentNode( | ||
| val node = createPersistentNode( | ||
| conf, | ||
| namespace, | ||
| instance, | ||
| version, | ||
| external, | ||
| serviceDiscovery.fe.attributes) | ||
| // Set a watch on the serviceNode | ||
| synchronized { | ||
| serviceNode = node | ||
| } | ||
| watchNode() | ||
| } | ||
|
|
||
| override def deregisterService(): Unit = { | ||
| // close the EPHEMERAL_SEQUENTIAL node in zk | ||
| if (serviceNode != null) { | ||
| // Explicit shutdown and the deletion watcher can deregister concurrently. | ||
| val node = synchronized { | ||
| val current = serviceNode | ||
| serviceNode = null | ||
| current | ||
| } | ||
| if (node != null) { | ||
| val path = node.getActualPath | ||
| try { | ||
| serviceNode.close() | ||
| node.close() | ||
| } catch { | ||
| case e @ (_: IOException | _: KeeperException) => | ||
| error("Failed to close the persistent ephemeral znode" + serviceNode.getActualPath, e) | ||
| } finally { | ||
| serviceNode = null | ||
| error(s"Failed to close the persistent ephemeral znode $path", e) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -401,11 +407,12 @@ class ZookeeperDiscoveryClient(conf: KyuubiConf) extends DiscoveryClient { | |
| } | ||
|
|
||
| private def watchNode(): Unit = { | ||
| if (zkClient.checkExists | ||
| .usingWatcher(watcher.asInstanceOf[Watcher]).forPath(serviceNode.getActualPath) == null) { | ||
| // No node exists, throw exception | ||
| throw new KyuubiException(s"Unable to create znode for this Kyuubi " + | ||
| s"instance[${watcher.instance}] on ZooKeeper.") | ||
| // A queued NodeDataChanged event can arrive after deregistration. | ||
| Option(serviceNode).flatMap(node => Option(node.getActualPath)).foreach { path => | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
| if (zkClient.checkExists.usingWatcher(watcher.asInstanceOf[Watcher]).forPath(path) == null) { | ||
| throw new KyuubiException(s"Unable to create znode for this Kyuubi " + | ||
| s"instance[${watcher.instance}] on ZooKeeper.") | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It seems like a simpler approach might be to make
registerServiceandderegisterServicemutually exclusive; otherwise, a situation might still arise where a node has already been deleted but a watch is still creating.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 reproduced this by calling
registerService()andderegisterService()concurrently. Deregistration returned before registration stored the node, so the node stayed registered. A lock would cover that case. I haven’t reproduced it through normal service startup and shutdown. Would it make sense to track this as a separate follow-up?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 think holding a lock for the entire method might be the simplest approach. It could fix many concurrency issues like this while keeping the code simple.
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.
My initial concern was holding the lock during the network I/O in node.close(). I tested this yesterday with network delays and connection loss and didn’t observe any additional shutdown issues, so I’m fine with synchronizing both methods.
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.
Thanks for testing this with delays and connection loss. Do you see locking both methods as a blocker for merging #7840, or would it be okay to track it as a separate follow-up?