Skip to content

Commit 710a308

Browse files
authored
Support multiple services in bigtable::DataClient. (#449)
This fixes #433. With this change all the clients can support multiple interfaces, for example, google.longrunning.Operations.
1 parent 88031e6 commit 710a308

32 files changed

Lines changed: 540 additions & 787 deletions

bigtable/benchmarks/benchmark.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include "bigtable/benchmarks/embedded_server.h"
1919
#include "bigtable/benchmarks/random.h"
2020
#include "bigtable/benchmarks/setup.h"
21-
2221
#include <chrono>
2322
#include <deque>
23+
#include <thread>
2424

2525
namespace bigtable {
2626
namespace benchmarks {

bigtable/client/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ add_library(bigtable_client
6666
internal/throw_delegate.h
6767
internal/throw_delegate.cc
6868
internal/unary_client_utils.h
69-
internal/unary_rpc_utils.h
7069
idempotent_mutation_policy.h
7170
idempotent_mutation_policy.cc
7271
mutations.h
@@ -127,6 +126,7 @@ add_library(bigtable_client_testing
127126
testing/mock_data_client.h
128127
testing/mock_instance_admin_client.h
129128
testing/inprocess_data_client.h
129+
testing/inprocess_data_client.cc
130130
testing/inprocess_admin_client.h
131131
testing/inprocess_admin_client.cc
132132
testing/mock_mutate_rows_reader.h

bigtable/client/data_client.cc

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "bigtable/client/data_client.h"
1616
#include "bigtable/client/internal/common_client.h"
1717

18-
namespace btproto = ::google::bigtable::v2;
18+
namespace btproto = google::bigtable::v2;
1919

2020
namespace bigtable {
2121
inline namespace BIGTABLE_CLIENT_NS {
@@ -35,9 +35,7 @@ class DefaultDataClient : public DataClient {
3535
}
3636
};
3737

38-
using Impl =
39-
bigtable::internal::CommonClient<DataTraits,
40-
::google::bigtable::v2::Bigtable>;
38+
using Impl = bigtable::internal::CommonClient<DataTraits, btproto::Bigtable>;
4139

4240
public:
4341
DefaultDataClient(std::string project, std::string instance,
@@ -53,12 +51,46 @@ class DefaultDataClient : public DataClient {
5351
std::string const& project_id() const override;
5452
std::string const& instance_id() const override;
5553

56-
using BigtableStubPtr =
57-
std::shared_ptr<google::bigtable::v2::Bigtable::StubInterface>;
58-
59-
BigtableStubPtr Stub() override { return impl_.Stub(); }
54+
std::shared_ptr<grpc::Channel> Channel() override { return impl_.Channel(); }
6055
void reset() override { impl_.reset(); }
61-
void on_completion(grpc::Status const& status) override {}
56+
57+
grpc::Status MutateRow(grpc::ClientContext* context,
58+
btproto::MutateRowRequest const& request,
59+
btproto::MutateRowResponse* response) override {
60+
return impl_.Stub()->MutateRow(context, request, response);
61+
}
62+
63+
grpc::Status CheckAndMutateRow(
64+
grpc::ClientContext* context,
65+
btproto::CheckAndMutateRowRequest const& request,
66+
btproto::CheckAndMutateRowResponse* response) override {
67+
return impl_.Stub()->CheckAndMutateRow(context, request, response);
68+
}
69+
70+
grpc::Status ReadModifyWriteRow(
71+
grpc::ClientContext* context,
72+
btproto::ReadModifyWriteRowRequest const& request,
73+
btproto::ReadModifyWriteRowResponse* response) override {
74+
return impl_.Stub()->ReadModifyWriteRow(context, request, response);
75+
}
76+
77+
std::unique_ptr<grpc::ClientReaderInterface<btproto::ReadRowsResponse>>
78+
ReadRows(grpc::ClientContext* context,
79+
btproto::ReadRowsRequest const& request) override {
80+
return impl_.Stub()->ReadRows(context, request);
81+
}
82+
83+
std::unique_ptr<grpc::ClientReaderInterface<btproto::SampleRowKeysResponse>>
84+
SampleRowKeys(grpc::ClientContext* context,
85+
btproto::SampleRowKeysRequest const& request) override {
86+
return impl_.Stub()->SampleRowKeys(context, request);
87+
}
88+
89+
std::unique_ptr<grpc::ClientReaderInterface<btproto::MutateRowsResponse>>
90+
MutateRows(grpc::ClientContext* context,
91+
btproto::MutateRowsRequest const& request) override {
92+
return impl_.Stub()->MutateRows(context, request);
93+
}
6294

6395
private:
6496
std::string project_;

bigtable/client/data_client.h

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,50 @@ class DataClient {
3737
virtual std::string const& project_id() const = 0;
3838
virtual std::string const& instance_id() const = 0;
3939

40-
virtual std::shared_ptr<google::bigtable::v2::Bigtable::StubInterface>
41-
Stub() = 0;
40+
/**
41+
* Return a new channel to handle admin operations.
42+
*
43+
* Intended to access rarely used services in the same endpoints as the
44+
* Bigtable admin interfaces, for example, the google.longrunning.Operations.
45+
*/
46+
virtual std::shared_ptr<grpc::Channel> Channel() = 0;
4247

4348
/**
44-
* Reset and create a new Stub().
49+
* Reset and create new Channels.
4550
*
4651
* Currently this is only used in testing. In the future, we expect this,
4752
* or a similar member function, will be needed to handle errors that require
4853
* a new connection, or an explicit refresh of the credentials.
4954
*/
5055
virtual void reset() = 0;
5156

52-
/**
53-
* A callback for completed RPCs.
54-
*
55-
* Currently this is only used in testing. In the future, we expect that
56-
* some errors may require the class to update its state.
57-
*/
58-
virtual void on_completion(grpc::Status const&) = 0;
57+
//@{
58+
/// @name the google.bigtable.v2.Bigtable operations.
59+
virtual grpc::Status MutateRow(
60+
grpc::ClientContext* context,
61+
google::bigtable::v2::MutateRowRequest const& request,
62+
google::bigtable::v2::MutateRowResponse* response) = 0;
63+
virtual grpc::Status CheckAndMutateRow(
64+
grpc::ClientContext* context,
65+
google::bigtable::v2::CheckAndMutateRowRequest const& request,
66+
google::bigtable::v2::CheckAndMutateRowResponse* response) = 0;
67+
virtual grpc::Status ReadModifyWriteRow(
68+
grpc::ClientContext* context,
69+
google::bigtable::v2::ReadModifyWriteRowRequest const& request,
70+
google::bigtable::v2::ReadModifyWriteRowResponse* response) = 0;
71+
virtual std::unique_ptr<
72+
grpc::ClientReaderInterface<google::bigtable::v2::ReadRowsResponse>>
73+
ReadRows(grpc::ClientContext* context,
74+
google::bigtable::v2::ReadRowsRequest const& request) = 0;
75+
virtual std::unique_ptr<
76+
grpc::ClientReaderInterface<google::bigtable::v2::SampleRowKeysResponse>>
77+
SampleRowKeys(grpc::ClientContext* context,
78+
google::bigtable::v2::SampleRowKeysRequest const& request) = 0;
79+
virtual std::unique_ptr<
80+
grpc::ClientReaderInterface<google::bigtable::v2::MutateRowsResponse>>
81+
MutateRows(grpc::ClientContext* context,
82+
google::bigtable::v2::MutateRowsRequest const& request) = 0;
83+
//@}
5984
};
6085

6186
/// Create the default implementation of ClientInterface.

bigtable/client/data_client_test.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ TEST(DataClientTest, Default) {
2424
EXPECT_EQ("test-project", data_client->project_id());
2525
EXPECT_EQ("test-instance", data_client->instance_id());
2626

27-
auto stub0 = data_client->Stub();
28-
EXPECT_TRUE(stub0);
27+
auto channel0 = data_client->Channel();
28+
EXPECT_TRUE(channel0);
2929

30-
auto stub1 = data_client->Stub();
31-
EXPECT_EQ(stub0.get(), stub1.get());
30+
auto channel1 = data_client->Channel();
31+
EXPECT_EQ(channel0.get(), channel1.get());
3232

3333
data_client->reset();
34-
stub1 = data_client->Stub();
35-
EXPECT_TRUE(stub1);
36-
EXPECT_NE(stub0.get(), stub1.get());
34+
channel1 = data_client->Channel();
35+
EXPECT_TRUE(channel1);
36+
EXPECT_NE(channel0.get(), channel1.get());
3737
}

bigtable/client/internal/bulk_mutator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ BulkMutator::BulkMutator(std::string const& table_name,
5151
}
5252
}
5353

54-
grpc::Status BulkMutator::MakeOneRequest(btproto::Bigtable::StubInterface& stub,
54+
grpc::Status BulkMutator::MakeOneRequest(bigtable::DataClient& client,
5555
grpc::ClientContext& client_context) {
5656
PrepareForRequest();
5757
// Send the request to the server and read the resulting result stream.
58-
auto stream = stub.MutateRows(&client_context, mutations_);
58+
auto stream = client.MutateRows(&client_context, mutations_);
5959
btproto::MutateRowsResponse response;
6060
while (stream->Read(&response)) {
6161
ProcessResponse(response);

bigtable/client/internal/bulk_mutator.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
#ifndef GOOGLE_CLOUD_CPP_BIGTABLE_CLIENT_INTERNAL_BULK_MUTATOR_H_
1616
#define GOOGLE_CLOUD_CPP_BIGTABLE_CLIENT_INTERNAL_BULK_MUTATOR_H_
1717

18+
#include "bigtable/client/data_client.h"
1819
#include "bigtable/client/idempotent_mutation_policy.h"
1920

20-
#include <google/bigtable/v2/bigtable.grpc.pb.h>
21-
2221
namespace bigtable {
2322
inline namespace BIGTABLE_CLIENT_NS {
2423
namespace internal {
@@ -34,9 +33,8 @@ class BulkMutator {
3433
}
3534

3635
/// Send one batch request to the given stub.
37-
grpc::Status MakeOneRequest(
38-
google::bigtable::v2::Bigtable::StubInterface& stub,
39-
grpc::ClientContext& client_context);
36+
grpc::Status MakeOneRequest(bigtable::DataClient& client,
37+
grpc::ClientContext& client_context);
4038

4139
/// Give up on any pending mutations, move them to the failures array.
4240
std::vector<FailedMutation> ExtractFinalFailures();

0 commit comments

Comments
 (0)