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

[WIP]keyspace gc safepoint #141

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/pingcap/pd/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/pingcap/pd/IClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class IClient
virtual std::vector<metapb::Store> 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;

Expand Down
2 changes: 2 additions & 0 deletions include/pingcap/pd/MockPDClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<metapb::Region, metapb::Peer> getRegionByKey(const std::string &) override { throw Exception("not implemented", pingcap::ErrorCodes::UnknownError); }
Expand Down
24 changes: 24 additions & 0 deletions src/pd/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<metapb::Region, metapb::Peer> Client::getRegionByKey(const std::string & key)
{
pdpb::GetRegionRequest request{};
Expand Down