From 0989e08aa5b21a4ce7be08f6cd5f7c287b7b2ee7 Mon Sep 17 00:00:00 2001 From: ystaticy Date: Thu, 11 May 2023 17:14:44 +0800 Subject: [PATCH 1/5] add getgcsafepoint v2 Signed-off-by: ystaticy --- include/pingcap/pd/Client.h | 2 ++ include/pingcap/pd/IClient.h | 2 ++ include/pingcap/pd/MockPDClient.h | 2 ++ src/pd/Client.cc | 23 +++++++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/include/pingcap/pd/Client.h b/include/pingcap/pd/Client.h index f2380262..ded8c45c 100644 --- a/include/pingcap/pd/Client.h +++ b/include/pingcap/pd/Client.h @@ -56,6 +56,8 @@ class Client : public IClient uint64_t getGCSafePoint() override; + uint64_t getGCSafePointV2(KeyspaceID KeyspaceID) override; + KeyspaceID getKeyspaceID(const std::string & keyspace_name) override; bool isMock() override; diff --git a/include/pingcap/pd/IClient.h b/include/pingcap/pd/IClient.h index a9de5a74..625855f9 100644 --- a/include/pingcap/pd/IClient.h +++ b/include/pingcap/pd/IClient.h @@ -45,6 +45,8 @@ class IClient virtual std::vector getAllStores(bool exclude_tombstone) = 0; virtual uint64_t getGCSafePoint() = 0; + + virtual uint64_t getGCSafePointV2(KeyspaceID KeyspaceID) = 0; virtual KeyspaceID getKeyspaceID(const std::string & keyspace_name) = 0; diff --git a/include/pingcap/pd/MockPDClient.h b/include/pingcap/pd/MockPDClient.h index 0092aeba..15fe3d34 100644 --- a/include/pingcap/pd/MockPDClient.h +++ b/include/pingcap/pd/MockPDClient.h @@ -21,6 +21,8 @@ class MockPDClient : public IClient uint64_t getGCSafePoint() override { return 10000000; } + uint64_t getGCSafePointV2(KeyspaceID keyspaceID) override { return 10000000; } + uint64_t getTS() override { return Clock::now().time_since_epoch().count(); } std::pair getRegionByKey(const std::string &) override { throw Exception("not implemented", pingcap::ErrorCodes::UnknownError); } diff --git a/src/pd/Client.cc b/src/pd/Client.cc index 4bb7bfa5..bd3d6336 100644 --- a/src/pd/Client.cc +++ b/src/pd/Client.cc @@ -320,6 +320,29 @@ uint64_t Client::getGCSafePoint() return response.safe_point(); } +uint64_t Client::getGCSafePointV2(KeyspaceID keyspaceID) +{ + log->info("[test-yjy] client-c getGCSafePointV2 "+std::to_string(keyspaceID)) + pdpb::GetGCSafePointRequest request{}; + pdpb::GetGCSafePointResponse response{}; + request.set_allocated_header(requestHeader()); + std::string err_msg; + + grpc::ClientContext context; + + context.set_deadline(std::chrono::system_clock::now() + pd_timeout); + + auto status = leaderClient()->stub->GetGCSafePoint(&context, request, &response); + if (!status.ok()) + { + err_msg = "get safe point failed: " + std::to_string(status.error_code()) + ": " + status.error_message(); + log->error(err_msg); + check_leader.store(true); + throw Exception(err_msg, status.error_code()); + } + return response.safe_point(); +} + std::pair Client::getRegionByKey(const std::string & key) { pdpb::GetRegionRequest request{}; From ac3dbb999d3f24cabc5d488d45888d7f9ffb3474 Mon Sep 17 00:00:00 2001 From: ystaticy Date: Thu, 11 May 2023 17:20:34 +0800 Subject: [PATCH 2/5] add getgcsafepoint v2 Signed-off-by: ystaticy --- src/pd/Client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pd/Client.cc b/src/pd/Client.cc index bd3d6336..991ce86e 100644 --- a/src/pd/Client.cc +++ b/src/pd/Client.cc @@ -322,7 +322,7 @@ uint64_t Client::getGCSafePoint() uint64_t Client::getGCSafePointV2(KeyspaceID keyspaceID) { - log->info("[test-yjy] client-c getGCSafePointV2 "+std::to_string(keyspaceID)) + log->information("[test-yjy] client-c getGCSafePointV2 "+std::to_string(keyspaceID)) pdpb::GetGCSafePointRequest request{}; pdpb::GetGCSafePointResponse response{}; request.set_allocated_header(requestHeader()); From e95fd0c5e24be74935755f928649e637a2dc0ab8 Mon Sep 17 00:00:00 2001 From: ystaticy Date: Thu, 11 May 2023 17:28:24 +0800 Subject: [PATCH 3/5] add getgcsafepoint v2 Signed-off-by: ystaticy --- src/pd/Client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pd/Client.cc b/src/pd/Client.cc index 991ce86e..4d18622c 100644 --- a/src/pd/Client.cc +++ b/src/pd/Client.cc @@ -322,7 +322,7 @@ uint64_t Client::getGCSafePoint() uint64_t Client::getGCSafePointV2(KeyspaceID keyspaceID) { - log->information("[test-yjy] client-c getGCSafePointV2 "+std::to_string(keyspaceID)) + log->information("[test-yjy] client-c getGCSafePointV2 "+std::to_string(keyspaceID)); pdpb::GetGCSafePointRequest request{}; pdpb::GetGCSafePointResponse response{}; request.set_allocated_header(requestHeader()); From 4808b8bf5dd0342c77c3712997995453f1e576f5 Mon Sep 17 00:00:00 2001 From: ystaticy Date: Thu, 11 May 2023 19:06:48 +0800 Subject: [PATCH 4/5] add getgcsafepoint v2 Signed-off-by: ystaticy --- .gitmodules | 3 ++- src/pd/Client.cc | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index eaa005f9..77a113db 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,7 @@ [submodule "third_party/kvproto"] path = third_party/kvproto - url = https://github.com/pingcap/kvproto.git + url = https://github.com/ystaticy/kvproto.git + brancc= keyspace_safepoint_v2 [submodule "third_party/googletest"] path = third_party/googletest url = https://github.com/google/googletest.git diff --git a/src/pd/Client.cc b/src/pd/Client.cc index 4d18622c..3e3596ff 100644 --- a/src/pd/Client.cc +++ b/src/pd/Client.cc @@ -323,19 +323,20 @@ uint64_t Client::getGCSafePoint() uint64_t Client::getGCSafePointV2(KeyspaceID keyspaceID) { log->information("[test-yjy] client-c getGCSafePointV2 "+std::to_string(keyspaceID)); - pdpb::GetGCSafePointRequest request{}; + pdpb::GetGCSafePointV2Request request{}; pdpb::GetGCSafePointResponse response{}; request.set_allocated_header(requestHeader()); + request.set_keyspace_id(keyspaceID); std::string err_msg; grpc::ClientContext context; context.set_deadline(std::chrono::system_clock::now() + pd_timeout); - auto status = leaderClient()->stub->GetGCSafePoint(&context, request, &response); + auto status = leaderClient()->stub->GetGCSafePointV2(&context, request, &response); if (!status.ok()) { - err_msg = "get safe point failed: " + std::to_string(status.error_code()) + ": " + status.error_message(); + err_msg = "get keyspace safe point failed: " + std::to_string(status.error_code()) + ": " + status.error_message(); log->error(err_msg); check_leader.store(true); throw Exception(err_msg, status.error_code()); From 79919e4ede48f4ed3b01721503c78260f6c97f3d Mon Sep 17 00:00:00 2001 From: ystaticy Date: Fri, 26 May 2023 23:48:28 +0800 Subject: [PATCH 5/5] update resp Signed-off-by: ystaticy --- src/pd/Client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pd/Client.cc b/src/pd/Client.cc index 3e3596ff..9333d8ee 100644 --- a/src/pd/Client.cc +++ b/src/pd/Client.cc @@ -324,7 +324,7 @@ uint64_t Client::getGCSafePointV2(KeyspaceID keyspaceID) { log->information("[test-yjy] client-c getGCSafePointV2 "+std::to_string(keyspaceID)); pdpb::GetGCSafePointV2Request request{}; - pdpb::GetGCSafePointResponse response{}; + pdpb::GetGCSafePointV2Response response{}; request.set_allocated_header(requestHeader()); request.set_keyspace_id(keyspaceID); std::string err_msg;