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: delete iter before return for 3.5 branch #2786

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/storage/src/redis_hashes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "src/scope_snapshot.h"
#include "storage/util.h"

#include "pstd/include/pstd_defer.h"

namespace storage {

RedisHashes::RedisHashes(Storage* const s, const DataType& type) : Redis(s, type) {}
Expand Down Expand Up @@ -156,6 +158,9 @@ Status RedisHashes::PKPatternMatchDel(const std::string& pattern, int32_t* ret)
Status s;
rocksdb::WriteBatch batch;
rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[0]);
DEFER {
delete iter;
};
iter->SeekToFirst();
while (iter->Valid()) {
key = iter->key().ToString();
Expand Down
5 changes: 5 additions & 0 deletions src/storage/src/redis_lists.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "src/scope_snapshot.h"
#include "storage/util.h"

#include "pstd/include/pstd_defer.h"

namespace storage {

const rocksdb::Comparator* ListsDataKeyComparator() {
Expand Down Expand Up @@ -163,6 +165,9 @@ Status RedisLists::PKPatternMatchDel(const std::string& pattern, int32_t* ret) {
Status s;
rocksdb::WriteBatch batch;
rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[0]);
DEFER {
delete iter;
};
iter->SeekToFirst();
while (iter->Valid()) {
key = iter->key().ToString();
Expand Down
7 changes: 6 additions & 1 deletion src/storage/src/redis_sets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "src/scope_snapshot.h"
#include "storage/util.h"

#include "pstd/include/pstd_defer.h"

namespace storage {

RedisSets::RedisSets(Storage* const s, const DataType& type) : Redis(s, type) {
Expand Down Expand Up @@ -163,6 +165,9 @@ rocksdb::Status RedisSets::PKPatternMatchDel(const std::string& pattern, int32_t
rocksdb::Status s;
rocksdb::WriteBatch batch;
rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[0]);
DEFER {
delete iter;
};
iter->SeekToFirst();
while (iter->Valid()) {
key = iter->key().ToString();
Expand Down Expand Up @@ -872,7 +877,7 @@ rocksdb::Status RedisSets::SPop(const Slice& key, std::vector<std::string>* memb
//parsed_sets_meta_value.ModifyCount(-cnt);
//batch.Put(handles_[0], key, meta_value);
batch.Delete(handles_[0], key);
delete iter;
delete iter;

} else {
engine.seed(time(nullptr));
Expand Down
5 changes: 5 additions & 0 deletions src/storage/src/redis_streams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "storage/storage.h"
#include "storage/util.h"

#include "pstd/include/pstd_defer.h"

namespace storage {

Status RedisStreams::XAdd(const Slice& key, const std::string& serialized_message, StreamAddTrimArgs& args) {
Expand Down Expand Up @@ -453,6 +455,9 @@ Status RedisStreams::PKPatternMatchDel(const std::string& pattern, int32_t* ret)
Status s;
rocksdb::WriteBatch batch;
rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[0]);
DEFER {
delete iter;
};
iter->SeekToFirst();
while (iter->Valid()) {
key = iter->key().ToString();
Expand Down
9 changes: 7 additions & 2 deletions src/storage/src/redis_strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "src/strings_filter.h"
#include "storage/util.h"

#include "pstd/include/pstd_defer.h"

namespace storage {

RedisStrings::RedisStrings(Storage* const s, const DataType& type) : Redis(s, type) {}
Expand Down Expand Up @@ -126,6 +128,9 @@ Status RedisStrings::PKPatternMatchDel(const std::string& pattern, int32_t* ret)
Status s;
rocksdb::WriteBatch batch;
rocksdb::Iterator* iter = db_->NewIterator(iterator_options);
DEFER {
delete iter;
};
iter->SeekToFirst();
while (iter->Valid()) {
key = iter->key().ToString();
Expand Down Expand Up @@ -1464,8 +1469,8 @@ void RedisStrings::ScanDatabase() {
survival_time =
parsed_strings_value.timestamp() - current_time > 0 ? parsed_strings_value.timestamp() - current_time : -1;
}
LOG(INFO) << fmt::format("[key : {:<30}] [value : {:<30}] [timestamp : {:<10}] [version : {}] [survival_time : {}]", iter->key().ToString(),
parsed_strings_value.value().ToString(), parsed_strings_value.timestamp(), parsed_strings_value.version(),
LOG(INFO) << fmt::format("[key : {:<30}] [value : {:<30}] [timestamp : {:<10}] [version : {}] [survival_time : {}]", iter->key().ToString(),
parsed_strings_value.value().ToString(), parsed_strings_value.timestamp(), parsed_strings_value.version(),
survival_time);

}
Expand Down
7 changes: 6 additions & 1 deletion src/storage/src/redis_zsets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "src/zsets_filter.h"
#include "storage/util.h"

#include "pstd/include/pstd_defer.h"

namespace storage {

rocksdb::Comparator* ZSetsScoreKeyComparator() {
Expand Down Expand Up @@ -179,6 +181,9 @@ Status RedisZSets::PKPatternMatchDel(const std::string& pattern, int32_t* ret) {
rocksdb::WriteBatch batch;
rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[0]);
iter->SeekToFirst();
DEFER {
delete iter;
};
while (iter->Valid()) {
key = iter->key().ToString();
meta_value = iter->value().ToString();
Expand Down Expand Up @@ -1889,7 +1894,7 @@ void RedisZSets::ScanDatabase() {
auto score_iter = db_->NewIterator(iterator_options, handles_[2]);
for (score_iter->SeekToFirst(); score_iter->Valid(); score_iter->Next()) {
ParsedZSetsScoreKey parsed_zsets_score_key(score_iter->key());

LOG(INFO) << fmt::format("[key : {:<30}] [score : {:<20}] [member : {:<20}] [version : {}]",
parsed_zsets_score_key.key().ToString(), parsed_zsets_score_key.score(),
parsed_zsets_score_key.member().ToString(), parsed_zsets_score_key.version());
Expand Down
Loading