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/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..9333d8ee 100644 --- a/src/pd/Client.cc +++ b/src/pd/Client.cc @@ -320,6 +320,30 @@ uint64_t Client::getGCSafePoint() return response.safe_point(); } +uint64_t Client::getGCSafePointV2(KeyspaceID keyspaceID) +{ + log->information("[test-yjy] client-c getGCSafePointV2 "+std::to_string(keyspaceID)); + pdpb::GetGCSafePointV2Request request{}; + pdpb::GetGCSafePointV2Response 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->GetGCSafePointV2(&context, request, &response); + if (!status.ok()) + { + 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()); + } + return response.safe_point(); +} + std::pair Client::getRegionByKey(const std::string & key) { pdpb::GetRegionRequest request{};