Skip to content

Commit c97fff0

Browse files
committed
Fixed bugs in reviewed code
1 parent 71e92ec commit c97fff0

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/storage/src/redis.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,15 @@ Redis::Redis(Storage* const s, const DataType& type)
2626
}
2727

2828
Redis::~Redis() {
29-
for (auto handle : handles_) {
30-
if (handle != nullptr) {
31-
delete handle;
32-
}
33-
}
29+
std::vector<rocksdb::ColumnFamilyHandle*> tmp_handles = handles_;
3430
handles_.clear();
35-
if (db_ != nullptr) {
36-
delete db_;
37-
db_ = nullptr;
31+
for (auto handle : tmp_handles) {
32+
delete handle;
3833
}
34+
delete db_;
35+
3936
if (default_compact_range_options_.canceled) {
4037
delete default_compact_range_options_.canceled;
41-
default_compact_range_options_.canceled = nullptr;
4238
}
4339
}
4440

src/storage/src/redis_hashes.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ Status RedisHashes::Open(const StorageOptions& storage_options, const std::strin
6464
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
6565
// Data CF
6666
column_families.emplace_back("data_cf", data_cf_ops);
67-
s = rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
68-
return s;
67+
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
6968
}
7069

7170
Status RedisHashes::CompactRange(const rocksdb::Slice* begin, const rocksdb::Slice* end, const ColumnFamilyType& type) {
@@ -424,8 +423,8 @@ Status RedisHashes::HIncrby(const Slice& key, const Slice& field, int64_t value,
424423
UpdateSpecificKeyStatistics(key.ToString(), statistic);
425424
if (s.ok()) {
426425
int32_t current_count = 1;
427-
s = db_->Get(default_read_options_, handles_[0], key, &meta_value);
428-
if (s.ok()) {
426+
427+
if (meta_value.size() > 0) {
429428
ParsedHashesMetaValue parsed_hashes_meta_value(&meta_value);
430429
current_count = parsed_hashes_meta_value.count();
431430
}
@@ -507,8 +506,7 @@ Status RedisHashes::HIncrbyfloat(const Slice& key, const Slice& field, const Sli
507506
UpdateSpecificKeyStatistics(key.ToString(), statistic);
508507
if (s.ok()) {
509508
int32_t current_count = 1;
510-
s = db_->Get(default_read_options_, handles_[0], key, &meta_value);
511-
if (s.ok()) {
509+
if (meta_value.size() > 0) {
512510
ParsedHashesMetaValue parsed_hashes_meta_value(&meta_value);
513511
current_count = parsed_hashes_meta_value.count();
514512
}
@@ -680,8 +678,7 @@ Status RedisHashes::HMSet(const Slice& key, const std::vector<FieldValue>& fvs)
680678
UpdateSpecificKeyStatistics(key.ToString(), statistic);
681679
if (s.ok()) {
682680
int32_t current_count = 1;
683-
s = db_->Get(default_read_options_, handles_[0], key, &meta_value);
684-
if (s.ok()) {
681+
if (meta_value.size() > 0) {
685682
ParsedHashesMetaValue parsed_hashes_meta_value(&meta_value);
686683
current_count = parsed_hashes_meta_value.count();
687684
}
@@ -802,8 +799,7 @@ Status RedisHashes::HSetnx(const Slice& key, const Slice& field, const Slice& va
802799
if (s.ok()) {
803800
int32_t current_count = 1;
804801
if (*ret == 0) {
805-
s = db_->Get(default_read_options_, handles_[0], key, &meta_value);
806-
if (s.ok()) {
802+
if (meta_value.size() > 0) {
807803
ParsedHashesMetaValue parsed_hashes_meta_value(&meta_value);
808804
current_count = parsed_hashes_meta_value.count();
809805
}

0 commit comments

Comments
 (0)