diff --git a/include/pika_admin.h b/include/pika_admin.h index c1251c7c8f..1ead76725a 100644 --- a/include/pika_admin.h +++ b/include/pika_admin.h @@ -420,9 +420,9 @@ class ScandbCmd : public Cmd { Cmd* Clone() override { return new ScandbCmd(*this); } private: - storage::DataType type_ = storage::kAll; + storage::DataType type_ = storage::DataType::kAll; void DoInitial() override; - void Clear() override { type_ = storage::kAll; } + void Clear() override { type_ = storage::DataType::kAll; } }; class SlowlogCmd : public Cmd { @@ -469,7 +469,7 @@ class PKPatternMatchDelCmd : public Cmd { Cmd* Clone() override { return new PKPatternMatchDelCmd(*this); } private: - storage::DataType type_ = storage::kAll; + storage::DataType type_ = storage::DataType::kAll; std::string pattern_; void DoInitial() override; }; diff --git a/include/pika_kv.h b/include/pika_kv.h index ac50011802..41fc5d53df 100644 --- a/include/pika_kv.h +++ b/include/pika_kv.h @@ -845,7 +845,7 @@ class PKRScanRangeCmd : public Cmd { Cmd* Clone() override { return new PKRScanRangeCmd(*this); } private: - storage::DataType type_ = storage::kAll; + storage::DataType type_ = storage::DataType::kAll; std::string key_start_; std::string key_end_; std::string pattern_ = "*"; diff --git a/src/pika_admin.cc b/src/pika_admin.cc index 13516089ed..19467eabc2 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -2905,18 +2905,18 @@ void ScandbCmd::DoInitial() { return; } if (argv_.size() == 1) { - type_ = storage::kAll; + type_ = storage::DataType::kAll; } else { if (strcasecmp(argv_[1].data(), "string") == 0) { - type_ = storage::kStrings; + type_ = storage::DataType::kStrings; } else if (strcasecmp(argv_[1].data(), "hash") == 0) { - type_ = storage::kHashes; + type_ = storage::DataType::kHashes; } else if (strcasecmp(argv_[1].data(), "set") == 0) { - type_ = storage::kSets; + type_ = storage::DataType::kSets; } else if (strcasecmp(argv_[1].data(), "zset") == 0) { - type_ = storage::kZSets; + type_ = storage::DataType::kZSets; } else if (strcasecmp(argv_[1].data(), "list") == 0) { - type_ = storage::kLists; + type_ = storage::DataType::kLists; } else { res_.SetRes(CmdRes::kInvalidDbType); } diff --git a/src/pika_kv.cc b/src/pika_kv.cc index dec8fdd583..a26e078bfe 100644 --- a/src/pika_kv.cc +++ b/src/pika_kv.cc @@ -1456,11 +1456,11 @@ void TypeCmd::DoInitial() { } void TypeCmd::Do() { - enum storage::RedisType type = storage::RedisType::kNone; + enum storage::DataType type = storage::DataType::kNones; std::string key_type; rocksdb::Status s = db_->storage()->GetType(key_, type); if (s.ok()) { - res_.AppendContent("+" + std::string(RedisTypeToString(type))); + res_.AppendContent("+" + std::string(DataTypeToString(type))); } else if (s_.IsInvalidArgument()) { res_.SetRes(CmdRes::kMultiKey); } else { @@ -1469,12 +1469,12 @@ void TypeCmd::Do() { } void TypeCmd::ReadCache() { - enum storage::RedisType type = storage::RedisType::kNone; + enum storage::DataType type = storage::DataType::kNones; std::string key_type; // TODO Cache GetType function rocksdb::Status s = db_->storage()->GetType(key_, type); if (s.ok()) { - res_.AppendContent("+" + std::string(RedisTypeToString(type))); + res_.AppendContent("+" + std::string(DataTypeToString(type))); } else { res_.SetRes(CmdRes::kCacheMiss, s.ToString()); } @@ -1577,15 +1577,15 @@ void ScanxCmd::DoInitial() { return; } if (strcasecmp(argv_[1].data(), "string") == 0) { - type_ = storage::kStrings; + type_ = storage::DataType::kStrings; } else if (strcasecmp(argv_[1].data(), "hash") == 0) { - type_ = storage::kHashes; + type_ = storage::DataType::kHashes; } else if (strcasecmp(argv_[1].data(), "set") == 0) { - type_ = storage::kSets; + type_ = storage::DataType::kSets; } else if (strcasecmp(argv_[1].data(), "zset") == 0) { - type_ = storage::kZSets; + type_ = storage::DataType::kZSets; } else if (strcasecmp(argv_[1].data(), "list") == 0) { - type_ = storage::kLists; + type_ = storage::DataType::kLists; } else { res_.SetRes(CmdRes::kInvalidDbType); return; @@ -1666,18 +1666,18 @@ void PKScanRangeCmd::DoInitial() { return; } if (strcasecmp(argv_[1].data(), "string_with_value") == 0) { - type_ = storage::kStrings; + type_ = storage::DataType::kStrings; string_with_value = true; } else if (strcasecmp(argv_[1].data(), "string") == 0) { - type_ = storage::kStrings; + type_ = storage::DataType::kStrings; } else if (strcasecmp(argv_[1].data(), "hash") == 0) { - type_ = storage::kHashes; + type_ = storage::DataType::kHashes; } else if (strcasecmp(argv_[1].data(), "set") == 0) { - type_ = storage::kSets; + type_ = storage::DataType::kSets; } else if (strcasecmp(argv_[1].data(), "zset") == 0) { - type_ = storage::kZSets; + type_ = storage::DataType::kZSets; } else if (strcasecmp(argv_[1].data(), "list") == 0) { - type_ = storage::kLists; + type_ = storage::DataType::kLists; } else { res_.SetRes(CmdRes::kInvalidDbType); return; @@ -1724,7 +1724,7 @@ void PKScanRangeCmd::Do() { res_.AppendArrayLen(2); res_.AppendStringLenUint64(next_key.size()); res_.AppendContent(next_key); - if (type_ == storage::kStrings) { + if (type_ == storage::DataType::kStrings) { res_.AppendArrayLenUint64(string_with_value ? 2 * kvs.size() : kvs.size()); for (const auto& kv : kvs) { res_.AppendString(kv.key); @@ -1751,18 +1751,18 @@ void PKRScanRangeCmd::DoInitial() { return; } if (strcasecmp(argv_[1].data(), "string_with_value") == 0) { - type_ = storage::kStrings; + type_ = storage::DataType::kStrings; string_with_value = true; } else if (strcasecmp(argv_[1].data(), "string") == 0) { - type_ = storage::kStrings; + type_ = storage::DataType::kStrings; } else if (strcasecmp(argv_[1].data(), "hash") == 0) { - type_ = storage::kHashes; + type_ = storage::DataType::kHashes; } else if (strcasecmp(argv_[1].data(), "set") == 0) { - type_ = storage::kSets; + type_ = storage::DataType::kSets; } else if (strcasecmp(argv_[1].data(), "zset") == 0) { - type_ = storage::kZSets; + type_ = storage::DataType::kZSets; } else if (strcasecmp(argv_[1].data(), "list") == 0) { - type_ = storage::kLists; + type_ = storage::DataType::kLists; } else { res_.SetRes(CmdRes::kInvalidDbType); return; @@ -1811,7 +1811,7 @@ void PKRScanRangeCmd::Do() { res_.AppendStringLenUint64(next_key.size()); res_.AppendContent(next_key); - if (type_ == storage::kStrings) { + if (type_ == storage::DataType::kStrings) { res_.AppendArrayLenUint64(string_with_value ? 2 * kvs.size() : kvs.size()); for (const auto& kv : kvs) { res_.AppendString(kv.key); diff --git a/src/pika_migrate_thread.cc b/src/pika_migrate_thread.cc index 3045e91d13..a5786381b0 100644 --- a/src/pika_migrate_thread.cc +++ b/src/pika_migrate_thread.cc @@ -137,7 +137,7 @@ static int MigrateKv(net::NetCli *cli, const std::string& key, const std::shared } int r; - if (0 > (r = migrateKeyTTl(cli, key, storage::kStrings, db))) { + if (0 > (r = migrateKeyTTl(cli, key, storage::DataType::kStrings, db))) { return -1; } else { send_num += r; @@ -174,7 +174,7 @@ static int MigrateHash(net::NetCli *cli, const std::string& key, const std::shar if (send_num > 0) { int r; - if ((r = migrateKeyTTl(cli, key, storage::kHashes, db)) < 0) { + if ((r = migrateKeyTTl(cli, key, storage::DataType::kHashes, db)) < 0) { return -1; } else { send_num += r; @@ -224,7 +224,7 @@ static int MigrateList(net::NetCli *cli, const std::string& key, const std::shar // has send del key command if (send_num > 1) { int r; - if (0 > (r = migrateKeyTTl(cli, key, storage::kLists, db))) { + if (0 > (r = migrateKeyTTl(cli, key, storage::DataType::kLists, db))) { return -1; } else { send_num += r; @@ -298,7 +298,7 @@ static int MigrateSet(net::NetCli *cli, const std::string& key, const std::share if (0 < send_num) { int r; - if (0 > (r = migrateKeyTTl(cli, key, storage::kSets, db))) { + if (0 > (r = migrateKeyTTl(cli, key, storage::DataType::kSets, db))) { return -1; } else { send_num += r; @@ -337,7 +337,7 @@ static int MigrateZset(net::NetCli *cli, const std::string& key, const std::shar if (send_num > 0) { int r; - if ((r = migrateKeyTTl(cli, key, storage::kZSets, db)) < 0) { + if ((r = migrateKeyTTl(cli, key, storage::DataType::kZSets, db)) < 0) { return -1; } else { send_num += r; @@ -639,7 +639,7 @@ int PikaMigrateThread::ReqMigrateOne(const std::string& key, const std::shared_p std::unique_lock lm(migrator_mutex_); int slot_id = GetSlotID(g_pika_conf->default_slot_num(), key); - enum storage::RedisType type; + storage::DataType type; char key_type; rocksdb::Status s = db->storage()->GetType(key, type); if (!s.ok()) { @@ -651,32 +651,11 @@ int PikaMigrateThread::ReqMigrateOne(const std::string& key, const std::shared_p return -1; } } - switch (type) { - case storage::RedisType::kString: - key_type = 'k'; - break; - case storage::RedisType::kHash: - key_type = 'h'; - break; - case storage::RedisType::kList: - key_type = 'l'; - break; - case storage::RedisType::kSet: - key_type = 's'; - break; - case storage::RedisType::kZset: - key_type = 'z'; - break; - case storage::RedisType::kStream: - key_type = 'm'; - break; - case storage::RedisType::kNone: - return 0; - default: - LOG(WARNING) << "PikaMigrateThread::ReqMigrateOne key: " << key << " type: " << static_cast(type) << " is illegal"; - return -1; + key_type = storage::DataTypeToTag(type); + if (type == storage::DataType::kNones) { + LOG(WARNING) << "PikaMigrateThread::ReqMigrateOne key: " << key << " type: " << static_cast(type) << " is illegal"; + return -1; } - if (slot_id != slot_id_) { LOG(WARNING) << "PikaMigrateThread::ReqMigrateOne Slot : " << slot_id << " is not the migrating slot:" << slot_id_; return -2; diff --git a/src/pika_server.cc b/src/pika_server.cc index 9147e9b2f0..dc0d6cd8e3 100644 --- a/src/pika_server.cc +++ b/src/pika_server.cc @@ -478,7 +478,7 @@ Status PikaServer::DoSameThingEveryDB(const TaskType& type) { break; } case TaskType::kCompactAll: - db_item.second->Compact(storage::kAll); + db_item.second->Compact(storage::DataType::kAll); break; default: break; diff --git a/src/pika_slot_command.cc b/src/pika_slot_command.cc index 39e472cb1c..95745ad38c 100644 --- a/src/pika_slot_command.cc +++ b/src/pika_slot_command.cc @@ -251,7 +251,6 @@ int PikaMigrate::ParseKey(const std::string& key, const char type, std::string& int command_num = -1; int64_t ttl = 0; rocksdb::Status s; - switch (type) { case 'k': command_num = ParseKKey(key, wbuf_str, db); @@ -760,37 +759,20 @@ void RemSlotKey(const std::string& key, const std::shared_ptr& db) { } int GetKeyType(const std::string& key, std::string& key_type, const std::shared_ptr& db) { - enum storage::RedisType type; + enum storage::DataType type; rocksdb::Status s = db->storage()->GetType(key, type); if (!s.ok()) { LOG(WARNING) << "Get key type error: " << key << " " << s.ToString(); key_type = ""; return -1; } - switch (type) { - case storage::RedisType::kString: - key_type = "k"; - break; - case storage::RedisType::kHash: - key_type = "h"; - break; - case storage::RedisType::kList: - key_type = "l"; - break; - case storage::RedisType::kSet: - key_type = "s"; - break; - case storage::RedisType::kZset: - key_type = "z"; - break; - case storage::RedisType::kStream: - key_type = "m"; - break; - default: - LOG(WARNING) << "Get key type error: " << key; - key_type = ""; - return -1; + auto key_type_char = storage::DataTypeToTag(type); + if (key_type_char == DataTypeToTag(storage::DataType::kNones)) { + LOG(WARNING) << "Get key type error: " << key; + key_type = ""; + return -1; } + key_type = key_type_char; return 1; } @@ -944,7 +926,7 @@ void SlotsMgrtTagSlotCmd::Do() { // check key type int SlotsMgrtTagOneCmd::KeyTypeCheck(const std::shared_ptr& db) { - enum storage::RedisType type; + enum storage::DataType type; std::string key_type; rocksdb::Status s = db->storage()->GetType(key_, type); if (!s.ok()) { @@ -957,29 +939,11 @@ int SlotsMgrtTagOneCmd::KeyTypeCheck(const std::shared_ptr& db) { } return -1; } - switch (type) { - case storage::RedisType::kString: - key_type_ = 'k'; - break; - case storage::RedisType::kHash: - key_type_ = 'h'; - break; - case storage::RedisType::kList: - key_type_ = 'l'; - break; - case storage::RedisType::kSet: - key_type_ = 's'; - break; - case storage::RedisType::kZset: - key_type_ = 'z'; - break; - case storage::RedisType::kStream: - key_type_ = 'm'; - break; - default: - LOG(WARNING) << "Migrate slot key: " << key_ << " not found"; - res_.AppendInteger(0); - return -1; + key_type = storage::DataTypeToTag(type); + if (type == storage::DataType::kNones) { + LOG(WARNING) << "Migrate slot key: " << key_ << " not found"; + res_.AppendInteger(0); + return -1; } return 0; } diff --git a/src/storage/include/storage/storage.h b/src/storage/include/storage/storage.h index 68968cc946..779e52cc3e 100644 --- a/src/storage/include/storage/storage.h +++ b/src/storage/include/storage/storage.h @@ -139,10 +139,6 @@ struct ScoreMember { enum BeforeOrAfter { Before, After }; -enum DataType { kAll, kStrings, kHashes, kSets, kLists, kZSets, kStreams }; - -const char DataTypeTag[] = {'a', 'k', 'h', 's', 'l', 'z', 'x'}; - enum class OptionType { kDB, kColumnFamily, @@ -1032,7 +1028,7 @@ class Storage { // Reutrns the data all type of the key // if single is true, the query will return the first one - Status GetType(const std::string& key, enum RedisType& type); + Status GetType(const std::string& key, enum DataType& type); // Reutrns the data all type of the key Status Type(const std::string& key, std::vector& types); diff --git a/src/storage/src/base_data_value_format.h b/src/storage/src/base_data_value_format.h index 5b92bccc25..ce118613a6 100644 --- a/src/storage/src/base_data_value_format.h +++ b/src/storage/src/base_data_value_format.h @@ -11,9 +11,9 @@ #include "rocksdb/env.h" #include "rocksdb/slice.h" +#include "base_value_format.h" #include "src/coding.h" #include "src/mutex.h" -#include "src/base_value_format.h" #include "storage/storage_define.h" namespace storage { @@ -27,7 +27,7 @@ class BaseDataValue : public InternalValue { /* * The header of the Value field is initially initialized to knulltype */ - explicit BaseDataValue(const rocksdb::Slice& user_value) : InternalValue(RedisType::kNone, user_value) {} + explicit BaseDataValue(const rocksdb::Slice& user_value) : InternalValue(DataType::kNones, user_value) {} virtual ~BaseDataValue() {} virtual rocksdb::Slice Encode() { diff --git a/src/storage/src/base_filter.h b/src/storage/src/base_filter.h index 09badf6f9e..4b13673ef7 100644 --- a/src/storage/src/base_filter.h +++ b/src/storage/src/base_filter.h @@ -36,9 +36,9 @@ class BaseMetaFilter : public rocksdb::CompactionFilter { * The field designs of the remaining zset,set,hash and stream in meta-value * are the same, so the same filtering strategy is used */ - auto type = static_cast(static_cast(value[0])); + auto type = static_cast(static_cast(value[0])); DEBUG("==========================START=========================="); - if (type == RedisType::kString) { + if (type == DataType::kStrings) { ParsedStringsValue parsed_strings_value(value); DEBUG("[StringsFilter] key: {}, value = {}, timestamp: {}, cur_time: {}", key.ToString().c_str(), parsed_strings_value.UserValue().ToString().c_str(), parsed_strings_value.Etime(), cur_time); @@ -49,7 +49,7 @@ class BaseMetaFilter : public rocksdb::CompactionFilter { DEBUG("Reserve"); return false; } - } else if (type == RedisType::kList) { + } else if (type == DataType::kLists) { ParsedListsMetaValue parsed_lists_meta_value(value); DEBUG("[ListMetaFilter], key: {}, count = {}, timestamp: {}, cur_time: {}, version: {}", key.ToString().c_str(), parsed_lists_meta_value.Count(), parsed_lists_meta_value.Etime(), cur_time, @@ -100,7 +100,7 @@ class BaseMetaFilterFactory : public rocksdb::CompactionFilterFactory { class BaseDataFilter : public rocksdb::CompactionFilter { public: - BaseDataFilter(rocksdb::DB* db, std::vector* cf_handles_ptr, enum RedisType type) + BaseDataFilter(rocksdb::DB* db, std::vector* cf_handles_ptr, enum DataType type) : db_(db), cf_handles_ptr_(cf_handles_ptr), type_(type) @@ -135,10 +135,10 @@ class BaseDataFilter : public rocksdb::CompactionFilter { } Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); if (type != type_) { return true; - } else if (type == RedisType::kHash || type == RedisType::kSet || type == RedisType::kStream || type == RedisType::kZset) { + } else if (type == DataType::kHashes || type == DataType::kSets || type == DataType::kStreams || type == DataType::kZSets) { ParsedBaseMetaValue parsed_base_meta_value(&meta_value); meta_not_found_ = false; cur_meta_version_ = parsed_base_meta_value.Version(); @@ -203,12 +203,12 @@ class BaseDataFilter : public rocksdb::CompactionFilter { mutable bool meta_not_found_ = false; mutable uint64_t cur_meta_version_ = 0; mutable uint64_t cur_meta_etime_ = 0; - enum RedisType type_ = RedisType::kNone; + enum DataType type_ = DataType::kNones; }; class BaseDataFilterFactory : public rocksdb::CompactionFilterFactory { public: - BaseDataFilterFactory(rocksdb::DB** db_ptr, std::vector* handles_ptr, enum RedisType type) + BaseDataFilterFactory(rocksdb::DB** db_ptr, std::vector* handles_ptr, enum DataType type) : db_ptr_(db_ptr), cf_handles_ptr_(handles_ptr), type_(type) {} std::unique_ptr CreateCompactionFilter( const rocksdb::CompactionFilter::Context& context) override { @@ -219,7 +219,7 @@ class BaseDataFilterFactory : public rocksdb::CompactionFilterFactory { private: rocksdb::DB** db_ptr_ = nullptr; std::vector* cf_handles_ptr_ = nullptr; - enum RedisType type_ = RedisType::kNone; + enum DataType type_ = DataType::kNones; }; using HashesMetaFilter = BaseMetaFilter; diff --git a/src/storage/src/base_meta_value_format.h b/src/storage/src/base_meta_value_format.h index f5da92a4bc..150774479a 100644 --- a/src/storage/src/base_meta_value_format.h +++ b/src/storage/src/base_meta_value_format.h @@ -24,7 +24,7 @@ class BaseMetaValue : public InternalValue { /* * Constructing MetaValue requires passing in a type value */ - explicit BaseMetaValue(RedisType type, const Slice& user_value) : InternalValue(type, user_value) {} + explicit BaseMetaValue(DataType type, const Slice& user_value) : InternalValue(type, user_value) {} rocksdb::Slice Encode() override { size_t usize = user_value_.size(); size_t needed = usize + kVersionLength + kSuffixReserveLength + 2 * kTimestampLength + kTypeLength; @@ -62,7 +62,7 @@ class ParsedBaseMetaValue : public ParsedInternalValue { explicit ParsedBaseMetaValue(std::string* internal_value_str) : ParsedInternalValue(internal_value_str) { if (internal_value_str->size() >= kBaseMetaValueSuffixLength) { size_t offset = 0; - type_ = static_cast(static_cast((*internal_value_str)[0])); + type_ = static_cast(static_cast((*internal_value_str)[0])); offset += kTypeLength; user_value_ = Slice(internal_value_str->data() + offset, internal_value_str->size() - kBaseMetaValueSuffixLength - offset); @@ -82,7 +82,7 @@ class ParsedBaseMetaValue : public ParsedInternalValue { explicit ParsedBaseMetaValue(const Slice& internal_value_slice) : ParsedInternalValue(internal_value_slice) { if (internal_value_slice.size() >= kBaseMetaValueSuffixLength) { size_t offset = 0; - type_ = static_cast(static_cast(internal_value_slice[0])); + type_ = static_cast(static_cast(internal_value_slice[0])); offset += kTypeLength; user_value_ = Slice(internal_value_slice.data() + offset, internal_value_slice.size() - kBaseMetaValueSuffixLength - offset); diff --git a/src/storage/src/base_value_format.h b/src/storage/src/base_value_format.h index 9e42844384..e41b66d4f1 100644 --- a/src/storage/src/base_value_format.h +++ b/src/storage/src/base_value_format.h @@ -18,22 +18,28 @@ namespace storage { -/* - * Use enumeration types to store data structure types - */ -enum class RedisType : uint8_t { kString = 0, kHash = 1, kList = 2, kSet = 3, kZset = 4, kStream = 5, kNone = 6 }; -constexpr char* RedisTypeStrings[] = {"string", "hash", "list", "set", "zset", "streams", "none"}; - -constexpr char* RedisTypeToString(RedisType type) { - if (type < RedisType::kString || type > RedisType::kNone) { - return RedisTypeStrings[static_cast(RedisType::kNone)]; +enum class DataType : uint8_t { kStrings = 0, kHashes = 1, kLists = 2, kSets = 3, kZSets = 4, kStreams = 5, kNones = 6, kAll = 7 }; + +constexpr char DataTypeTag[] = { 'k', 'h', 's', 'l', 'z', 'x', 'n', 'a'}; +constexpr char* DataTypeStrings[] = { "string", "hash", "set", "list", "zset", "streams", "none", "all"}; + +constexpr char* DataTypeToString(DataType type) { + if (type < DataType::kStrings || type > DataType::kNones) { + return DataTypeStrings[static_cast(DataType::kNones)]; + } + return DataTypeStrings[static_cast(type)]; +} + +constexpr char DataTypeToTag(DataType type) { + if (type < DataType::kStrings || type > DataType::kNones) { + return DataTypeTag[static_cast(DataType::kNones)]; } - return RedisTypeStrings[static_cast(type)]; + return DataTypeTag[static_cast(type)]; } class InternalValue { public: - explicit InternalValue(RedisType type, const rocksdb::Slice& user_value) : type_(type), user_value_(user_value) { + explicit InternalValue(DataType type, const rocksdb::Slice& user_value) : type_(type), user_value_(user_value) { ctime_ = pstd::NowMicros() / 1e6; } @@ -75,7 +81,7 @@ class InternalValue { uint64_t version_ = 0; uint64_t etime_ = 0; uint64_t ctime_ = 0; - RedisType type_; + DataType type_; char reserve_[16] = {0}; }; @@ -148,7 +154,7 @@ class ParsedInternalValue { uint64_t version_ = 0 ; uint64_t ctime_ = 0; uint64_t etime_ = 0; - RedisType type_; + DataType type_; char reserve_[16] = {0}; //unused }; diff --git a/src/storage/src/lists_filter.h b/src/storage/src/lists_filter.h index a05957bc44..f0e1f90678 100644 --- a/src/storage/src/lists_filter.h +++ b/src/storage/src/lists_filter.h @@ -26,7 +26,7 @@ namespace storage { class ListsDataFilter : public rocksdb::CompactionFilter { public: - ListsDataFilter(rocksdb::DB* db, std::vector* cf_handles_ptr, enum RedisType type) + ListsDataFilter(rocksdb::DB* db, std::vector* cf_handles_ptr, enum DataType type) : db_(db), cf_handles_ptr_(cf_handles_ptr), type_(type) @@ -61,7 +61,7 @@ class ListsDataFilter : public rocksdb::CompactionFilter { } rocksdb::Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); if (type != type_) { return true; } @@ -125,12 +125,12 @@ class ListsDataFilter : public rocksdb::CompactionFilter { mutable bool meta_not_found_ = false; mutable uint64_t cur_meta_version_ = 0; mutable uint64_t cur_meta_etime_ = 0; - enum RedisType type_ = RedisType::kNone; + enum DataType type_ = DataType::kNones; }; class ListsDataFilterFactory : public rocksdb::CompactionFilterFactory { public: - ListsDataFilterFactory(rocksdb::DB** db_ptr, std::vector* handles_ptr, enum RedisType type) + ListsDataFilterFactory(rocksdb::DB** db_ptr, std::vector* handles_ptr, enum DataType type) : db_ptr_(db_ptr), cf_handles_ptr_(handles_ptr), type_(type) {} std::unique_ptr CreateCompactionFilter( @@ -142,7 +142,7 @@ class ListsDataFilterFactory : public rocksdb::CompactionFilterFactory { private: rocksdb::DB** db_ptr_ = nullptr; std::vector* cf_handles_ptr_ = nullptr; - enum RedisType type_ = RedisType::kNone; + enum DataType type_ = DataType::kNones; }; } // namespace storage diff --git a/src/storage/src/lists_meta_value_format.h b/src/storage/src/lists_meta_value_format.h index 3bd37040cb..c860ed9e12 100644 --- a/src/storage/src/lists_meta_value_format.h +++ b/src/storage/src/lists_meta_value_format.h @@ -23,7 +23,7 @@ const uint64_t InitalRightIndex = 9223372036854775808U; class ListsMetaValue : public InternalValue { public: explicit ListsMetaValue(const rocksdb::Slice& user_value) - : InternalValue(RedisType::kList, user_value), left_index_(InitalLeftIndex), right_index_(InitalRightIndex) {} + : InternalValue(DataType::kLists, user_value), left_index_(InitalLeftIndex), right_index_(InitalRightIndex) {} rocksdb::Slice Encode() override { size_t usize = user_value_.size(); @@ -82,7 +82,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { assert(internal_value_str->size() >= kListsMetaValueSuffixLength); if (internal_value_str->size() >= kListsMetaValueSuffixLength) { size_t offset = 0; - type_ = static_cast(static_cast((*internal_value_str)[0])); + type_ = static_cast(static_cast((*internal_value_str)[0])); offset += kTypeLength; user_value_ = rocksdb::Slice(internal_value_str->data() + kTypeLength, internal_value_str->size() - kListsMetaValueSuffixLength - kTypeLength); @@ -109,7 +109,7 @@ class ParsedListsMetaValue : public ParsedInternalValue { assert(internal_value_slice.size() >= kListsMetaValueSuffixLength); if (internal_value_slice.size() >= kListsMetaValueSuffixLength) { size_t offset = 0; - type_ = static_cast(static_cast(internal_value_slice[0])); + type_ = static_cast(static_cast(internal_value_slice[0])); offset += kTypeLength; user_value_ = rocksdb::Slice(internal_value_slice.data() + kTypeLength, internal_value_slice.size() - kListsMetaValueSuffixLength - kTypeLength); diff --git a/src/storage/src/pika_stream_meta_value.h b/src/storage/src/pika_stream_meta_value.h index 62443138b9..e010d5c830 100644 --- a/src/storage/src/pika_stream_meta_value.h +++ b/src/storage/src/pika_stream_meta_value.h @@ -25,7 +25,7 @@ static const uint64_t kDefaultStreamValueLength = sizeof(tree_id_t) + sizeof(uint64_t) + 3 * sizeof(streamID) + sizeof(int32_t) + sizeof(uint64_t) + kTypeLength; class StreamMetaValue { public: - explicit StreamMetaValue() : type_(RedisType::kStream) {} + explicit StreamMetaValue() : type_(DataType::kStreams) {} // used only when create a new stream void InitMetaValue() { @@ -86,7 +86,7 @@ class StreamMetaValue { return; } char* pos = &value_[0]; - type_ = static_cast(static_cast((value_)[0])); + type_ = static_cast(static_cast((value_)[0])); pos += kTypeLength; groups_id_ = DecodeFixed32(pos); pos += sizeof(tree_id_t); @@ -205,7 +205,7 @@ class StreamMetaValue { streamID max_deleted_entry_id_; int32_t length_{0}; // number of the messages in the stream uint64_t version_{0}; - RedisType type_; + DataType type_; std::string value_{}; }; @@ -219,7 +219,7 @@ class ParsedStreamMetaValue { return; } char* pos = const_cast(value.data()); - type_ = static_cast(static_cast((value)[0])); + type_ = static_cast(static_cast((value)[0])); pos += kTypeLength; groups_id_ = DecodeFixed32(pos); pos += sizeof(tree_id_t); @@ -278,7 +278,7 @@ class ParsedStreamMetaValue { streamID max_deleted_entry_id_; int32_t length_{0}; // number of the messages in the stream uint64_t version_{0}; - RedisType type_; + DataType type_; }; static const uint64_t kDefaultStreamCGroupValueLength = sizeof(streamID) + sizeof(uint64_t) + 2 * sizeof(tree_id_t) + kTypeLength; diff --git a/src/storage/src/redis.cc b/src/storage/src/redis.cc index 66f7acc33e..66604aec7e 100644 --- a/src/storage/src/redis.cc +++ b/src/storage/src/redis.cc @@ -86,7 +86,7 @@ Status Redis::Open(const StorageOptions& storage_options, const std::string& db_ // hash column-family options rocksdb::ColumnFamilyOptions hash_data_cf_ops(storage_options.options); - hash_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, RedisType::kHash); + hash_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, DataType::kHashes); rocksdb::BlockBasedTableOptions hash_data_cf_table_ops(table_ops); if (!storage_options.share_block_cache && storage_options.block_cache_size > 0) { hash_data_cf_table_ops.block_cache = rocksdb::NewLRUCache(storage_options.block_cache_size); @@ -95,7 +95,7 @@ Status Redis::Open(const StorageOptions& storage_options, const std::string& db_ // list column-family options rocksdb::ColumnFamilyOptions list_data_cf_ops(storage_options.options); - list_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, RedisType::kList); + list_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, DataType::kLists); list_data_cf_ops.comparator = ListsDataKeyComparator(); rocksdb::BlockBasedTableOptions list_data_cf_table_ops(table_ops); @@ -106,7 +106,7 @@ Status Redis::Open(const StorageOptions& storage_options, const std::string& db_ // set column-family options rocksdb::ColumnFamilyOptions set_data_cf_ops(storage_options.options); - set_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, RedisType::kSet); + set_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, DataType::kSets); rocksdb::BlockBasedTableOptions set_data_cf_table_ops(table_ops); if (!storage_options.share_block_cache && storage_options.block_cache_size > 0) { set_data_cf_table_ops.block_cache = rocksdb::NewLRUCache(storage_options.block_cache_size); @@ -116,8 +116,8 @@ Status Redis::Open(const StorageOptions& storage_options, const std::string& db_ // zset column-family options rocksdb::ColumnFamilyOptions zset_data_cf_ops(storage_options.options); rocksdb::ColumnFamilyOptions zset_score_cf_ops(storage_options.options); - zset_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, RedisType::kZset); - zset_score_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, RedisType::kZset); + zset_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, DataType::kZSets); + zset_score_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, DataType::kZSets); zset_score_cf_ops.comparator = ZSetsScoreKeyComparator(); rocksdb::BlockBasedTableOptions zset_meta_cf_table_ops(table_ops); @@ -131,7 +131,7 @@ Status Redis::Open(const StorageOptions& storage_options, const std::string& db_ // stream column-family options rocksdb::ColumnFamilyOptions stream_data_cf_ops(storage_options.options); - stream_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, RedisType::kStream); + stream_data_cf_ops.compaction_filter_factory = std::make_shared(&db_, &handles_, DataType::kStreams); rocksdb::BlockBasedTableOptions stream_data_cf_table_ops(table_ops); if (!storage_options.share_block_cache && storage_options.block_cache_size > 0) { stream_data_cf_table_ops.block_cache = rocksdb::NewLRUCache(storage_options.block_cache_size); @@ -157,7 +157,7 @@ Status Redis::Open(const StorageOptions& storage_options, const std::string& db_ Status Redis::GetScanStartPoint(const DataType& type, const Slice& key, const Slice& pattern, int64_t cursor, std::string* start_point) { std::string index_key; - index_key.append(1, DataTypeTag[type]); + index_key.append(1, DataTypeTag[static_cast(type)]); index_key.append("_"); index_key.append(key.ToString()); index_key.append("_"); @@ -170,7 +170,7 @@ Status Redis::GetScanStartPoint(const DataType& type, const Slice& key, const Sl Status Redis::StoreScanNextPoint(const DataType& type, const Slice& key, const Slice& pattern, int64_t cursor, const std::string& next_point) { std::string index_key; - index_key.append(1, DataTypeTag[type]); + index_key.append(1, DataTypeTag[static_cast(type)]); index_key.append("_"); index_key.append(key.ToString()); index_key.append("_"); @@ -213,7 +213,7 @@ Status Redis::UpdateSpecificKeyStatistics(const DataType& dtype, const std::stri if ((statistics_store_->Capacity() != 0U) && (count != 0U) && (small_compaction_threshold_ != 0U)) { KeyStatistics data; std::string lkp_key; - lkp_key.append(1, DataTypeTag[dtype]); + lkp_key.append(1, DataTypeTag[static_cast(dtype)]); lkp_key.append(key); statistics_store_->Lookup(lkp_key, &data); data.AddModifyCount(count); @@ -227,7 +227,7 @@ Status Redis::UpdateSpecificKeyDuration(const DataType& dtype, const std::string if ((statistics_store_->Capacity() != 0U) && (duration != 0U) && (small_compaction_duration_threshold_ != 0U)) { KeyStatistics data; std::string lkp_key; - lkp_key.append(1, DataTypeTag[dtype]); + lkp_key.append(1, DataTypeTag[static_cast(dtype)]); lkp_key.append(key); statistics_store_->Lookup(lkp_key, &data); data.AddDuration(duration); @@ -241,7 +241,7 @@ Status Redis::AddCompactKeyTaskIfNeeded(const DataType& dtype, const std::string if (total < small_compaction_threshold_ || duration < small_compaction_duration_threshold_) { return Status::OK(); } else { - std::string lkp_key(1, DataTypeTag[dtype]); + std::string lkp_key(1, DataTypeTag[static_cast(dtype)]); lkp_key.append(key); storage_->AddBGTask({dtype, kCompactRange, {key}}); statistics_store_->Remove(lkp_key); diff --git a/src/storage/src/redis.h b/src/storage/src/redis.h index bbdf7660fe..71d4d67db3 100644 --- a/src/storage/src/redis.h +++ b/src/storage/src/redis.h @@ -188,7 +188,7 @@ class Redis { Status TTL(const Slice& key, int64_t* timestamp); Status PKPatternMatchDel(const std::string& pattern, int32_t* ret); - Status GetType(const Slice& key, enum RedisType& type); + Status GetType(const Slice& key, enum DataType& type); Status IsExist(const Slice& key); // Hash Commands Status HDel(const Slice& key, const std::vector& fields, int32_t* ret); @@ -353,7 +353,7 @@ class Redis { void ScanSets(); TypeIterator* CreateIterator(const DataType& type, const std::string& pattern, const Slice* lower_bound, const Slice* upper_bound) { - return CreateIterator(DataTypeTag[type], pattern, lower_bound, upper_bound); + return CreateIterator(DataTypeTag[static_cast(type)], pattern, lower_bound, upper_bound); } TypeIterator* CreateIterator(const char& type, const std::string& pattern, const Slice* lower_bound, const Slice* upper_bound) { @@ -389,13 +389,13 @@ class Redis { return nullptr; } - enum RedisType GetMetaValueType(const std::string &meta_value) { - RedisType meta_type = static_cast(static_cast(meta_value[0])); + enum DataType GetMetaValueType(const std::string &meta_value) { + DataType meta_type = static_cast(static_cast(meta_value[0])); return meta_type; } - inline bool ExpectedMetaValue(enum RedisType type, const std::string &meta_value) { - auto meta_type = static_cast(static_cast(meta_value[0])); + inline bool ExpectedMetaValue(enum DataType type, const std::string &meta_value) { + auto meta_type = static_cast(static_cast(meta_value[0])); if (type == meta_type) { return true; } @@ -403,18 +403,18 @@ class Redis { } inline bool ExpectedStale(const std::string &meta_value) { - auto meta_type = static_cast(static_cast(meta_value[0])); - if (meta_type == RedisType::kZset || meta_type == RedisType::kSet || meta_type == RedisType::kHash) { + auto meta_type = static_cast(static_cast(meta_value[0])); + if (meta_type == DataType::kZSets || meta_type == DataType::kSets || meta_type == DataType::kHashes) { ParsedBaseMetaValue parsed_meta_value(meta_value); if (parsed_meta_value.IsStale() || parsed_meta_value.Count() == 0) { return true; } - } else if (meta_type == RedisType::kList) { + } else if (meta_type == DataType::kLists) { ParsedListsMetaValue parsed_lists_meta_value(meta_value); if (parsed_lists_meta_value.IsStale() || parsed_lists_meta_value.Count() == 0) { return true; } - } else if (meta_type == RedisType::kStream) { + } else if (meta_type == DataType::kStreams) { StreamMetaValue stream_meta_value; if (stream_meta_value.length() == 0) { return true; diff --git a/src/storage/src/redis_hashes.cc b/src/storage/src/redis_hashes.cc index 8fedcd88e3..e256757e43 100644 --- a/src/storage/src/redis_hashes.cc +++ b/src/storage/src/redis_hashes.cc @@ -36,7 +36,7 @@ Status Redis::ScanHashesKeyNum(KeyInfo* key_info) { rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { - if (!ExpectedMetaValue(RedisType::kHash, iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kHashes, iter->value().ToString())) { continue; } ParsedHashesMetaValue parsed_hashes_meta_value(iter->value()); @@ -84,11 +84,11 @@ Status Redis::HDel(const Slice& key, const std::vector& fields, int BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -145,11 +145,11 @@ Status Redis::HGet(const Slice& key, const Slice& field, std::string* value) { BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -182,11 +182,11 @@ Status Redis::HGetall(const Slice& key, std::vector* fvs) { BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -222,11 +222,11 @@ Status Redis::HGetallWithTTL(const Slice& key, std::vector* fvs, int read_options.snapshot = snapshot; BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -277,11 +277,11 @@ Status Redis::HIncrby(const Slice& key, const Slice& field, int64_t value, int64 Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); char value_buf[32] = {0}; char meta_value_buf[4] = {0}; - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -330,7 +330,7 @@ Status Redis::HIncrby(const Slice& key, const Slice& field, int64_t value, int64 } } else if (s.IsNotFound()) { EncodeFixed32(meta_value_buf, 1); - HashesMetaValue hashes_meta_value(RedisType::kHash, Slice(meta_value_buf, 4)); + HashesMetaValue hashes_meta_value(DataType::kHashes, Slice(meta_value_buf, 4)); version = hashes_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_meta_key.Encode(), hashes_meta_value.Encode()); HashesDataKey hashes_data_key(key, version, field); @@ -366,11 +366,11 @@ Status Redis::HIncrbyfloat(const Slice& key, const Slice& field, const Slice& by BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); char meta_value_buf[4] = {0}; - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -420,7 +420,7 @@ Status Redis::HIncrbyfloat(const Slice& key, const Slice& field, const Slice& by } } else if (s.IsNotFound()) { EncodeFixed32(meta_value_buf, 1); - HashesMetaValue hashes_meta_value(RedisType::kHash, Slice(meta_value_buf, 4)); + HashesMetaValue hashes_meta_value(DataType::kHashes, Slice(meta_value_buf, 4)); version = hashes_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_meta_key.Encode(), hashes_meta_value.Encode()); @@ -448,11 +448,11 @@ Status Redis::HKeys(const Slice& key, std::vector* fields) { BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -483,11 +483,11 @@ Status Redis::HLen(const Slice& key, int32_t* ret) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -519,11 +519,11 @@ Status Redis::HMGet(const Slice& key, const std::vector& fields, st read_options.snapshot = snapshot; BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -580,11 +580,11 @@ Status Redis::HMSet(const Slice& key, const std::vector& fvs) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); char meta_value_buf[4] = {0}; - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -627,7 +627,7 @@ Status Redis::HMSet(const Slice& key, const std::vector& fvs) { } } else if (s.IsNotFound()) { EncodeFixed32(meta_value_buf, filtered_fvs.size()); - HashesMetaValue hashes_meta_value(RedisType::kHash, Slice(meta_value_buf, 4)); + HashesMetaValue hashes_meta_value(DataType::kHashes, Slice(meta_value_buf, 4)); version = hashes_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_meta_key.Encode(), hashes_meta_value.Encode()); for (const auto& fv : filtered_fvs) { @@ -652,11 +652,11 @@ Status Redis::HSet(const Slice& key, const Slice& field, const Slice& value, int BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); char meta_value_buf[4] = {0}; - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -698,7 +698,7 @@ Status Redis::HSet(const Slice& key, const Slice& field, const Slice& value, int } } else if (s.IsNotFound()) { EncodeFixed32(meta_value_buf, 1); - HashesMetaValue hashes_meta_value(RedisType::kHash, Slice(meta_value_buf, 4)); + HashesMetaValue hashes_meta_value(DataType::kHashes, Slice(meta_value_buf, 4)); version = hashes_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_meta_key.Encode(), hashes_meta_value.Encode()); HashesDataKey data_key(key, version, field); @@ -724,11 +724,11 @@ Status Redis::HSetnx(const Slice& key, const Slice& field, const Slice& value, i BaseDataValue internal_value(value); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); char meta_value_buf[4] = {0}; - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -761,7 +761,7 @@ Status Redis::HSetnx(const Slice& key, const Slice& field, const Slice& value, i } } else if (s.IsNotFound()) { EncodeFixed32(meta_value_buf, 1); - HashesMetaValue hashes_meta_value(RedisType::kHash, Slice(meta_value_buf, 4)); + HashesMetaValue hashes_meta_value(DataType::kHashes, Slice(meta_value_buf, 4)); version = hashes_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_meta_key.Encode(), hashes_meta_value.Encode()); HashesDataKey hashes_data_key(key, version, field); @@ -784,11 +784,11 @@ Status Redis::HVals(const Slice& key, std::vector* values) { BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -844,11 +844,11 @@ Status Redis::HScan(const Slice& key, int64_t cursor, const std::string& pattern BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -918,11 +918,11 @@ Status Redis::HScanx(const Slice& key, const std::string& start_field, const std BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -986,11 +986,11 @@ Status Redis::PKHScanRange(const Slice& key, const Slice& field_start, const std BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1055,11 +1055,11 @@ Status Redis::PKHRScanRange(const Slice& key, const Slice& field_start, const st BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1109,11 +1109,11 @@ Status Redis::HashesExpire(const Slice& key, int64_t ttl) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1141,11 +1141,11 @@ Status Redis::HashesDel(const Slice& key) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1170,11 +1170,11 @@ Status Redis::HashesExpireat(const Slice& key, int64_t timestamp) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1201,11 +1201,11 @@ Status Redis::HashesPersist(const Slice& key) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1232,11 +1232,11 @@ Status Redis::HashesTTL(const Slice& key, int64_t* timestamp) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kHash, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kHashes, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kHash)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kHashes)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1274,7 +1274,7 @@ void Redis::ScanHashes() { LOG(INFO) << "***************" << "rocksdb instance: " << index_ << " Hashes Meta Data***************"; auto meta_iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (meta_iter->SeekToFirst(); meta_iter->Valid(); meta_iter->Next()) { - if (!ExpectedMetaValue(RedisType::kHash, meta_iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kHashes, meta_iter->value().ToString())) { continue; } ParsedHashesMetaValue parsed_hashes_meta_value(meta_iter->value()); diff --git a/src/storage/src/redis_lists.cc b/src/storage/src/redis_lists.cc index effd7a99e3..1998a76d23 100644 --- a/src/storage/src/redis_lists.cc +++ b/src/storage/src/redis_lists.cc @@ -35,7 +35,7 @@ Status Redis::ScanListsKeyNum(KeyInfo* key_info) { rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { - if (!ExpectedMetaValue(RedisType::kList, iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kLists, iter->value().ToString())) { continue; } ParsedListsMetaValue parsed_lists_meta_value(iter->value()); @@ -68,11 +68,11 @@ Status Redis::LIndex(const Slice& key, int64_t index, std::string* element) { BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -109,11 +109,11 @@ Status Redis::LInsert(const Slice& key, const BeforeOrAfter& before_or_after, co BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -217,11 +217,11 @@ Status Redis::LLen(const Slice& key, uint64_t* len) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -249,11 +249,11 @@ Status Redis::LPop(const Slice& key, int64_t count, std::vector* el BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -304,11 +304,11 @@ Status Redis::LPush(const Slice& key, const std::vector& values, ui BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -357,11 +357,11 @@ Status Redis::LPushx(const Slice& key, const std::vector& values, u BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -398,11 +398,11 @@ Status Redis::LRange(const Slice& key, int64_t start, int64_t stop, std::vector< std::string meta_value; BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -455,11 +455,11 @@ Status Redis::LRangeWithTTL(const Slice& key, int64_t start, int64_t stop, std:: std::string meta_value; BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -522,11 +522,11 @@ Status Redis::LRem(const Slice& key, int64_t count, const Slice& value, uint64_t BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -651,11 +651,11 @@ Status Redis::LSet(const Slice& key, int64_t index, const Slice& value) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -692,11 +692,11 @@ Status Redis::LTrim(const Slice& key, int64_t start, int64_t stop) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -762,11 +762,11 @@ Status Redis::RPop(const Slice& key, int64_t count, std::vector* el BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -816,11 +816,11 @@ Status Redis::RPoplpush(const Slice& source, const Slice& destination, std::stri std::string meta_value; BaseMetaKey base_source(source); s = db_->Get(default_read_options_, handles_[kMetaCF], base_source.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -868,11 +868,11 @@ Status Redis::RPoplpush(const Slice& source, const Slice& destination, std::stri std::string source_meta_value; BaseMetaKey base_source(source); s = db_->Get(default_read_options_, handles_[kMetaCF], base_source.Encode(), &source_meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, source_meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, source_meta_value)) { if (ExpectedStale(source_meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + source.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(source_meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + source.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(source_meta_value))]); } } if (s.ok()) { @@ -903,11 +903,11 @@ Status Redis::RPoplpush(const Slice& source, const Slice& destination, std::stri std::string destination_meta_value; BaseMetaKey base_destination(destination); s = db_->Get(default_read_options_, handles_[kMetaCF], base_destination.Encode(), &destination_meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, destination_meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, destination_meta_value)) { if (ExpectedStale(destination_meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(destination_meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(destination_meta_value))]); } } if (s.ok()) { @@ -957,11 +957,11 @@ Status Redis::RPush(const Slice& key, const std::vector& values, ui BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1010,11 +1010,11 @@ Status Redis::RPushx(const Slice& key, const std::vector& values, u BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1047,11 +1047,11 @@ Status Redis::ListsExpire(const Slice& key, int64_t ttl) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1079,11 +1079,11 @@ Status Redis::ListsDel(const Slice& key) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1108,11 +1108,11 @@ Status Redis::ListsExpireat(const Slice& key, int64_t timestamp) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1138,11 +1138,11 @@ Status Redis::ListsPersist(const Slice& key) { ScopeRecordLock l(lock_mgr_, key); BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1169,11 +1169,11 @@ Status Redis::ListsTTL(const Slice& key, int64_t* timestamp) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kList, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kLists, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kList)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kLists)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1211,7 +1211,7 @@ void Redis::ScanLists() { LOG(INFO) << "*************** " << "rocksdb instance: " << index_ << " List Meta ***************"; auto meta_iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (meta_iter->SeekToFirst(); meta_iter->Valid(); meta_iter->Next()) { - if (!ExpectedMetaValue(RedisType::kList, meta_iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kLists, meta_iter->value().ToString())) { continue; } ParsedListsMetaValue parsed_lists_meta_value(meta_iter->value()); diff --git a/src/storage/src/redis_sets.cc b/src/storage/src/redis_sets.cc index d436cf2b3d..9fc400d039 100644 --- a/src/storage/src/redis_sets.cc +++ b/src/storage/src/redis_sets.cc @@ -39,7 +39,7 @@ rocksdb::Status Redis::ScanSetsKeyNum(KeyInfo* key_info) { rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { - if (!ExpectedMetaValue(RedisType::kSet, iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kSets, iter->value().ToString())) { continue; } ParsedSetsMetaValue parsed_sets_meta_value(iter->value()); @@ -79,11 +79,11 @@ rocksdb::Status Redis::SAdd(const Slice& key, const std::vector& me BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -131,7 +131,7 @@ rocksdb::Status Redis::SAdd(const Slice& key, const std::vector& me } else if (s.IsNotFound()) { char str[4]; EncodeFixed32(str, filtered_members.size()); - SetsMetaValue sets_meta_value(RedisType::kSet, Slice(str, 4)); + SetsMetaValue sets_meta_value(DataType::kSets, Slice(str, 4)); version = sets_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_meta_key.Encode(), sets_meta_value.Encode()); for (const auto& member : filtered_members) { @@ -152,11 +152,11 @@ rocksdb::Status Redis::SCard(const Slice& key, int32_t* ret) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -191,11 +191,11 @@ rocksdb::Status Redis::SDiff(const std::vector& keys, std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -210,11 +210,11 @@ rocksdb::Status Redis::SDiff(const std::vector& keys, std::vectorGet(read_options, handles_[kMetaCF], base_meta_key0.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[0] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[0] + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -276,11 +276,11 @@ rocksdb::Status Redis::SDiffstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -296,11 +296,11 @@ rocksdb::Status Redis::SDiffstore(const Slice& destination, const std::vector members; BaseMetaKey base_meta_key0(keys[0]); s = db_->Get(read_options, handles_[kMetaCF], base_meta_key0.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[0] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[0] + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -342,11 +342,11 @@ rocksdb::Status Redis::SDiffstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_destination.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -361,7 +361,7 @@ rocksdb::Status Redis::SDiffstore(const Slice& destination, const std::vector& keys, std::vector< for (uint32_t idx = 1; idx < keys.size(); ++idx) { BaseMetaKey base_meta_key(keys[idx]); s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -420,11 +420,11 @@ rocksdb::Status Redis::SInter(const std::vector& keys, std::vector< BaseMetaKey base_meta_key0(keys[0]); s = db_->Get(read_options, handles_[kMetaCF], base_meta_key0.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[0] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[0] + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -492,11 +492,11 @@ rocksdb::Status Redis::SInterstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -519,11 +519,11 @@ rocksdb::Status Redis::SInterstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key0.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[0] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[0] + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -571,11 +571,11 @@ rocksdb::Status Redis::SInterstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_destination.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -590,7 +590,7 @@ rocksdb::Status Redis::SInterstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -657,18 +657,18 @@ rocksdb::Status Redis::SMembers(const Slice& key, std::vector* memb BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -705,11 +705,11 @@ Status Redis::SMembersWithTTL(const Slice& key, read_options.snapshot = snapshot; BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -764,11 +764,11 @@ rocksdb::Status Redis::SMove(const Slice& source, const Slice& destination, cons BaseMetaKey base_source(source); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_source.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + source.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + source.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -807,11 +807,11 @@ rocksdb::Status Redis::SMove(const Slice& source, const Slice& destination, cons BaseMetaKey base_destination(destination); s = db_->Get(default_read_options_, handles_[kMetaCF], base_destination.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -843,7 +843,7 @@ rocksdb::Status Redis::SMove(const Slice& source, const Slice& destination, cons } else if (s.IsNotFound()) { char str[4]; EncodeFixed32(str, 1); - SetsMetaValue sets_meta_value(RedisType::kSet, Slice(str, 4)); + SetsMetaValue sets_meta_value(DataType::kSets, Slice(str, 4)); version = sets_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_destination.Encode(), sets_meta_value.Encode()); SetsMemberKey sets_member_key(destination, version, member); @@ -868,11 +868,11 @@ rocksdb::Status Redis::SPop(const Slice& key, std::vector* members, BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -982,11 +982,11 @@ rocksdb::Status Redis::SRandmember(const Slice& key, int32_t count, std::vector< BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1053,11 +1053,11 @@ rocksdb::Status Redis::SRem(const Slice& key, const std::vector& me BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1117,11 +1117,11 @@ rocksdb::Status Redis::SUnion(const std::vector& keys, std::vector< for (const auto & key : keys) { BaseMetaKey base_meta_key(key); s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1174,11 +1174,11 @@ rocksdb::Status Redis::SUnionstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1213,11 +1213,11 @@ rocksdb::Status Redis::SUnionstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_destination.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1232,7 +1232,7 @@ rocksdb::Status Redis::SUnionstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1335,11 +1335,11 @@ rocksdb::Status Redis::SetsExpire(const Slice& key, int64_t ttl) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1367,11 +1367,11 @@ rocksdb::Status Redis::SetsDel(const Slice& key) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1396,11 +1396,11 @@ rocksdb::Status Redis::SetsExpireat(const Slice& key, int64_t timestamp) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1427,11 +1427,11 @@ rocksdb::Status Redis::SetsPersist(const Slice& key) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1458,11 +1458,11 @@ rocksdb::Status Redis::SetsTTL(const Slice& key, int64_t* timestamp) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kSet)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1500,7 +1500,7 @@ void Redis::ScanSets() { LOG(INFO) << "***************Sets Meta Data***************"; auto meta_iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (meta_iter->SeekToFirst(); meta_iter->Valid(); meta_iter->Next()) { - if (!ExpectedMetaValue(RedisType::kSet, meta_iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kSets, meta_iter->value().ToString())) { continue; } ParsedSetsMetaValue parsed_sets_meta_value(meta_iter->value()); diff --git a/src/storage/src/redis_streams.cc b/src/storage/src/redis_streams.cc index e0876b5dd7..47942244c5 100644 --- a/src/storage/src/redis_streams.cc +++ b/src/storage/src/redis_streams.cc @@ -343,7 +343,7 @@ Status Redis::ScanStreamsKeyNum(KeyInfo* key_info) { rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { - if (!ExpectedMetaValue(RedisType::kStream, iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kStreams, iter->value().ToString())) { continue; } ParsedStreamMetaValue parsed_stream_meta_value(iter->value()); @@ -364,11 +364,11 @@ Status Redis::StreamsDel(const Slice& key) { std::string meta_value; BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kStream, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStreams, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kStream)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStreams)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -391,11 +391,11 @@ Status Redis::GetStreamMeta(StreamMetaValue& stream_meta, const rocksdb::Slice& std::string value; BaseMetaKey base_meta_key(key); auto s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kStream, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStreams, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kStream)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStreams)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { diff --git a/src/storage/src/redis_strings.cc b/src/storage/src/redis_strings.cc index 2d1cdb9c9e..57319369ba 100644 --- a/src/storage/src/redis_strings.cc +++ b/src/storage/src/redis_strings.cc @@ -40,7 +40,7 @@ Status Redis::ScanStringsKeyNum(KeyInfo* key_info) { // a parameter, use the default column family rocksdb::Iterator* iter = db_->NewIterator(iterator_options); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { - if (!ExpectedMetaValue(RedisType::kString, iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kStrings, iter->value().ToString())) { continue; } ParsedStringsValue parsed_strings_value(iter->value()); @@ -70,11 +70,11 @@ Status Redis::Append(const Slice& key, const Slice& value, int32_t* ret) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -123,11 +123,11 @@ Status Redis::BitCount(const Slice& key, int64_t start_offset, int64_t end_offse BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -226,11 +226,11 @@ Status Redis::BitOp(BitOpType op, const std::string& dest_key, const std::vector std::string value; BaseKey base_key(src_key); s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + dest_key + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + dest_key + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -269,11 +269,11 @@ Status Redis::Decrby(const Slice& key, int64_t value, int64_t* ret) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -317,11 +317,11 @@ Status Redis::Get(const Slice& key, std::string* value) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), value); std::string meta_value = *value; - if (s.ok() && !ExpectedMetaValue(RedisType::kString, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -342,7 +342,7 @@ Status Redis::MGet(const Slice& key, std::string* value) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), value); std::string meta_value = *value; - if (s.ok() && !ExpectedMetaValue(RedisType::kString, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, meta_value)) { return Status::NotFound(); } if (s.ok()) { @@ -362,11 +362,11 @@ Status Redis::GetWithTTL(const Slice& key, std::string* value, int64_t* ttl) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), value); std::string meta_value = *value; - if (s.ok() && !ExpectedMetaValue(RedisType::kString, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -401,11 +401,11 @@ Status Redis::GetBit(const Slice& key, int64_t offset, int32_t* ret) { Status s = db_->Get(default_read_options_, base_key.Encode(), &meta_value); if (s.ok() || s.IsNotFound()) { std::string data_value; - if (s.ok() && !ExpectedMetaValue(RedisType::kString, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -436,11 +436,11 @@ Status Redis::Getrange(const Slice& key, int64_t start_offset, int64_t end_offse BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -478,11 +478,11 @@ Status Redis::GetrangeWithValue(const Slice& key, int64_t start_offset, int64_t BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), value); std::string meta_value = *value; - if (s.ok() && !ExpectedMetaValue(RedisType::kString, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -537,11 +537,11 @@ Status Redis::GetSet(const Slice& key, const Slice& value, std::string* old_valu BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), old_value); std::string meta_value = *old_value; - if (s.ok() && !ExpectedMetaValue(RedisType::kString, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -566,11 +566,11 @@ Status Redis::Incrby(const Slice& key, int64_t value, int64_t* ret) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); char buf[32] = {0}; - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -618,11 +618,11 @@ Status Redis::Incrbyfloat(const Slice& key, const Slice& value, std::string* ret BaseKey base_key(key); ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -684,11 +684,11 @@ Status Redis::MSetnx(const std::vector& kvs, int32_t* ret) { for (const auto & kv : kvs) { BaseKey base_key(kv.key); s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + kv.key + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + kv.key + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -724,11 +724,11 @@ Status Redis::Setxx(const Slice& key, const Slice& value, int32_t* ret, int64_t BaseKey base_key(key); ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -761,11 +761,11 @@ Status Redis::SetBit(const Slice& key, int64_t offset, int32_t on, int32_t* ret) BaseKey base_key(key); ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok() || s.IsNotFound()) { @@ -830,11 +830,11 @@ Status Redis::Setnx(const Slice& key, const Slice& value, int32_t* ret, int64_t BaseKey base_key(key); ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -870,11 +870,11 @@ Status Redis::Setvx(const Slice& key, const Slice& value, const Slice& new_value BaseKey base_key(key); ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -911,11 +911,11 @@ Status Redis::Delvx(const Slice& key, const Slice& value, int32_t* ret) { BaseKey base_key(key); ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -947,11 +947,11 @@ Status Redis::Setrange(const Slice& key, int64_t start_offset, const Slice& valu BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &old_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, old_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, old_value)) { if (ExpectedStale(old_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(old_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(old_value))]); } } if (s.ok()) { @@ -1053,11 +1053,11 @@ Status Redis::BitPos(const Slice& key, int32_t bit, int64_t* ret) { BaseKey base_key(key); s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -1097,11 +1097,11 @@ Status Redis::BitPos(const Slice& key, int32_t bit, int64_t start_offset, int64_ BaseKey base_key(key); s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -1154,11 +1154,11 @@ Status Redis::BitPos(const Slice& key, int32_t bit, int64_t start_offset, int64_ BaseKey base_key(key); s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -1230,11 +1230,11 @@ Status Redis::StringsExpire(const Slice& key, int64_t ttl) { BaseKey base_key(key); ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -1258,11 +1258,11 @@ Status Redis::StringsDel(const Slice& key) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -1281,11 +1281,11 @@ Status Redis::StringsExpireat(const Slice& key, int64_t timestamp) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -1310,11 +1310,11 @@ Status Redis::StringsPersist(const Slice& key) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -1340,11 +1340,11 @@ Status Redis::StringsTTL(const Slice& key, int64_t* timestamp) { BaseKey base_key(key); Status s = db_->Get(default_read_options_, base_key.Encode(), &value); - if (s.ok() && !ExpectedMetaValue(RedisType::kString, value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kStrings, value)) { if (ExpectedStale(value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kString)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kStrings)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(value))]); } } if (s.ok()) { @@ -1379,7 +1379,7 @@ void Redis::ScanStrings() { LOG(INFO) << "***************" << "rocksdb instance: " << index_ << " " << "String Data***************"; auto iter = db_->NewIterator(iterator_options); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { - if (!ExpectedMetaValue(RedisType::kString, iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kStrings, iter->value().ToString())) { continue; } ParsedBaseKey parsed_strings_key(iter->key()); @@ -1409,19 +1409,19 @@ rocksdb::Status Redis::Exists(const Slice& key) { storage::StreamUtils::StreamParseIntervalId("+", arg.end_sid, &arg.end_ex, UINT64_MAX); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); switch (type) { - case RedisType::kSet: + case DataType::kSets: return SCard(key, &ret); - case RedisType::kZset: + case DataType::kZSets: return ZCard(key, &ret); - case RedisType::kHash: + case DataType::kHashes: return HLen(key, &ret); - case RedisType::kList: + case DataType::kLists: return LLen(key, &llen); - case RedisType::kString: + case DataType::kStrings: return Get(key, &value); - case RedisType::kStream: + case DataType::kStreams: return XRange(key, arg, id_messages); default: return rocksdb::Status::NotFound(); @@ -1435,19 +1435,19 @@ rocksdb::Status Redis::Del(const Slice& key) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); switch (type) { - case RedisType::kSet: + case DataType::kSets: return SetsDel(key); - case RedisType::kZset: + case DataType::kZSets: return ZsetsDel(key); - case RedisType::kHash: + case DataType::kHashes: return HashesDel(key); - case RedisType::kList: + case DataType::kLists: return ListsDel(key); - case RedisType::kString: + case DataType::kStrings: return StringsDel(key); - case RedisType::kStream: + case DataType::kStreams: return StreamsDel(key); default: return rocksdb::Status::NotFound(); @@ -1461,17 +1461,17 @@ rocksdb::Status Redis::Expire(const Slice& key, int64_t ttl) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); switch (type) { - case RedisType::kSet: + case DataType::kSets: return SetsExpire(key, ttl); - case RedisType::kZset: + case DataType::kZSets: return ZsetsExpire(key, ttl); - case RedisType::kHash: + case DataType::kHashes: return HashesExpire(key, ttl); - case RedisType::kList: + case DataType::kLists: return ListsExpire(key, ttl); - case RedisType::kString: + case DataType::kStrings: return StringsExpire(key, ttl); default: return rocksdb::Status::NotFound(); @@ -1485,17 +1485,17 @@ rocksdb::Status Redis::Expireat(const Slice& key, int64_t ttl) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); switch (type) { - case RedisType::kSet: + case DataType::kSets: return SetsExpireat(key, ttl); - case RedisType::kZset: + case DataType::kZSets: return ZsetsExpireat(key, ttl); - case RedisType::kHash: + case DataType::kHashes: return HashesExpireat(key, ttl); - case RedisType::kList: + case DataType::kLists: return ListsExpireat(key, ttl); - case RedisType::kString: + case DataType::kStrings: return StringsExpireat(key, ttl); default: return rocksdb::Status::NotFound(); @@ -1509,17 +1509,17 @@ rocksdb::Status Redis::Persist(const Slice& key) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); switch (type) { - case RedisType::kSet: + case DataType::kSets: return SetsPersist(key); - case RedisType::kZset: + case DataType::kZSets: return ZsetsPersist(key); - case RedisType::kHash: + case DataType::kHashes: return HashesPersist(key); - case RedisType::kList: + case DataType::kLists: return ListsPersist(key); - case RedisType::kString: + case DataType::kStrings: return StringsPersist(key); default: return rocksdb::Status::NotFound(); @@ -1533,17 +1533,17 @@ rocksdb::Status Redis::TTL(const Slice& key, int64_t* timestamp) { BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); switch (type) { - case RedisType::kSet: + case DataType::kSets: return SetsTTL(key, timestamp); - case RedisType::kZset: + case DataType::kZSets: return ZsetsTTL(key, timestamp); - case RedisType::kHash: + case DataType::kHashes: return HashesTTL(key, timestamp); - case RedisType::kList: + case DataType::kLists: return ListsTTL(key, timestamp); - case RedisType::kString: + case DataType::kStrings: return StringsTTL(key, timestamp); default: return rocksdb::Status::NotFound(); @@ -1552,12 +1552,12 @@ rocksdb::Status Redis::TTL(const Slice& key, int64_t* timestamp) { return rocksdb::Status::NotFound(); } -rocksdb::Status Redis::GetType(const storage::Slice& key, enum RedisType& type) { +rocksdb::Status Redis::GetType(const storage::Slice& key, enum DataType& type) { std::string meta_value; BaseMetaKey base_meta_key(key); rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); if (s.ok()) { - type = static_cast(static_cast(meta_value[0])); + type = static_cast(static_cast(meta_value[0])); } return Status::OK(); } @@ -1591,16 +1591,16 @@ rocksdb::Status Redis::PKPatternMatchDel(const std::string& pattern, int32_t* re iter->SeekToFirst(); key = iter->key().ToString(); while (iter->Valid()) { - auto meta_type = static_cast(static_cast(iter->value()[0])); + auto meta_type = static_cast(static_cast(iter->value()[0])); ParsedBaseMetaKey parsed_meta_key(iter->key().ToString()); - if (meta_type == RedisType::kString) { + if (meta_type == DataType::kStrings) { meta_value = iter->value().ToString(); ParsedStringsValue parsed_strings_value(&meta_value); if (!parsed_strings_value.IsStale() && (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0) != 0)) { batch.Delete(key); } - } else if (meta_type == RedisType::kList) { + } else if (meta_type == DataType::kLists) { meta_value = iter->value().ToString(); ParsedListsMetaValue parsed_lists_meta_value(&meta_value); if (!parsed_lists_meta_value.IsStale() && (parsed_lists_meta_value.Count() != 0U) && @@ -1609,7 +1609,7 @@ rocksdb::Status Redis::PKPatternMatchDel(const std::string& pattern, int32_t* re parsed_lists_meta_value.InitialMetaValue(); batch.Put(handles_[kMetaCF], iter->key(), meta_value); } - } else if (meta_type == RedisType::kStream) { + } else if (meta_type == DataType::kStreams) { StreamMetaValue stream_meta_value; stream_meta_value.ParseFrom(meta_value); if ((stream_meta_value.length() != 0) && diff --git a/src/storage/src/redis_zsets.cc b/src/storage/src/redis_zsets.cc index ebda6b94c6..503d3710dc 100644 --- a/src/storage/src/redis_zsets.cc +++ b/src/storage/src/redis_zsets.cc @@ -41,7 +41,7 @@ Status Redis::ScanZsetsKeyNum(KeyInfo* key_info) { rocksdb::Iterator* iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { - if (!ExpectedMetaValue(RedisType::kZset, iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kZSets, iter->value().ToString())) { continue; } ParsedZSetsMetaValue parsed_zsets_meta_value(iter->value()); @@ -73,11 +73,11 @@ Status Redis::ZPopMax(const Slice& key, const int64_t count, std::vectorGet(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -128,11 +128,11 @@ Status Redis::ZPopMin(const Slice& key, const int64_t count, std::vectorGet(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -194,11 +194,11 @@ Status Redis::ZAdd(const Slice& key, const std::vector& score_membe BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -261,7 +261,7 @@ Status Redis::ZAdd(const Slice& key, const std::vector& score_membe } else if (s.IsNotFound()) { char buf[4]; EncodeFixed32(buf, filtered_score_members.size()); - ZSetsMetaValue zsets_meta_value(RedisType::kZset, Slice(buf, 4)); + ZSetsMetaValue zsets_meta_value(DataType::kZSets, Slice(buf, 4)); version = zsets_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_meta_key.Encode(), zsets_meta_value.Encode()); for (const auto& sm : filtered_score_members) { @@ -291,11 +291,11 @@ Status Redis::ZCard(const Slice& key, int32_t* card) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -325,11 +325,11 @@ Status Redis::ZCount(const Slice& key, double min, double max, bool left_close, BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -390,11 +390,11 @@ Status Redis::ZIncrby(const Slice& key, const Slice& member, double increment, d BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -432,7 +432,7 @@ Status Redis::ZIncrby(const Slice& key, const Slice& member, double increment, d } else if (s.IsNotFound()) { char buf[4]; EncodeFixed32(buf, 1); - ZSetsMetaValue zsets_meta_value(RedisType::kZset, Slice(buf, 4)); + ZSetsMetaValue zsets_meta_value(DataType::kZSets, Slice(buf, 4)); version = zsets_meta_value.UpdateVersion(); batch.Put(handles_[kMetaCF], base_meta_key.Encode(), zsets_meta_value.Encode()); score = increment; @@ -466,11 +466,11 @@ Status Redis::ZRange(const Slice& key, int32_t start, int32_t stop, std::vector< BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -521,11 +521,11 @@ Status Redis::ZRangeWithTTL(const Slice& key, int32_t start, int32_t stop, std:: BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -590,11 +590,11 @@ Status Redis::ZRangebyscore(const Slice& key, double min, double max, bool left_ BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -664,11 +664,11 @@ Status Redis::ZRank(const Slice& key, const Slice& member, int32_t* rank) { BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -723,11 +723,11 @@ Status Redis::ZRem(const Slice& key, const std::vector& members, in BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -783,11 +783,11 @@ Status Redis::ZRemrangebyrank(const Slice& key, int32_t start, int32_t stop, int BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -848,11 +848,11 @@ Status Redis::ZRemrangebyscore(const Slice& key, double min, double max, bool le BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -927,11 +927,11 @@ Status Redis::ZRevrange(const Slice& key, int32_t start, int32_t stop, std::vect BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -982,11 +982,11 @@ Status Redis::ZRevrangebyscore(const Slice& key, double min, double max, bool le BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1056,11 +1056,11 @@ Status Redis::ZRevrank(const Slice& key, const Slice& member, int32_t* rank) { BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1107,11 +1107,11 @@ Status Redis::ZScore(const Slice& key, const Slice& member, double* score) { BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value) && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value) && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1151,11 +1151,11 @@ Status Redis::ZGetAll(const Slice& key, double weight, std::mapGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value) && !ExpectedMetaValue(RedisType::kSet, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value) && !ExpectedMetaValue(DataType::kSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1200,11 +1200,11 @@ Status Redis::ZUnionstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1251,11 +1251,11 @@ Status Redis::ZUnionstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_destination.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1270,7 +1270,7 @@ Status Redis::ZUnionstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + keys[idx] + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1401,11 +1401,11 @@ Status Redis::ZInterstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_destination.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + destination.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1420,7 +1420,7 @@ Status Redis::ZInterstore(const Slice& destination, const std::vectorGet(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1530,11 +1530,11 @@ Status Redis::ZRemrangebylex(const Slice& key, const Slice& min, const Slice& ma BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1599,11 +1599,11 @@ Status Redis::ZsetsExpire(const Slice& key, int64_t ttl) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1630,11 +1630,11 @@ Status Redis::ZsetsDel(const Slice& key) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1659,11 +1659,11 @@ Status Redis::ZsetsExpireat(const Slice& key, int64_t timestamp) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1704,11 +1704,11 @@ Status Redis::ZScan(const Slice& key, int64_t cursor, const std::string& pattern BaseMetaKey base_meta_key(key); Status s = db_->Get(read_options, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1773,11 +1773,11 @@ Status Redis::ZsetsPersist(const Slice& key) { ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1804,11 +1804,11 @@ Status Redis::ZsetsTTL(const Slice& key, int64_t* timestamp) { BaseMetaKey base_meta_key(key); Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value); - if (s.ok() && !ExpectedMetaValue(RedisType::kZset, meta_value)) { + if (s.ok() && !ExpectedMetaValue(DataType::kZSets, meta_value)) { if (ExpectedStale(meta_value)) { s = Status::NotFound(); } else { - return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + RedisTypeStrings[static_cast(RedisType::kZset)] + "get type: " + RedisTypeStrings[static_cast(GetMetaValueType(meta_value))]); + return Status::InvalidArgument("WRONGTYPE, key: " + key.ToString() + ", expect type: " + DataTypeStrings[static_cast(DataType::kZSets)] + "get type: " + DataTypeStrings[static_cast(GetMetaValueType(meta_value))]); } } if (s.ok()) { @@ -1846,7 +1846,7 @@ void Redis::ScanZsets() { LOG(INFO) << "***************" << "rocksdb instance: " << index_ << " ZSets Meta Data***************"; auto meta_iter = db_->NewIterator(iterator_options, handles_[kMetaCF]); for (meta_iter->SeekToFirst(); meta_iter->Valid(); meta_iter->Next()) { - if (!ExpectedMetaValue(RedisType::kZset, meta_iter->value().ToString())) { + if (!ExpectedMetaValue(DataType::kZSets, meta_iter->value().ToString())) { continue; } ParsedBaseMetaKey parsed_meta_key(meta_iter->key()); diff --git a/src/storage/src/storage.cc b/src/storage/src/storage.cc index 8026a16303..8da780c39d 100644 --- a/src/storage/src/storage.cc +++ b/src/storage/src/storage.cc @@ -106,7 +106,7 @@ Status Storage::Open(const StorageOptions& storage_options, const std::string& d } Status Storage::LoadCursorStartKey(const DataType& dtype, int64_t cursor, char* type, std::string* start_key) { - std::string index_key = DataTypeTag[dtype] + std::to_string(cursor); + std::string index_key = DataTypeTag[static_cast(dtype)] + std::to_string(cursor); std::string index_value; Status s = cursors_store_->Lookup(index_key, &index_value); if (!s.ok() || index_value.size() < 3) { @@ -118,7 +118,7 @@ Status Storage::LoadCursorStartKey(const DataType& dtype, int64_t cursor, char* } Status Storage::StoreCursorStartKey(const DataType& dtype, int64_t cursor, char type, const std::string& next_key) { - std::string index_key = DataTypeTag[dtype] + std::to_string(cursor); + std::string index_key = DataTypeTag[static_cast(dtype)] + std::to_string(cursor); // format: data_type tag(1B) | start_key std::string index_value(1, type); index_value.append(next_key); @@ -1229,7 +1229,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& Status s = LoadCursorStartKey(dtype, cursor, &key_type, &start_key); if (!s.ok()) { // If want to scan all the databases, we start with the strings database - key_type = dtype == DataType::kAll ? DataTypeTag[DataType::kStrings] : DataTypeTag[dtype]; + key_type = dtype == DataType::kAll ? DataTypeTag[static_cast(DataType::kStrings)] : DataTypeTag[static_cast(dtype)]; start_key = prefix; cursor = 0; } @@ -1245,7 +1245,7 @@ int64_t Storage::Scan(const DataType& dtype, int64_t cursor, const std::string& } std::copy(pos, iter_end, std::back_inserter(types)); } else { - types.push_back(DataTypeTag[dtype]); + types.push_back(DataTypeTag[static_cast(dtype)]); } for (const auto& type : types) { @@ -1470,7 +1470,7 @@ int64_t Storage::TTL(const Slice& key) { return timestamp; } -Status Storage::GetType(const std::string& key, enum RedisType& type) { +Status Storage::GetType(const std::string& key, enum DataType& type) { auto& inst = GetDBInstance(key); inst->GetType(key, type); return Status::OK(); @@ -1503,25 +1503,25 @@ Status Storage::Keys(const DataType& data_type, const std::string& pattern, std: void Storage::ScanDatabase(const DataType& type) { for (const auto& inst : insts_) { switch (type) { - case kStrings: + case DataType::kStrings: inst->ScanStrings(); break; - case kHashes: + case DataType::kHashes: inst->ScanHashes(); break; - case kSets: + case DataType::kSets: inst->ScanSets(); break; - case kZSets: + case DataType::kZSets: inst->ScanZsets(); break; - case kLists: + case DataType::kLists: inst->ScanLists(); break; - case kStreams: + case DataType::kStreams: // do noting break; - case kAll: + case DataType::kAll: inst->ScanStrings(); inst->ScanHashes(); inst->ScanSets(); @@ -1658,7 +1658,7 @@ Status Storage::StartBGThread() { Status Storage::AddBGTask(const BGTask& bg_task) { bg_tasks_mutex_.lock(); - if (bg_task.type == kAll) { + if (bg_task.type == DataType::kAll) { // if current task it is global compact, // clear the bg_tasks_queue_; std::queue empty_queue; @@ -1711,7 +1711,7 @@ Status Storage::Compact(const DataType& type, bool sync) { // run compactrange for all rocksdb instance Status Storage::DoCompactRange(const DataType& type, const std::string& start, const std::string& end) { - if (type != kAll) { + if (type != DataType::kAll) { return Status::InvalidArgument(""); } diff --git a/src/storage/src/strings_value_format.h b/src/storage/src/strings_value_format.h index b31bbaf46d..56c8263682 100644 --- a/src/storage/src/strings_value_format.h +++ b/src/storage/src/strings_value_format.h @@ -18,7 +18,7 @@ namespace storage { */ class StringsValue : public InternalValue { public: - explicit StringsValue(const rocksdb::Slice& user_value) : InternalValue(RedisType::kString, user_value) {} + explicit StringsValue(const rocksdb::Slice& user_value) : InternalValue(DataType::kStrings, user_value) {} virtual rocksdb::Slice Encode() override { size_t usize = user_value_.size(); size_t needed = usize + kSuffixReserveLength + 2 * kTimestampLength + kTypeLength; @@ -45,7 +45,7 @@ class ParsedStringsValue : public ParsedInternalValue { // TODO Why need this logic; Mixficsol if (internal_value_str->size() >= kStringsValueMinLength) { size_t offset = 0; - type_ = static_cast(static_cast((*internal_value_str)[0])); + type_ = static_cast(static_cast((*internal_value_str)[0])); offset += kTypeLength; user_value_ = rocksdb::Slice(internal_value_str->data() + offset, internal_value_str->size() - kStringsValueSuffixLength - offset); @@ -62,7 +62,7 @@ class ParsedStringsValue : public ParsedInternalValue { explicit ParsedStringsValue(const rocksdb::Slice& internal_value_slice) : ParsedInternalValue(internal_value_slice) { if (internal_value_slice.size() >= kStringsValueMinLength) { size_t offset = 0; - type_ = static_cast(static_cast(internal_value_slice[0])); + type_ = static_cast(static_cast(internal_value_slice[0])); offset += kTypeLength; user_value_ = rocksdb::Slice(internal_value_slice.data() + offset, internal_value_slice.size() - kStringsValueSuffixLength - offset); offset += user_value_.size(); diff --git a/src/storage/src/type_iterator.h b/src/storage/src/type_iterator.h index 6038d9b53e..0e9c6aba7d 100644 --- a/src/storage/src/type_iterator.h +++ b/src/storage/src/type_iterator.h @@ -118,8 +118,8 @@ class StringsIterator : public TypeIterator { ~StringsIterator() {} bool ShouldSkip() override { - auto type = static_cast(static_cast(raw_iter_->value()[0])); - if (type != RedisType::kString) { + auto type = static_cast(static_cast(raw_iter_->value()[0])); + if (type != DataType::kStrings) { return true; } ParsedStringsValue parsed_value(raw_iter_->value()); @@ -150,8 +150,8 @@ class HashesIterator : public TypeIterator { ~HashesIterator() {} bool ShouldSkip() override { - auto type = static_cast(static_cast(raw_iter_->value()[0])); - if (type != RedisType::kHash) { + auto type = static_cast(static_cast(raw_iter_->value()[0])); + if (type != DataType::kHashes) { return true; } ParsedHashesMetaValue parsed_meta_value(raw_iter_->value()); @@ -181,8 +181,8 @@ class ListsIterator : public TypeIterator { ~ListsIterator() {} bool ShouldSkip() override { - auto type = static_cast(static_cast(raw_iter_->value()[0])); - if (type != RedisType::kList) { + auto type = static_cast(static_cast(raw_iter_->value()[0])); + if (type != DataType::kLists) { return true; } ParsedListsMetaValue parsed_meta_value(raw_iter_->value()); @@ -212,8 +212,8 @@ class SetsIterator : public TypeIterator { ~SetsIterator() {} bool ShouldSkip() override { - auto type = static_cast(static_cast(raw_iter_->value()[0])); - if (type != RedisType::kSet) { + auto type = static_cast(static_cast(raw_iter_->value()[0])); + if (type != DataType::kSets) { return true; } ParsedSetsMetaValue parsed_meta_value(raw_iter_->value()); @@ -243,8 +243,8 @@ class ZsetsIterator : public TypeIterator { ~ZsetsIterator() {} bool ShouldSkip() override { - auto type = static_cast(static_cast(raw_iter_->value()[0])); - if (type != RedisType::kZset) { + auto type = static_cast(static_cast(raw_iter_->value()[0])); + if (type != DataType::kZSets) { return true; } ParsedZSetsMetaValue parsed_meta_value(raw_iter_->value()); @@ -274,8 +274,8 @@ class StreamsIterator : public TypeIterator { ~StreamsIterator() {} bool ShouldSkip() override { - auto type = static_cast(static_cast(raw_iter_->value()[0])); - if (type != RedisType::kStream) { + auto type = static_cast(static_cast(raw_iter_->value()[0])); + if (type != DataType::kStreams) { return true; } ParsedStreamMetaValue parsed_meta_value(raw_iter_->value()); @@ -310,14 +310,14 @@ class AllIterator : public TypeIterator { bool ShouldSkip() override { std::string user_value; - auto type = static_cast(static_cast(raw_iter_->value()[0])); - if (type == RedisType::kZset || type == RedisType::kSet || type == RedisType::kHash || type == RedisType::kStream) { + auto type = static_cast(static_cast(raw_iter_->value()[0])); + if (type == DataType::kZSets || type == DataType::kSets || type == DataType::kHashes || type == DataType::kStreams) { ParsedBaseMetaValue parsed_meta_value(raw_iter_->value()); user_value = parsed_meta_value.UserValue().ToString(); if (parsed_meta_value.IsStale() || parsed_meta_value.Count() == 0) { return true; } - } else if (type == RedisType::kList) { + } else if (type == DataType::kLists) { ParsedListsMetaValue parsed_meta_value(raw_iter_->value()); user_value = parsed_meta_value.UserValue().ToString(); if (parsed_meta_value.IsStale() || parsed_meta_value.Count() == 0) { diff --git a/src/storage/src/zsets_filter.h b/src/storage/src/zsets_filter.h index 5a3753f493..35dde6d0b9 100644 --- a/src/storage/src/zsets_filter.h +++ b/src/storage/src/zsets_filter.h @@ -20,7 +20,7 @@ namespace storage { class ZSetsScoreFilter : public rocksdb::CompactionFilter { public: - ZSetsScoreFilter(rocksdb::DB* db, std::vector* handles_ptr, enum RedisType type) + ZSetsScoreFilter(rocksdb::DB* db, std::vector* handles_ptr, enum DataType type) : db_(db), cf_handles_ptr_(handles_ptr), type_(type) {} bool Filter(int level, const rocksdb::Slice& key, const rocksdb::Slice& value, std::string* new_value, @@ -53,7 +53,7 @@ class ZSetsScoreFilter : public rocksdb::CompactionFilter { } Status s = db_->Get(default_read_options_, (*cf_handles_ptr_)[0], cur_key_, &meta_value); if (s.ok()) { - auto type = static_cast(static_cast(meta_value[0])); + auto type = static_cast(static_cast(meta_value[0])); if (type != type_) { return true; } @@ -117,12 +117,12 @@ class ZSetsScoreFilter : public rocksdb::CompactionFilter { mutable bool meta_not_found_ = false; mutable uint64_t cur_meta_version_ = 0; mutable uint64_t cur_meta_etime_ = 0; - enum RedisType type_ = RedisType::kNone; + enum DataType type_ = DataType::kNones; }; class ZSetsScoreFilterFactory : public rocksdb::CompactionFilterFactory { public: - ZSetsScoreFilterFactory(rocksdb::DB** db_ptr, std::vector* handles_ptr, enum RedisType type) + ZSetsScoreFilterFactory(rocksdb::DB** db_ptr, std::vector* handles_ptr, enum DataType type) : db_ptr_(db_ptr), cf_handles_ptr_(handles_ptr), type_(type) {} std::unique_ptr CreateCompactionFilter( @@ -135,7 +135,7 @@ class ZSetsScoreFilterFactory : public rocksdb::CompactionFilterFactory { private: rocksdb::DB** db_ptr_ = nullptr; std::vector* cf_handles_ptr_ = nullptr; - enum RedisType type_ = RedisType::kNone; + enum DataType type_ = DataType::kNones; }; } // namespace storage diff --git a/src/storage/tests/keys_test.cc b/src/storage/tests/keys_test.cc index 7f13d323f8..1b292f642e 100644 --- a/src/storage/tests/keys_test.cc +++ b/src/storage/tests/keys_test.cc @@ -5050,7 +5050,7 @@ TEST_F(KeysTest, ExpireTest) { ret = db.Expire("GP3_EXPIRE_LISTS_KEY", 1); LOG(WARNING) << "ret: " << ret; for (const auto& ts : type_status) { - LOG(WARNING) << "type: " << ts.first << " status: " << ts.second.ToString(); + LOG(WARNING) << "type: " << storage::DataTypeStrings[static_cast(ts.first)] << " status: " << ts.second.ToString(); } // ASSERT_EQ(ret, 0); diff --git a/src/storage/tests/lists_filter_test.cc b/src/storage/tests/lists_filter_test.cc index 923aad959f..4f85ba8756 100644 --- a/src/storage/tests/lists_filter_test.cc +++ b/src/storage/tests/lists_filter_test.cc @@ -65,58 +65,6 @@ class ListsFilterTest : public ::testing::Test { std::vector handles; }; -// Meta Filter -TEST_F(ListsFilterTest, MetaFilterTest) { - char str[8]; - bool filter_result; - bool value_changed; - uint64_t version = 0; - std::string new_value; - - // Test Meta Filter - // auto lists_meta_filter = std::make_unique(); - //ASSERT_TRUE(lists_meta_filter != nullptr); - - // Timeout timestamp is not set, but it's an empty list. -// EncodeFixed64(str, 0); -// ListsMetaValue lists_meta_value1(Slice(str, sizeof(uint64_t))); -// lists_meta_value1.UpdateVersion(); -// std::this_thread::sleep_for(std::chrono::milliseconds(1000)); -// filter_result = -// lists_meta_filter->Filter(0, "FILTER_TEST_KEY", lists_meta_value1.Encode(), &new_value, &value_changed); -// ASSERT_EQ(filter_result, true); -// -// // Timeout timestamp is not set, it's not an empty list. -// EncodeFixed64(str, 1); -// ListsMetaValue lists_meta_value2(Slice(str, sizeof(uint64_t))); -// lists_meta_value2.UpdateVersion(); -// std::this_thread::sleep_for(std::chrono::milliseconds(1000)); -// filter_result = -// lists_meta_filter->Filter(0, "FILTER_TEST_KEY", lists_meta_value2.Encode(), &new_value, &value_changed); -// ASSERT_EQ(filter_result, false); -// -// // Timeout timestamp is set, but not expired. -// EncodeFixed64(str, 1); -// ListsMetaValue lists_meta_value3(Slice(str, sizeof(uint64_t))); -// lists_meta_value3.UpdateVersion(); -// lists_meta_value3.SetRelativeTimestamp(3); -// std::this_thread::sleep_for(std::chrono::milliseconds(1000)); -// filter_result = -// lists_meta_filter->Filter(0, "FILTER_TEST_KEY", lists_meta_value3.Encode(), &new_value, &value_changed); -// ASSERT_EQ(filter_result, false); -// -// // Timeout timestamp is set, already expired. -// EncodeFixed64(str, 1); -// ListsMetaValue lists_meta_value4(Slice(str, sizeof(uint64_t))); -// lists_meta_value4.UpdateVersion(); -// lists_meta_value4.SetRelativeTimestamp(1); -// std::this_thread::sleep_for(std::chrono::milliseconds(2000)); -// storage::ParsedListsMetaValue parsed_meta_value(lists_meta_value4.Encode()); -// filter_result = -// lists_meta_filter->Filter(0, "FILTER_TEST_KEY", lists_meta_value4.Encode(), &new_value, &value_changed); -// ASSERT_EQ(filter_result, true); -} - // Data Filter TEST_F(ListsFilterTest, DataFilterTest) { char str[8]; @@ -126,7 +74,7 @@ TEST_F(ListsFilterTest, DataFilterTest) { std::string new_value; // Timeout timestamp is not set, the version is valid. - auto lists_data_filter1 = std::make_unique(meta_db, &handles, RedisType::kList); + auto lists_data_filter1 = std::make_unique(meta_db, &handles, DataType::kLists); ASSERT_TRUE(lists_data_filter1 != nullptr); EncodeFixed64(str, 1); @@ -146,7 +94,7 @@ TEST_F(ListsFilterTest, DataFilterTest) { ASSERT_TRUE(s.ok()); // Timeout timestamp is set, but not expired. - auto lists_data_filter2 = std::make_unique(meta_db, &handles, RedisType::kList); + auto lists_data_filter2 = std::make_unique(meta_db, &handles, DataType::kLists); ASSERT_TRUE(lists_data_filter2 != nullptr); EncodeFixed64(str, 1); @@ -163,7 +111,7 @@ TEST_F(ListsFilterTest, DataFilterTest) { ASSERT_TRUE(s.ok()); // Timeout timestamp is set, already expired. - auto lists_data_filter3 = std::make_unique(meta_db, &handles, RedisType::kList); + auto lists_data_filter3 = std::make_unique(meta_db, &handles, DataType::kLists); ASSERT_TRUE(lists_data_filter3 != nullptr); EncodeFixed64(str, 1); @@ -181,7 +129,7 @@ TEST_F(ListsFilterTest, DataFilterTest) { ASSERT_TRUE(s.ok()); // Timeout timestamp is not set, the version is invalid - auto lists_data_filter4 = std::make_unique(meta_db, &handles, RedisType::kList); + auto lists_data_filter4 = std::make_unique(meta_db, &handles, DataType::kLists); ASSERT_TRUE(lists_data_filter4 != nullptr); EncodeFixed64(str, 1); @@ -200,7 +148,7 @@ TEST_F(ListsFilterTest, DataFilterTest) { ASSERT_TRUE(s.ok()); // Meta data has been clear - auto lists_data_filter5 = std::make_unique(meta_db, &handles, RedisType::kList); + auto lists_data_filter5 = std::make_unique(meta_db, &handles, DataType::kLists); ASSERT_TRUE(lists_data_filter5 != nullptr); EncodeFixed64(str, 1); diff --git a/src/storage/tests/zsets_test.cc b/src/storage/tests/zsets_test.cc index 2f4e987cdc..baaf284f5e 100644 --- a/src/storage/tests/zsets_test.cc +++ b/src/storage/tests/zsets_test.cc @@ -18,7 +18,7 @@ using storage::Status; using storage::Slice; using storage::ScoreMember; -using storage::kZSets; +using storage::DataType::kZSets; using storage::DataType; class ZSetsTest : public ::testing::Test { diff --git a/tests/unit/type/string.tcl b/tests/unit/type/string.tcl index 5fbf2b68b4..7f716831ef 100644 --- a/tests/unit/type/string.tcl +++ b/tests/unit/type/string.tcl @@ -452,7 +452,7 @@ start_server {tags {"string"}} { assert_error "WRONGTYPE*" {r setrange mykey 0 bar} } -# Keys for multiple data types of Pika can be duplicate +# Configuration parameters are not set # test "SETRANGE with out of range offset" { # r del mykey # assert_error "*maximum allowed size*" {r setrange mykey [expr 512*1024*1024-4] world} diff --git a/tools/pika-port/pika_port_3/const.cc b/tools/pika-port/pika_port_3/const.cc index 2f9a67ba54..a72891a8b6 100644 --- a/tools/pika-port/pika_port_3/const.cc +++ b/tools/pika-port/pika_port_3/const.cc @@ -58,24 +58,24 @@ std::string PikaRole(int role) { const char* GetDBTypeString(int type) { switch (type) { - case static_cast(storage::kStrings): { - return "storage::kStrings"; + case static_cast(storage::DataType::kStrings): { + return "storage::DataType::kStrings"; } - case static_cast(storage::kLists): { - return "storage::kLists"; + case static_cast(storage::DataType::kLists): { + return "storage::DataType::kLists"; } - case static_cast(storage::kHashes): { - return "storage::kHashes"; + case static_cast(storage::DataType::kHashes): { + return "storage::DataType::kHashes"; } - case static_cast(storage::kSets): { - return "storage::kSets"; + case static_cast(storage::DataType::kSets): { + return "storage::DataType::kSets"; } - case static_cast(storage::kZSets): { - return "storage::kZSets"; + case static_cast(storage::DataType::kZSets): { + return "storage::DataType::kZSets"; } default: { diff --git a/tools/pika-port/pika_port_3/migrator_thread.cc b/tools/pika-port/pika_port_3/migrator_thread.cc index f1bb206473..77e52f2572 100644 --- a/tools/pika-port/pika_port_3/migrator_thread.cc +++ b/tools/pika-port/pika_port_3/migrator_thread.cc @@ -369,27 +369,27 @@ void MigratorThread::MigrateZsetsDB() { void MigratorThread::MigrateDB() { switch (static_cast(type_)) { - case static_cast(storage::kStrings): { + case static_cast(storage::DataType::kStrings): { MigrateStringsDB(); break; } - case static_cast(storage::kLists): { + case static_cast(storage::DataType::kLists): { MigrateListsDB(); break; } - case static_cast(storage::kHashes): { + case static_cast(storage::DataType::kHashes): { MigrateHashesDB(); break; } - case static_cast(storage::kSets): { + case static_cast(storage::DataType::kSets): { MigrateSetsDB(); break; } - case static_cast(storage::kZSets): { + case static_cast(storage::DataType::kZSets): { MigrateZsetsDB(); break; } diff --git a/tools/pika-port/pika_port_3/trysync_thread.cc b/tools/pika-port/pika_port_3/trysync_thread.cc index 89ebc7899b..03a95eb1a3 100644 --- a/tools/pika-port/pika_port_3/trysync_thread.cc +++ b/tools/pika-port/pika_port_3/trysync_thread.cc @@ -284,44 +284,44 @@ int TrysyncThread::Retransmit() { storage::Storage bw; - storage::RedisStrings stringsDB(&bw, storage::kStrings); + storage::RedisStrings stringsDB(&bw, storage::DataType::kStrings); std::string path = db_path + "strings"; s = stringsDB.Open(bwOptions, path); LOG(INFO) << "Open strings DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread(&stringsDB, &senders_, storage::kStrings, thread_num)); + migrators_.emplace_back(new MigratorThread(&stringsDB, &senders_, storage::DataType::kStrings, thread_num)); } - storage::RedisLists listsDB(&bw, storage::kLists); + storage::RedisLists listsDB(&bw, storage::DataType::kLists); path = db_path + "lists"; s = listsDB.Open(bwOptions, path); LOG(INFO) << "Open lists DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread(&listsDB, &senders_, storage::kLists, thread_num)); + migrators_.emplace_back(new MigratorThread(&listsDB, &senders_, storage::DataType::kLists, thread_num)); } - storage::RedisHashes hashesDB(&bw, storage::kHashes); + storage::RedisHashes hashesDB(&bw, storage::DataType::kHashes); path = db_path + "hashes"; s = hashesDB.Open(bwOptions, path); LOG(INFO) << "Open hashes DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread(&hashesDB, &senders_, storage::kHashes, thread_num)); + migrators_.emplace_back(new MigratorThread(&hashesDB, &senders_, storage::DataType::kHashes, thread_num)); } - storage::RedisSets setsDB(&bw, storage::kSets); + storage::RedisSets setsDB(&bw, storage::DataType::kSets); path = db_path + "sets"; s = setsDB.Open(bwOptions, path); LOG(INFO) << "Open sets DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread(&setsDB, &senders_, storage::kSets, thread_num)); + migrators_.emplace_back(new MigratorThread(&setsDB, &senders_, storage::DataType::kSets, thread_num)); } - storage::RedisZSets zsetsDB(&bw, storage::kZSets); + storage::RedisZSets zsetsDB(&bw, storage::DataType::kZSets); path = db_path + "zsets"; s = zsetsDB.Open(bwOptions, path); LOG(INFO) << "Open zsets DB " << path << " result " << s.ToString(); if (s.ok()) { - migrators_.emplace_back(new MigratorThread(&zsetsDB, &senders_, storage::kZSets, thread_num)); + migrators_.emplace_back(new MigratorThread(&zsetsDB, &senders_, storage::DataType::kZSets, thread_num)); } retransmit_mutex_.lock();