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

curvefs/metaserver: fixed rocksdb storage memory leak caused by unrel… #1388

Merged
merged 1 commit into from
May 6, 2022
Merged

curvefs/metaserver: fixed rocksdb storage memory leak caused by unrel… #1388

merged 1 commit into from
May 6, 2022

Conversation

Wine93
Copy link
Contributor

@Wine93 Wine93 commented May 4, 2022

…easing iterator and transaction.

What problem does this PR solve?

Issue Number: #1381

Problem Summary: rocksdb storage memory leak

What is changed and how it works?

What's Changed:

How it Works:

Side effects(Breaking backward compatibility? Performance regression?):

Check List

  • Relevant documentation/comments is changed or added
  • I acknowledge that all my contributions will be made under the project's license

@Wine93
Copy link
Contributor Author

Wine93 commented May 4, 2022

recheck

@@ -355,6 +361,10 @@ class RocksDBStorageIterator : public Iterator {
storage_->db_->ReleaseSnapshot(readOptions_.snapshot);
}
}

if (iter_ != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

wrap iter_ with a std::unique_ptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrap iter_ with a std::unique_ptr?

fixed.

@@ -86,12 +86,14 @@ class RocksDBOptions {
std::vector<ColumnFamilyDescriptor> columnFamilies_;

static const std::string kOrderedColumnFamilyName_;

std::shared_ptr<rocksdb::Comparator> comparator_;
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no need to wrap it with a std::shared_ptr, just storing the raw value is enough.

Copy link
Contributor Author

@Wine93 Wine93 May 5, 2022

Choose a reason for hiding this comment

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

If we storing raw value, like rocksdb::Comparator*, the memory of comparator object will never be freed:

comparator_ = std::make_shared<RocksDBStorageComparator>();
...
cfOptions.comparator = comparator_.get();

auto unorderedCFOptions = ColumnFamilyOptions();
auto orderedCFOptions = ColumnFamilyOptions();
comparator_ = std::make_shared<RocksDBStorageComparator>();
auto cfOptions = ColumnFamilyOptions();
Copy link
Contributor

Choose a reason for hiding this comment

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

ColumnFamilyOptions cfOptions;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ColumnFamilyOptions cfOptions;

fixed.

return Status::NotSupported();
}
pending4set_.clear();
pending4del_.clear();
return ToStorageStatus(txn_->Rollback());
Status s = ToStorageStatus(txn_->Commit());
delete txn_;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, use std::unique_ptr if possiable

Copy link
Contributor

Choose a reason for hiding this comment

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

agree

Copy link
Contributor Author

@Wine93 Wine93 May 5, 2022

Choose a reason for hiding this comment

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

agree

the txn_ is the member of RocksDBStorage, we should free it manually when transaction finished, the std::unique_ptr is not work.

cfOptions.enable_blob_files = true;
cfOptions.level_compaction_dynamic_level_bytes = true;
cfOptions.compaction_pri = ROCKSDB_NAMESPACE::kMinOverlappingRatio;
cfOptions.prefix_extractor.reset(NewCappedPrefixTransform(3));
Copy link
Contributor

Choose a reason for hiding this comment

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

Does some options here important and add some comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does some options here important and add some comments?

fixed.

return Status::NotSupported();
}
pending4set_.clear();
pending4del_.clear();
return ToStorageStatus(txn_->Rollback());
Status s = ToStorageStatus(txn_->Commit());
delete txn_;
Copy link
Contributor

Choose a reason for hiding this comment

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

agree

@Wine93 Wine93 merged commit f78f563 into opencurve:master May 6, 2022
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.

None yet

3 participants