Skip to content

Commit

Permalink
RedisType to DataType
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixficsol committed May 16, 2024
1 parent 8e0376b commit 269e045
Show file tree
Hide file tree
Showing 34 changed files with 531 additions and 638 deletions.
6 changes: 3 additions & 3 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion include/pika_kv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ = "*";
Expand Down
12 changes: 6 additions & 6 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
46 changes: 23 additions & 23 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
41 changes: 10 additions & 31 deletions src/pika_migrate_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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<int>(type) << " is illegal";
return -1;
key_type = storage::DataTypeToTag(type);
if (type == storage::DataType::kNones) {
LOG(WARNING) << "PikaMigrateThread::ReqMigrateOne key: " << key << " type: " << static_cast<int>(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;
Expand Down
2 changes: 1 addition & 1 deletion src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 13 additions & 49 deletions src/pika_slot_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -760,37 +759,20 @@ void RemSlotKey(const std::string& key, const std::shared_ptr<DB>& db) {
}

int GetKeyType(const std::string& key, std::string& key_type, const std::shared_ptr<DB>& 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;
}

Expand Down Expand Up @@ -944,7 +926,7 @@ void SlotsMgrtTagSlotCmd::Do() {

// check key type
int SlotsMgrtTagOneCmd::KeyTypeCheck(const std::shared_ptr<DB>& db) {
enum storage::RedisType type;
enum storage::DataType type;
std::string key_type;
rocksdb::Status s = db->storage()->GetType(key_, type);
if (!s.ok()) {
Expand All @@ -957,29 +939,11 @@ int SlotsMgrtTagOneCmd::KeyTypeCheck(const std::shared_ptr<DB>& 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;
}
Expand Down
6 changes: 1 addition & 5 deletions src/storage/include/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<std::string>& types);
Expand Down

0 comments on commit 269e045

Please sign in to comment.