diff --git a/src/storage/src/redis_hashes.cc b/src/storage/src/redis_hashes.cc index 4d1c9bf6b..ec493014f 100644 --- a/src/storage/src/redis_hashes.cc +++ b/src/storage/src/redis_hashes.cc @@ -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) {} @@ -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(); diff --git a/src/storage/src/redis_lists.cc b/src/storage/src/redis_lists.cc index e2d484b3e..4a364e60c 100644 --- a/src/storage/src/redis_lists.cc +++ b/src/storage/src/redis_lists.cc @@ -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() { @@ -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(); diff --git a/src/storage/src/redis_sets.cc b/src/storage/src/redis_sets.cc index f76217eb3..48ae586e9 100644 --- a/src/storage/src/redis_sets.cc +++ b/src/storage/src/redis_sets.cc @@ -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) { @@ -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(); @@ -872,7 +877,7 @@ rocksdb::Status RedisSets::SPop(const Slice& key, std::vector* 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)); diff --git a/src/storage/src/redis_streams.cc b/src/storage/src/redis_streams.cc index 84e11832b..f57972efb 100644 --- a/src/storage/src/redis_streams.cc +++ b/src/storage/src/redis_streams.cc @@ -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) { @@ -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(); diff --git a/src/storage/src/redis_strings.cc b/src/storage/src/redis_strings.cc index dd4c63dbb..6d937c4a1 100644 --- a/src/storage/src/redis_strings.cc +++ b/src/storage/src/redis_strings.cc @@ -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) {} @@ -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(); @@ -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); } diff --git a/src/storage/src/redis_zsets.cc b/src/storage/src/redis_zsets.cc index 4da415901..e8153e821 100644 --- a/src/storage/src/redis_zsets.cc +++ b/src/storage/src/redis_zsets.cc @@ -19,6 +19,8 @@ #include "src/zsets_filter.h" #include "storage/util.h" +#include "pstd/include/pstd_defer.h" + namespace storage { rocksdb::Comparator* ZSetsScoreKeyComparator() { @@ -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(); @@ -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());