-
Notifications
You must be signed in to change notification settings - Fork 7.3k
ZOOKEEPER-1416 - Persistent, recursive watchers #1106
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
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ limitations under the License. | |
| * [ZooKeeper Sessions](#ch_zkSessions) | ||
| * [ZooKeeper Watches](#ch_zkWatches) | ||
| * [Semantics of Watches](#sc_WatchSemantics) | ||
| * [Persistent, Recursive Watches](#sc_WatchPersistentRecursive) | ||
| * [Remove Watches](#sc_WatchRemoval) | ||
| * [What ZooKeeper Guarantees about Watches](#sc_WatchGuarantees) | ||
| * [Things to Remember about Watches](#sc_WatchRememberThese) | ||
|
|
@@ -640,6 +641,11 @@ general this all occurs transparently. There is one case where a watch | |
| may be missed: a watch for the existence of a znode not yet created will | ||
| be missed if the znode is created and deleted while disconnected. | ||
|
|
||
| **New in 3.6.0:** Clients can also set | ||
| permanent, recursive watches on a znode that are not removed when triggered | ||
| and that trigger for changes on the registered znode as well as any children | ||
| znodes recursively. | ||
|
|
||
| <a name="sc_WatchSemantics"></a> | ||
|
|
||
| ### Semantics of Watches | ||
|
|
@@ -657,6 +663,21 @@ the events that a watch can trigger and the calls that enable them: | |
| * **Child event:** | ||
| Enabled with a call to getChildren. | ||
|
|
||
| <a name="sc_WatchPersistentRecursive"></a> | ||
|
|
||
| ### Persistent, Recursive Watches | ||
|
|
||
| **New in 3.6.0:** There is now a variation on the standard | ||
| watch described above whereby you can set a watch that does not get removed when triggered. | ||
| Additionally, these watches trigger the event types *NodeCreated*, *NodeDeleted*, and *NodeDataChanged* | ||
| and, optionally, recursively for all znodes starting at the znode that the watch is registered for. Note | ||
| that *NodeChildrenChanged* events are not triggered for persistent recursive watches as it would be redundant. | ||
|
Comment on lines
+673
to
+674
Member
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. Looks reasonable |
||
|
|
||
| Persistent watches are set using the method *addWatch()*. The triggering semantics and guarantees | ||
| (other than one-time triggering) are the same as standard watches. The only exception regarding events is that | ||
| recursive persistent watchers never trigger child changed events as they are redundant. | ||
| Persistent watches are removed using *removeWatches()* with watcher type *WatcherType.Any*. | ||
|
|
||
| <a name="sc_WatchRemoval"></a> | ||
|
|
||
| ### Remove Watches | ||
|
|
@@ -671,6 +692,8 @@ successful watch removal. | |
| Watcher which was added with a call to getChildren. | ||
| * **Data Remove event:** | ||
| Watcher which was added with a call to exists or getData. | ||
| * **Persistent Remove event:** | ||
| Watcher which was added with a call to add a persistent watch. | ||
|
|
||
| <a name="sc_WatchGuarantees"></a> | ||
|
|
||
|
|
@@ -693,11 +716,11 @@ guarantees: | |
|
|
||
| ### Things to Remember about Watches | ||
|
|
||
| * Watches are one time triggers; if you get a watch event and | ||
| * Standard watches are one time triggers; if you get a watch event and | ||
| you want to get notified of future changes, you must set another | ||
| watch. | ||
|
|
||
| * Because watches are one time triggers and there is latency | ||
| * Because standard watches are one time triggers and there is latency | ||
| between getting the event and sending a new request to get a watch | ||
| you cannot reliably see every change that happens to a node in | ||
| ZooKeeper. Be prepared to handle the case where the znode changes | ||
|
|
||
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
67 changes: 67 additions & 0 deletions
67
zookeeper-server/src/main/java/org/apache/zookeeper/AddWatchMode.java
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.zookeeper; | ||
|
|
||
| /** | ||
| * Modes available to {@link ZooKeeper#addWatch(String, Watcher, AddWatchMode)} | ||
| */ | ||
| public enum AddWatchMode { | ||
| /** | ||
| * <p> | ||
| * Set a watcher on the given path that does not get removed when triggered (i.e. it stays active | ||
| * until it is removed). This watcher | ||
| * is triggered for both data and child events. To remove the watcher, use | ||
| * <tt>removeWatches()</tt> with <tt>WatcherType.Any</tt>. The watcher behaves as if you placed an exists() watch and | ||
| * a getData() watch on the ZNode at the given path. | ||
| * </p> | ||
| */ | ||
| PERSISTENT(ZooDefs.AddWatchModes.persistent), | ||
|
|
||
| /** | ||
| * <p> | ||
| * Set a watcher on the given path that: a) does not get removed when triggered (i.e. it stays active | ||
| * until it is removed); b) applies not only to the registered path but all child paths recursively. This watcher | ||
| * is triggered for both data and child events. To remove the watcher, use | ||
| * <tt>removeWatches()</tt> with <tt>WatcherType.Any</tt> | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * The watcher behaves as if you placed an exists() watch and | ||
| * a getData() watch on the ZNode at the given path <strong>and</strong> any ZNodes that are children | ||
| * of the given path including children added later. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * NOTE: when there are active recursive watches there is a small performance decrease as all segments | ||
| * of ZNode paths must be checked for watch triggering. | ||
| * </p> | ||
| */ | ||
| PERSISTENT_RECURSIVE(ZooDefs.AddWatchModes.persistentRecursive) | ||
| ; | ||
|
|
||
| public int getMode() { | ||
| return mode; | ||
| } | ||
|
|
||
| private final int mode; | ||
|
|
||
| AddWatchMode(int mode) { | ||
| this.mode = mode; | ||
| } | ||
| } |
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
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.
Although now we have the
Persistent Watches, but we still cannot gurantee that client will see all the watch events without any missing, especially when the connection lost. IIUC, we need document this to let users know?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.
Any other committers agree? Watchers have never guaranteed all events so I don't think it needs to be spelled out here.
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.
No need from my point of view