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

[flash-408] implement get-all-stores #165

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion contrib/client-c/include/pd/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Client : public IClient

metapb::Store getStore(uint64_t store_id) override;

//std::vector<metapb::Store> getAllStores() override;
std::vector<metapb::Store> getAllStores() override;

uint64_t getGCSafePoint() override;

Expand Down
2 changes: 1 addition & 1 deletion contrib/client-c/include/pd/IClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class IClient

virtual metapb::Store getStore(uint64_t store_id) = 0;

// virtual std::vector<metapb::Store> getAllStores() = 0;
virtual std::vector<metapb::Store> getAllStores() = 0;

virtual uint64_t getGCSafePoint() = 0;

Expand Down
2 changes: 2 additions & 0 deletions contrib/client-c/include/pd/MockPDClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class MockPDClient : public IClient

~MockPDClient() override {}

std::vector<metapb::Store> getAllStores() override { throw "not implemented"; };

uint64_t getGCSafePoint() override { return 10000000; }

uint64_t getTS() override { return Clock::now().time_since_epoch().count(); }
Expand Down
26 changes: 26 additions & 0 deletions contrib/client-c/src/pd/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,31 @@ metapb::Store Client::getStore(uint64_t store_id)
return response.store();
}

std::vector<metapb::Store> Client::getAllStores()
{
pdpb::GetAllStoresRequest request{};
pdpb::GetAllStoresResponse response{};

request.set_allocated_header(requestHeader());

grpc::ClientContext context;

context.set_deadline(std::chrono::system_clock::now() + pd_timeout);

auto status = leaderStub()->GetAllStores(&context, request, &response);
if (!status.ok())
{
std::string err_msg = ("get all stores failed: " + std::to_string(status.error_code()) + ": " + status.error_message());
log->error(err_msg);
check_leader.store(true);
throw Exception(err_msg, GRPCErrorCode);
}
std::vector<metapb::Store> stores;
int size = response.stores_size();
for (int i = 0; i < size; i++)
stores.push_back(response.stores(i));
return stores;
}

} // namespace pd
} // namespace pingcap