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

fix memory leak in two_level_iterator #3718

Closed
wants to merge 3 commits into from

Conversation

miasantreble
Copy link
Contributor

@miasantreble miasantreble commented Apr 13, 2018

this PR fixes a few failed contbuild:

  1. ASAN memory leak in Block::NewIterator (table/block.cc:429). the proper destruction of first_level_iter_ and second_level_iter_ of two_level_iterator.cc is missing from the code after the refactoring in Customized BlockBasedTableIterator and LevelIterator #3406
  2. various unused param errors introduced by [codemod] comment unused parameters to turn on -Wunused-parameter flag #3662
  3. updated comment for ForceReleaseCachedEntry to emphasize the use of force_erase flag.

test plan: run asan, clang_release, lite, release, release_481 locally

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@miasantreble has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@miasantreble
Copy link
Contributor Author

@siying PTAL my changes in TwoLevelIterator __dtor

Copy link
Contributor

@ajkr ajkr left a comment

Choose a reason for hiding this comment

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

I don't know about the TwoLevelIterator changes, so am accepting the unused params part only (which could be a whole PR itself)

@@ -642,6 +642,8 @@ int main(int argc, char** argv) {

#else
int main(int argc, char** argv) {
(void) argc;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we comment out never-used variables?

@maysamyabandeh
Copy link
Contributor

I changed the title from "fix memory leak and unused param errors" to more descriptive title of "fix memory leak in two_level_iterator"

@maysamyabandeh maysamyabandeh changed the title fix memory leak and unused param errors fix memory leak in two_level_iterator Apr 13, 2018
@@ -24,7 +24,11 @@ class TwoLevelIterator : public InternalIterator {
explicit TwoLevelIterator(TwoLevelIteratorState* state,
InternalIterator* first_level_iter);

virtual ~TwoLevelIterator() { delete state_; }
virtual ~TwoLevelIterator() {
first_level_iter_.DeleteIter(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the variable that is assigned to false? and why false?

Copy link
Contributor Author

@miasantreble miasantreble Apr 13, 2018

Choose a reason for hiding this comment

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

it's is_arena_mode that dictates whether to call delete or ~InternalIterator(), see https://github.com/facebook/rocksdb/blob/master/table/iterator_wrapper.h#L45
I think by default it was false for both first and second level iter in the original code https://github.com/facebook/rocksdb/pull/3406/files#diff-5fed9b271c2846509d9ad683c2624f26

Copy link
Contributor

Choose a reason for hiding this comment

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

  • Can you put a comment beside the false value? something like /* is_arena_mode */
  • What if later someone uses TwoLevelIterator and passes a first_level_iterator is created using arena? Can we add some comments to NewTwoLevelIterator and NewSecondaryIterator to indicate the contract that the object should not have been created using arena.

@@ -1023,20 +1023,16 @@ class DbStressListener : public EventListener {
column_families_(column_families) {}
virtual ~DbStressListener() {}
#ifndef ROCKSDB_LITE
virtual void OnFlushCompleted(DB* db, const FlushJobInfo& info) override {
assert(db);
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of removing the assert, can we use unused attributed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ajkr suggested these assert are useless since for db_stress they will always be true

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah it seemed strange to me that we're testing whether OnFlushCompleted is passed the right arguments in our stress test, so I suggested deleting those checks rather than maintaining them.

@maysamyabandeh
Copy link
Contributor

why not using attribute((unused))?

@miasantreble
Copy link
Contributor Author

@maysamyabandeh the (void) unused way to resolve unused param issue was use throughout the previous PR #3662, is there advantage to use attribute((unused)) over (void) unused?

@facebook-github-bot
Copy link
Contributor

@miasantreble has updated the pull request. View: changes, changes since last import

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@miasantreble has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@maysamyabandeh
Copy link
Contributor

Can you also add a comment about arena to table/two_level_iterator.h:25

 21 struct TwoLevelIteratorState {
 22   TwoLevelIteratorState() {}
 23
 24   virtual ~TwoLevelIteratorState() {}
 25   virtual InternalIterator* NewSecondaryIterator(const Slice& handle) = 0;
 26 };

@facebook-github-bot
Copy link
Contributor

@miasantreble has updated the pull request. View: changes, changes since last import

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@miasantreble has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@maysamyabandeh
Copy link
Contributor

Seems like you strongly oppose against adding any clarification to NewSecondaryIterator. No problem. I can add it later after you land this.

@miasantreble
Copy link
Contributor Author

@maysamyabandeh No, I don't have problem with that, I missed the line number in your comment so I added in line 20, do you think that's ok or shall I move it to line 25?

@maysamyabandeh
Copy link
Contributor

Thanks @miasantreble. Let me go ahead and land this as I am about concerned about the production services being affected by that.

@miasantreble miasantreble deleted the fix-memory-leak branch April 16, 2018 03:21
maysamyabandeh pushed a commit that referenced this pull request Apr 16, 2018
Summary:
this PR fixes a few failed contbuild:
1. ASAN memory leak in Block::NewIterator (table/block.cc:429). the proper destruction of first_level_iter_ and second_level_iter_ of two_level_iterator.cc is missing from the code after the refactoring in #3406
2. various unused param errors introduced by #3662
3. updated comment for `ForceReleaseCachedEntry` to emphasize the use of `force_erase` flag.
Closes #3718

Reviewed By: maysamyabandeh

Differential Revision: D7621192

Pulled By: miasantreble

fbshipit-source-id: 476c94264083a0730ded957c29de7807e4f5b146
miasantreble added a commit that referenced this pull request Apr 20, 2018
Summary:
this PR fixes a few failed contbuild:
1. ASAN memory leak in Block::NewIterator (table/block.cc:429). the proper destruction of first_level_iter_ and second_level_iter_ of two_level_iterator.cc is missing from the code after the refactoring in #3406
2. various unused param errors introduced by #3662
3. updated comment for `ForceReleaseCachedEntry` to emphasize the use of `force_erase` flag.
Closes #3718

Reviewed By: maysamyabandeh

Differential Revision: D7621192

Pulled By: miasantreble

fbshipit-source-id: 476c94264083a0730ded957c29de7807e4f5b146
maysamyabandeh pushed a commit that referenced this pull request May 8, 2018
Summary:
this PR fixes a few failed contbuild:
1. ASAN memory leak in Block::NewIterator (table/block.cc:429). the proper destruction of first_level_iter_ and second_level_iter_ of two_level_iterator.cc is missing from the code after the refactoring in #3406
2. various unused param errors introduced by #3662
3. updated comment for `ForceReleaseCachedEntry` to emphasize the use of `force_erase` flag.
Closes #3718

Reviewed By: maysamyabandeh

Differential Revision: D7621192

Pulled By: miasantreble

fbshipit-source-id: 476c94264083a0730ded957c29de7807e4f5b146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants