Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change getvalues cmd type to getallvalues #111

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ You will see the following result if successful:

Run tools to get all values that have been set:

bazel-bin/service/tools/kv/api_tools/kv_service_tools service/tools/config/interface/service.config getvalues
bazel-bin/service/tools/kv/api_tools/kv_service_tools service/tools/config/interface/service.config getallvalues

You will see the following result if successful:

client getvalues value = [test_value]
client getallvalues value = [test_value]

## Deployment Script

Expand Down
2 changes: 1 addition & 1 deletion chain/state/chain_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST(KVServerExecutorTest, SetValue) {
EXPECT_EQ(state.SetValue("test_key", "test_value"), 0);
EXPECT_EQ(state.GetValue("test_key"), "test_value");

// GetValues and GetRange may be out of order for in-memory, so we test up to
// GetAllValues and GetRange may be out of order for in-memory, so we test up to
// 1 key-value pair
EXPECT_EQ(state.GetAllValues(), "[test_value]");
EXPECT_EQ(state.GetRange("a", "z"), "[test_value]");
Expand Down
6 changes: 3 additions & 3 deletions executor/kv/kv_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ std::unique_ptr<std::string> KVExecutor::ExecuteData(
Set(kv_request.key(), kv_request.value());
} else if (kv_request.cmd() == KVRequest::GET) {
kv_response.set_value(Get(kv_request.key()));
} else if (kv_request.cmd() == KVRequest::GETVALUES) {
kv_response.set_value(GetValues());
} else if (kv_request.cmd() == KVRequest::GETALLVALUES) {
kv_response.set_value(GetAllValues());
} else if (kv_request.cmd() == KVRequest::GETRANGE) {
kv_response.set_value(GetRange(kv_request.key(), kv_request.value()));
}
Expand All @@ -70,7 +70,7 @@ std::string KVExecutor::Get(const std::string& key) {
return state_->GetValue(key);
}

std::string KVExecutor::GetValues() { return state_->GetAllValues(); }
std::string KVExecutor::GetAllValues() { return state_->GetAllValues(); }

// Get values on a range of keys
std::string KVExecutor::GetRange(const std::string& min_key,
Expand Down
2 changes: 1 addition & 1 deletion executor/kv/kv_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class KVExecutor : public TransactionManager {
protected:
virtual void Set(const std::string& key, const std::string& value);
std::string Get(const std::string& key);
std::string GetValues();
std::string GetAllValues();
std::string GetRange(const std::string& min_key, const std::string& max_key);

private:
Expand Down
10 changes: 5 additions & 5 deletions executor/kv/kv_executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class KVExecutorTest : public Test {
return kv_response.value();
}

std::string GetValues() {
std::string GetAllValues() {
KVRequest request;
request.set_cmd(KVRequest::GETVALUES);
request.set_cmd(KVRequest::GETALLVALUES);

std::string str;
if (!request.SerializeToString(&str)) {
Expand Down Expand Up @@ -152,13 +152,13 @@ TEST_F(KVExecutorTest, SetValue) {
EXPECT_CALL(*mock_storage_ptr_, GetRange("a", "z"))
.WillOnce(Return("[test_value]"));

EXPECT_EQ(GetValues(), "[]");
EXPECT_EQ(GetAllValues(), "[]");
EXPECT_EQ(Set("test_key", "test_value"), 0);
EXPECT_EQ(Get("test_key"), "test_value");

// GetValues and GetRange may be out of order for in-memory, so we test up to
// GetAllValues and GetRange may be out of order for in-memory, so we test up to
// 1 key-value pair
EXPECT_EQ(GetValues(), "[test_value]");
EXPECT_EQ(GetAllValues(), "[test_value]");
EXPECT_EQ(GetRange("a", "z"), "[test_value]");
}

Expand Down
4 changes: 2 additions & 2 deletions interface/kv/kv_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ std::unique_ptr<std::string> KVClient::Get(const std::string& key) {
return std::make_unique<std::string>(response.value());
}

std::unique_ptr<std::string> KVClient::GetValues() {
std::unique_ptr<std::string> KVClient::GetAllValues() {
KVRequest request;
request.set_cmd(KVRequest::GETVALUES);
request.set_cmd(KVRequest::GETALLVALUES);
KVResponse response;
int ret = SendRequest(request, &response);
if (ret != 0) {
Expand Down
2 changes: 1 addition & 1 deletion interface/kv/kv_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class KVClient : public TransactionConstructor {

int Set(const std::string& key, const std::string& data);
std::unique_ptr<std::string> Get(const std::string& key);
std::unique_ptr<std::string> GetValues();
std::unique_ptr<std::string> GetAllValues();
std::unique_ptr<std::string> GetRange(const std::string& min_key,
const std::string& max_key);
};
Expand Down
2 changes: 1 addition & 1 deletion proto/kv/kv.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ message KVRequest {
NONE = 0;
SET = 1;
GET = 2;
GETVALUES = 3;
GETALLVALUES = 3;
GETRANGE = 4;
}
CMD cmd = 1;
Expand Down
12 changes: 6 additions & 6 deletions service/tools/kv/api_tools/kv_service_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ using resdb::ResDBConfig;
int main(int argc, char** argv) {
if (argc < 3) {
printf(
"<config path> <cmd>(set/get/getvalues/getrange), [key] "
"<config path> <cmd>(set/get/getallvalues/getrange), [key] "
"[value/key2]\n");
return 0;
}
std::string client_config_file = argv[1];
std::string cmd = argv[2];
std::string key;
if (cmd != "getvalues") {
if (cmd != "getallvalues") {
key = argv[3];
}
std::string value;
Expand Down Expand Up @@ -79,12 +79,12 @@ int main(int argc, char** argv) {
} else {
printf("client get value fail\n");
}
} else if (cmd == "getvalues") {
auto res = client.GetValues();
} else if (cmd == "getallvalues") {
auto res = client.GetAllValues();
if (res != nullptr) {
printf("client getvalues value = %s\n", res->c_str());
printf("client getallvalues value = %s\n", res->c_str());
} else {
printf("client getvalues value fail\n");
printf("client getallvalues value fail\n");
}
} else if (cmd == "getrange") {
auto res = client.GetRange(key, key2);
Expand Down