Skip to content
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

[dbnode] Register index.Query/Aggregate finalizers #1567

Merged
merged 2 commits into from
Apr 18, 2019

Conversation

prateek
Copy link
Collaborator

@prateek prateek commented Apr 18, 2019

No description provided.

@@ -868,6 +868,7 @@ func (i *nsIndex) Query(
results.Reset(i.nsMetadata.ID(), index.QueryResultsOptions{
SizeLimit: opts.Limit,
})
ctx.RegisterFinalizer(results)
Copy link
Contributor

Choose a reason for hiding this comment

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

were we really not finalizing these? not even at the RPC layer or something weird?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it looks like the finalize method will Finalize the underlying namespace ID and tags, but not the series ID. Are you sure thats safe in the context of this lifecycle? Where do the namespace IDs, tags, and series ID that end up in this thing come from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We were finalising these (the same way as this PR) until about a month ago, we accidentally dropped it in one of the concurrency PRs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Re: why is it safe?

We ensure the idents and backing bytes are independent copies of the data in the segments. i.e. look at dbnode/storage/index/results.go and dbnode/storage/index/aggregate_results.go. Here's a quick summary:
(1) the Reset() method in both files clones the nsID to start.
(2) AddDocuments() is the only way to add data to results.go and one of two ways to add data to aggregate_results.go. It also clones any data before adding to the map (or relies on the genny generated map's Set() method to do so).
(3) The only other way to add data to aggregate_results.go is the one I'm adding in #1545. In that case, we make an independent copy of the field/terms during iteration, and transfer ownership of those ident/bytes to aggregate_results.go via AddFields().
(4) Re: cleanup - both results.go and aggregate_results.go rely on Finalize() to be called (which is what this PR adds), and that internally calls Reset which in turn releases any idents/bytes/maps to the appropriate pools.

@prateek prateek merged commit 4c31000 into master Apr 18, 2019
@prateek prateek deleted the prateek/dbnode/index-query-results-bf branch April 18, 2019 17:35
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.

2 participants