-
Notifications
You must be signed in to change notification settings - Fork 526
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ using ROCKSDB_NAMESPACE::Transaction; | |
using ROCKSDB_NAMESPACE::TransactionDB; | ||
using ROCKSDB_NAMESPACE::NewLRUCache; | ||
using ROCKSDB_NAMESPACE::NewBloomFilterPolicy; | ||
using ROCKSDB_NAMESPACE::NewCappedPrefixTransform; | ||
using ROCKSDB_NAMESPACE::NewFixedPrefixTransform; | ||
using ROCKSDB_NAMESPACE::NewBlockBasedTableFactory; | ||
using STORAGE_TYPE = KVStorage::STORAGE_TYPE; | ||
|
||
|
@@ -86,12 +86,17 @@ class RocksDBOptions { | |
std::vector<ColumnFamilyDescriptor> columnFamilies_; | ||
|
||
static const std::string kOrderedColumnFamilyName_; | ||
|
||
std::shared_ptr<rocksdb::Comparator> comparator_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we storing raw value, like
|
||
}; | ||
|
||
class RocksDBStorageComparator : public rocksdb::Comparator { | ||
public: | ||
// if slice1 < slice2, return -1 | ||
// if slice1 > slice2, return 1 | ||
// if slice1 == slice2, return 0 | ||
int Compare(const rocksdb::Slice& slice1, | ||
const rocksdb::Slice& slice2) const { | ||
const rocksdb::Slice& slice2) const override { | ||
std::string key1 = std::string(slice1.data(), slice1.size()); | ||
std::string key2 = std::string(slice2.data(), slice2.size()); | ||
size_t num1 = BinrayString2Number(key1); | ||
|
@@ -111,9 +116,12 @@ class RocksDBStorageComparator : public rocksdb::Comparator { | |
} | ||
|
||
// Ignore the following methods for now | ||
const char* Name() const { return "RocksDBStorageComparator"; } | ||
void FindShortestSeparator(std::string*, const rocksdb::Slice&) const {} | ||
void FindShortSuccessor(std::string*) const {} | ||
const char* Name() const override { return "RocksDBStorageComparator"; } | ||
|
||
void FindShortestSeparator(std::string*, | ||
const rocksdb::Slice&) const override {} | ||
|
||
void FindShortSuccessor(std::string*) const override {} | ||
}; | ||
|
||
class RocksDBStorage : public KVStorage, public StorageTransaction { | ||
|
@@ -336,7 +344,8 @@ class RocksDBStorageIterator : public Iterator { | |
size_(size), | ||
status_(status), | ||
prefixChecking_(true), | ||
ordered_(ordered) { | ||
ordered_(ordered), | ||
iter_(nullptr) { | ||
if (status_ == 0) { | ||
readOptions_ = storage_->ReadOptions(); | ||
if (storage_->InTransaction_) { | ||
|
@@ -375,9 +384,9 @@ class RocksDBStorageIterator : public Iterator { | |
void SeekToFirst() { | ||
auto handler = storage_->GetColumnFamilyHandle(ordered_); | ||
if (storage_->InTransaction_) { | ||
iter_ = storage_->txn_->GetIterator(readOptions_, handler); | ||
iter_.reset(storage_->txn_->GetIterator(readOptions_, handler)); | ||
} else { | ||
iter_ = storage_->db_->NewIterator(readOptions_, handler); | ||
iter_.reset(storage_->db_->NewIterator(readOptions_, handler)); | ||
} | ||
iter_->Seek(prefix_); | ||
} | ||
|
@@ -420,7 +429,7 @@ class RocksDBStorageIterator : public Iterator { | |
int status_; | ||
bool ordered_; | ||
bool prefixChecking_; | ||
rocksdb::Iterator* iter_; | ||
std::unique_ptr<rocksdb::Iterator> iter_; | ||
RocksDBStorage* storage_; | ||
rocksdb::ReadOptions readOptions_; | ||
}; | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
txn_
is the member ofRocksDBStorage
, we should free it manually when transaction finished, thestd::unique_ptr
is not work.