Skip to content

[CURATOR-477] added support for turning off zk watches#278

Merged
asfgit merged 7 commits intoapache:masterfrom
ramaraochavali:CURATOR-477
Dec 10, 2018
Merged

[CURATOR-477] added support for turning off zk watches#278
asfgit merged 7 commits intoapache:masterfrom
ramaraochavali:CURATOR-477

Conversation

@ramaraochavali
Copy link
Copy Markdown
Contributor

In our use case, we use TreeCache to get Zk Data periodically. We start TreeCache read data and close it. In this use case, The ZkWatchManager of ZooKeeper class keeps growing for every TreeCache operation because new TreeNode objects are created and added there leading to a memory leak. Also since we do not want the Watcher to periodically watch, this creates unnecessary background operations.

In this PR, Made the createZkWatches configurable in the Builder, so that use cases like ours can set it to false. The default is true, retaining the current behaviour.
Fixes the jira issue https://issues.apache.org/jira/browse/CURATOR-477

client.getData().decompressed().usingWatcher(this).inBackground(this).forPath(path);
} else {
client.getData().decompressed().inBackground(this).forPath(path);
}
Copy link
Copy Markdown
Contributor

@dragonsinth dragonsinth Sep 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel like this could all be a little cleaner with a maybeWatch() helper in the class, e.g.

maybeWatch(client.getData().decompressed()).inBackground(this).forPath(path)

and so one throughout. You could also put the inBackground(this) into the helper too

private ExecutorService executorService = null;
private int maxDepth = Integer.MAX_VALUE;
private boolean createParentNodes = false;
private boolean createZkWatches = true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably reverse this as "disableZkWatch" since that's the unusual case.

{
this.createZkWatches = createZkWatches;
return this;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and e.g. disableZkWatches(boolean)

@ramaraochavali
Copy link
Copy Markdown
Contributor Author

@dragonsinth Thanks for your review. addressed the feedback. PTAL

return dataBuilder.usingWatcher(this).inBackground(this);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        private void doRefreshChildren() throws Exception
        {
            if ( treeState.get() == TreeState.STARTED )
            {
                maybeWatch(client.getChildren()).forPath(path);
            }
        }

        private void doRefreshData() throws Exception
        {
            if ( treeState.get() == TreeState.STARTED )
            {
                if ( dataIsCompressed )
                {
                    maybeWatch(client.getData().decompressed()).forPath(path);
                }
                else
                {
                    maybeWatch(client.getData()).forPath(path);
                }
            }
        }

        private <T, P extends Watchable<BackgroundPathable<T>> & BackgroundPathable<T>> Pathable<T> maybeWatch(P dataBuilder)
        {
            if ( disableZkWatches )
            {
                return dataBuilder.inBackground(this);
            }
            else
            {
                return dataBuilder.usingWatcher(this).inBackground(this);
            }
        }

@dragonsinth
Copy link
Copy Markdown
Contributor

TestTreeCache is getting stuck on your branch. Haven't figured out why yet. Wanna take a look?

@ramaraochavali
Copy link
Copy Markdown
Contributor Author

Sorry. My bad. Problem with my change. Fixed. PTAL

@dragonsinth
Copy link
Copy Markdown
Contributor

aha that would do it! I do think you should update the maybeWatch generic method per my other comment

@ramaraochavali
Copy link
Copy Markdown
Contributor Author

Ahh. Sorry. I missed that comment. I have changed it now. PTAL.

@dragonsinth
Copy link
Copy Markdown
Contributor

@Randgalt LGTM, although I haven't rerun tests yet.

@ramaraochavali
Copy link
Copy Markdown
Contributor Author

@dragonsinth sorry. Added one more commit for exists check also. can you PTAL?

Copy link
Copy Markdown
Contributor

@dragonsinth dragonsinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ramaraochavali
Copy link
Copy Markdown
Contributor Author

@Randgalt just following-up on this - Any thing else pending on this?

@cammckenzie
Copy link
Copy Markdown
Contributor

I will merge this shortly, thanks @ramaraochavali and @dragonsinth

@asfgit asfgit merged commit 7e9628e into apache:master Dec 10, 2018
@ramaraochavali ramaraochavali deleted the CURATOR-477 branch December 10, 2018 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants