[
https://issues.apache.org/jira/browse/ZOOKEEPER-442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13850816#comment-13850816
]
Raul Gutierrez Segales commented on ZOOKEEPER-442:
--------------------------------------------------
In:
{noformat}
+ private boolean removeWatches(Map<String, Set<Watcher>> watches,
+ Watcher watcher, String path, boolean local, int rc,
+ Set<Watcher> removedWatchers) {
+ // Check whether watches list contains the given watcher
+ boolean containsWatcher = contains(path, watcher, watches);
+ if (!containsWatcher) {
+ // Watcher not found for the given params
+ return false;
+ }
+
+ // Couldn't remove locally as it doesn't sees a success from server
+ if (!local && watcher == null && rc != Code.OK.intValue()) {
+ return containsWatcher;
{noformat}
shouldn't it return false since it couldn't remove in the server? At that point
containsWatcher is true...
The next part looks wrong too:
{noformat}
+ } else if (!local && rc != Code.OK.intValue()) {
+ Set<Watcher> watchers = watches.get(path);
+ // Couldn't remove locally as it doesn't sees a success from
+ // server
+ if (watchers.size() == 1) {
+ return containsWatcher;
+ } else if (watchers.remove(watcher)) {
+ // found path watcher
+ removedWatchers.add(watcher);
+ return containsWatcher;
+ }
{noformat}
why would watchers.size() == 1 imply that it was that the watches were removed?
Also, would it make since if they API also allowed to remove all watchers for a
given path? Right now it's all or nothing:
{noformat}
+ /**
+ * For the given znode path, removes the specified watcher.
+ *
+ * <p>
+ * If watcher is null all watchers for the given watcherType will be
+ * removed, Otherwise only the specified watcher corresponding to the
+ * watcherType will be removed.
+ * <p>
{noformat}
I think in that case it should be *for that path*. Or, alternatively, if path
is "" or null then go ahead and remove all watchers regardless of their path.
It also makes the documentation more precise (it starts by saying "for a given
znode path" and then it says it can actually remove all watchers regardless).
The change would be minimal.
> need a way to remove watches that are no longer of interest
> -----------------------------------------------------------
>
> Key: ZOOKEEPER-442
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-442
> Project: ZooKeeper
> Issue Type: Sub-task
> Components: java client, server
> Reporter: Benjamin Reed
> Assignee: Rakesh R
> Priority: Critical
> Fix For: 3.5.0
>
> Attachments: Remove Watch API.pdf, ZOOKEEPER-442.patch,
> ZOOKEEPER-442.patch, ZOOKEEPER-442.patch, ZOOKEEPER-442.patch,
> ZOOKEEPER-442.patch, ZOOKEEPER-442.patch, ZOOKEEPER-442.patch,
> ZOOKEEPER-442.patch, ZOOKEEPER-442.patch, ZOOKEEPER-442.patch
>
>
> currently the only way a watch cleared is to trigger it. we need a way to
> enumerate the outstanding watch objects, find watch events the objects are
> watching for, and remove interests in an event.
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)