Skip to content

Commit

Permalink
Merge branch 'unstable' of github.com:OpenAtomFoundation/pikiwidb int…
Browse files Browse the repository at this point in the history
…o floyd-improve
  • Loading branch information
Mixficsol committed Apr 12, 2024
2 parents 3d7cc93 + 57248c3 commit 5c2e2df
Show file tree
Hide file tree
Showing 17 changed files with 807 additions and 453 deletions.
12 changes: 7 additions & 5 deletions pikiwidbtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# clear the log file
function cleanup() {
rm -rf ./log[0-9]*
rm -rf ./db[0-9]*
rm -rf ./logs*
rm -rf ./db*
rm -rf dbsync/
rm src/redis-server
}
Expand Down Expand Up @@ -56,6 +56,8 @@ if [ $? -ne 0 ]; then
exit 1
fi

#if [ "$2" == "clean" ];
# cleanup
#fi
# You can use './pikiwidb.sh all clean 'to ensure that the
# data can be deleted immediately after the test
if [ "$2" == "clean" ]; then
cleanup
fi
3 changes: 3 additions & 0 deletions src/base_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace pikiwidb {
// key cmd
const std::string kCmdNameDel = "del";
const std::string kCmdNameExists = "exists";
const std::string kCmdNameType = "type";
const std::string kCmdNameExpire = "expire";
const std::string kCmdNameTtl = "ttl";
const std::string kCmdNamePExpire = "pexpire";
const std::string kCmdNameExpireat = "expireat";
const std::string kCmdNamePExpireat = "pexpireat";
Expand Down
12 changes: 12 additions & 0 deletions src/cmd_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ void HScanCmd::DoCmd(PClient* client) {
auto status = PSTORE.GetBackend(client->GetCurrentDB())
->GetStorage()
->HScan(client->Key(), cursor, pattern, count, &fvs, &next_cursor);
if (status.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (!status.ok() && !status.IsNotFound()) {
client->SetRes(CmdRes::kErrOther, status.ToString());
return;
Expand Down Expand Up @@ -465,6 +469,10 @@ void HRandFieldCmd::DoCmd(PClient* client) {
// execute command
std::vector<std::string> res;
auto s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HRandField(client->Key(), count, with_values, &res);
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (s.IsNotFound()) {
client->AppendString("");
return;
Expand Down Expand Up @@ -498,6 +506,10 @@ void HExistsCmd::DoCmd(PClient* client) {
// execute command
std::vector<std::string> res;
auto s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->HExists(client->Key(), field);
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (!s.ok() && !s.IsNotFound()) {
return client->SetRes(CmdRes::kErrOther, s.ToString());
}
Expand Down
55 changes: 55 additions & 0 deletions src/cmd_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,61 @@ void ExistsCmd::DoCmd(PClient* client) {
}
}

TypeCmd::TypeCmd(const std::string& name, int16_t arity)
: BaseCmd(name, arity, kCmdFlagsReadonly, kAclCategoryRead | kAclCategoryKeyspace) {}

bool TypeCmd::DoInitial(PClient* client) {
client->SetKey(client->argv_[1]);
return true;
}

void TypeCmd::DoCmd(PClient* client) {
std::string types;
rocksdb::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->GetType(client->Key(), types);
if (s.ok()) {
client->AppendContent("+" + types);
} else {
client->SetRes(CmdRes::kErrOther, s.ToString());
}
}

ExpireCmd::ExpireCmd(const std::string& name, int16_t arity)
: BaseCmd(name, arity, kCmdFlagsWrite, kAclCategoryWrite | kAclCategoryKeyspace) {}

bool ExpireCmd::DoInitial(PClient* client) {
client->SetKey(client->argv_[1]);
return true;
}

void ExpireCmd::DoCmd(PClient* client) {
uint64_t sec = 0;
if (pstd::String2int(client->argv_[2], &sec) == 0) {
client->SetRes(CmdRes ::kInvalidInt);
return;
}
auto res = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->Expire(client->Key(), sec);
if (res != -1) {
client->AppendInteger(res);
} else {
client->SetRes(CmdRes::kErrOther, "expire internal error");
}
}

TtlCmd::TtlCmd(const std::string& name, int16_t arity)
: BaseCmd(name, arity, kCmdFlagsReadonly, kAclCategoryRead | kAclCategoryKeyspace) {}

bool TtlCmd::DoInitial(PClient* client) {
client->SetKey(client->argv_[1]);
return true;
}

void TtlCmd::DoCmd(PClient* client) {
int64_t type_timestamp;
std::map<storage::DataType, rocksdb::Status> type_status;
type_timestamp = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->TTL(client->Key());
client->AppendInteger(type_timestamp);
}

PExpireCmd::PExpireCmd(const std::string& name, int16_t arity)
: BaseCmd(name, arity, kCmdFlagsWrite, kAclCategoryWrite | kAclCategoryKeyspace) {}

Expand Down
33 changes: 33 additions & 0 deletions src/cmd_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ class ExistsCmd : public BaseCmd {
void DoCmd(PClient* client) override;
};

class TypeCmd : public BaseCmd {
public:
TypeCmd(const std::string& name, int16_t arity);

protected:
bool DoInitial(PClient* client) override;

private:
void DoCmd(PClient* client) override;
};

class ExpireCmd : public BaseCmd {
public:
ExpireCmd(const std::string& name, int16_t arity);

protected:
bool DoInitial(PClient* client) override;

private:
void DoCmd(PClient* client) override;
};

class TtlCmd : public BaseCmd {
public:
TtlCmd(const std::string& name, int16_t arity);

protected:
bool DoInitial(PClient* client) override;

private:
void DoCmd(PClient* client) override;
};

class PExpireCmd : public BaseCmd {
public:
PExpireCmd(const std::string& name, int16_t arity);
Expand Down
45 changes: 31 additions & 14 deletions src/cmd_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ bool SIsMemberCmd::DoInitial(PClient* client) {
}
void SIsMemberCmd::DoCmd(PClient* client) {
int32_t reply_Num = 0; // only change to 1 if ismember . key not exist it is 0
PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SIsmember(client->Key(), client->argv_[2], &reply_Num);

storage::Status s =
PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SIsmember(client->Key(), client->argv_[2], &reply_Num);
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
client->AppendInteger(reply_Num);
}

Expand Down Expand Up @@ -66,12 +70,14 @@ void SUnionStoreCmd::DoCmd(PClient* client) {
->GetStorage()
->SUnionstore(client->Keys().at(0), keys, value_to_dest, &ret);

if (!s.ok()) {
client->SetRes(CmdRes::kSyntaxErr, "sunionstore cmd error");
}
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (!s.ok()) {
client->SetRes(CmdRes::kSyntaxErr, "sunionstore cmd error");
}

client->AppendInteger(ret);
}
SInterCmd::SInterCmd(const std::string& name, int16_t arity)
Expand All @@ -87,13 +93,14 @@ bool SInterCmd::DoInitial(PClient* client) {
void SInterCmd::DoCmd(PClient* client) {
std::vector<std::string> res_vt;
storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SInter(client->Keys(), &res_vt);
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (!s.ok()) {
client->SetRes(CmdRes::kErrOther, "sinter cmd error");
return;
}
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
}
client->AppendStringVector(res_vt);
}

Expand All @@ -110,11 +117,12 @@ void SRemCmd::DoCmd(PClient* client) {
int32_t reply_num = 0;
storage::Status s =
PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SRem(client->Key(), to_delete_members, &reply_num);
if (!s.ok()) {
client->SetRes(CmdRes::kErrOther, "srem cmd error");
}
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (!s.ok()) {
client->SetRes(CmdRes::kErrOther, "srem cmd error");
}
client->AppendInteger(reply_num);
}
Expand All @@ -131,11 +139,12 @@ bool SUnionCmd::DoInitial(PClient* client) {
void SUnionCmd::DoCmd(PClient* client) {
std::vector<std::string> res_vt;
storage::Status s = PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SUnion(client->Keys(), &res_vt);
if (!s.ok()) {
client->SetRes(CmdRes::kErrOther, "sunion cmd error");
}
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (!s.ok()) {
client->SetRes(CmdRes::kErrOther, "sunion cmd error");
}
client->AppendStringVector(res_vt);
}
Expand Down Expand Up @@ -262,6 +271,10 @@ void SPopCmd::DoCmd(PClient* client) {
std::vector<std::string> delete_member;
storage::Status s =
PSTORE.GetBackend(client->GetCurrentDB())->GetStorage()->SPop(client->Key(), &delete_member, cnt);
if (s.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (!s.ok()) {
client->SetRes(CmdRes::kSyntaxErr, "spop cmd error");
return;
Expand Down Expand Up @@ -406,6 +419,10 @@ void SScanCmd::DoCmd(PClient* client) {
auto status = PSTORE.GetBackend(client->GetCurrentDB())
->GetStorage()
->SScan(client->Key(), cursor, pattern, count, &members, &next_cursor);
if (status.ToString() == ErrTypeMessage) {
client->SetRes(CmdRes::kmultikey);
return;
}
if (!status.ok() && !status.IsNotFound()) {
client->SetRes(CmdRes::kErrOther, status.ToString());
return;
Expand Down
3 changes: 3 additions & 0 deletions src/cmd_table_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void CmdTableManager::InitCmdTable() {
// keyspace
ADD_COMMAND(Del, -2);
ADD_COMMAND(Exists, -2);
ADD_COMMAND(Type, 2);
ADD_COMMAND(Expire, 3);
ADD_COMMAND(Ttl, 2);
ADD_COMMAND(PExpire, 3);
ADD_COMMAND(Expireat, 3);
ADD_COMMAND(PExpireat, 3);
Expand Down
Loading

0 comments on commit 5c2e2df

Please sign in to comment.