Skip to content

Commit 8431f82

Browse files
authored
chore: modernize bigtable changelog update (#9430)
1 parent aa9da60 commit 8431f82

File tree

6 files changed

+155
-20
lines changed

6 files changed

+155
-20
lines changed

ARCHITECTURE.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,25 @@ defined, there are separate `${library}::*Client` objects.
9797

9898
These are some examples:
9999

100-
- Bigtable has a [bigtable::Table](/google/cloud/bigtable/table.h) client, as
101-
well as [TableAdmin](/google/cloud/bigtable/table_admin.h) and
102-
[InstanceAdmin](/google/cloud/bigtable/instance_admin.h) clients.
103-
- Storage has a single [storage::Client](/google/cloud/storage/client.h) client
100+
- Bigtable has a [`bigtable::Table`](/google/cloud/bigtable/table.h) client. It
101+
also has two admin clients:
102+
[`bigtable_admin::BigtableInstanceAdminClient`](/google/cloud/bigtable/admin/bigtable_instance_admin_client.h)
103+
and
104+
[`bigtable_admin::BigtableTableAdminClient`](/google/cloud/bigtable/admin/bigtable_table_admin_client.h).
105+
- Storage has a single [`storage::Client`](/google/cloud/storage/client.h) client
104106
class.
105107
- Pub/Sub has two non-admin clients, the
106-
[pubsub::Publisher](/google/cloud/pubsub/publisher.h)
107-
and the [pubsub::Subscriber](/google/cloud/pubsub/subscriber.h). It also has
108+
[`pubsub::Publisher`](/google/cloud/pubsub/publisher.h)
109+
and the [`pubsub::Subscriber`](/google/cloud/pubsub/subscriber.h). It also has
108110
two admin clients:
109-
[pubsub::TopicAdminClient](/google/cloud/pubsub/topic_admin_client.h),
110-
and [pubsub::SubscriptionAdminClient](/google/cloud/pubsub/subscription_admin_client.h).
111+
[`pubsub::TopicAdminClient`](/google/cloud/pubsub/topic_admin_client.h),
112+
and [`pubsub::SubscriptionAdminClient`](/google/cloud/pubsub/subscription_admin_client.h).
111113
- Spanner has one non-admin client, the
112-
[spanner::Client](/google/cloud/spanner/client.h). It also has two admin
114+
[`spanner::Client`](/google/cloud/spanner/client.h). It also has two admin
113115
clients:
114-
[spanner_admin::InstanceAdminClient](/google/cloud/spanner/admin/instance_admin_client.h),
116+
[`spanner_admin::InstanceAdminClient`](/google/cloud/spanner/admin/instance_admin_client.h),
115117
and
116-
[spanner_admin::DatabaseAdminClient](/google/cloud/spanner/admin/database_admin_client.h).
118+
[`spanner_admin::DatabaseAdminClient`](/google/cloud/spanner/admin/database_admin_client.h).
117119

118120
Generally these classes are very "thin"; they take function arguments from the
119121
application, package them in lightweight structure, and then forward the request
@@ -215,11 +217,6 @@ in order to help users diagnose option-related issues in their code.
215217

216218
## Deviations from the "normal" Architecture
217219

218-
### Bigtable
219-
220-
Bigtable does not have `*Stub` and `*Connection` classes, they are sadly merged
221-
into a single layer.
222-
223220
### Pub/Sub
224221

225222
Pub/Sub generally follow these patterns, but there is substantial code outside
@@ -238,7 +235,7 @@ the main classes to implement a few features:
238235
### Spanner
239236

240237
Spanner implements some key features in the
241-
[spanner_internal::SessionPool](/google/cloud/spanner/internal/session_pool.h).
238+
[`spanner_internal::SessionPool`](/google/cloud/spanner/internal/session_pool.h).
242239

243240
### Storage
244241

CHANGELOG.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,54 @@ case it elicits some feedback that requires changes.
127127

128128
* [Video Services](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/video/README.md)
129129

130+
### [Bigtable](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/bigtable/README.md)
131+
132+
We introduced a [new constructor][modern-table-ctor] for `Table` which accepts a
133+
`DataConnection` instead of a `DataClient`. The `DataConnection` is a new
134+
interface that more closely matches the client surface of `Table`. Read more
135+
about `*Connection` classes in our
136+
[Architecture Design][architecture-connection] document.
137+
138+
#### What are the benefits of `DataConnection`?
139+
140+
The new API greatly simplifies mocking. Every `Table::Foo(..)` call has an
141+
associated `DataConnection::Foo(...)` call. This allows you to set expectations
142+
on the exact values returned by the client call. See
143+
[Mocking the Cloud Bigtable C++ Client][howto-mock-data-api] for a complete
144+
example on how to mock the behavior of `Table` with
145+
`bigtable_mocks::MockDataConnection`.
146+
147+
The new `DataConnection` API offers more consistency across our libraries. It
148+
also enables the use of some common library features, such as our
149+
[`UnifiedCredentialsOption`][guac-dox]. Also, any new features will be added to
150+
the `DataConnection` API first.
151+
152+
#### Do I need to update my code?
153+
154+
No. If the benefits are not appealing enough, you do not need to update your
155+
code. All code that currently uses `DataClient` will continue to function as
156+
before. This includes uses of `testing::MockDataClient`.
157+
158+
However, if you are using `testing::MockDataClient` to mock the behavior of
159+
`Table` in your tests:
160+
161+
1. Be aware that we have announced our intention to remove classes derived from
162+
`DataClient` on or around 2023-05. Your tests will break then.
163+
2. Please consider using `bigtable_mocks::MockDataConnection`. It will greatly
164+
simplify your tests.
165+
166+
#### How do I update existing `DataClient` code?
167+
168+
See [Migrating from `DataClient` to `DataConnection`][cbt-dataclient-migration].
169+
170+
[modern-table-ctor]: https://github.com/googleapis/google-cloud-cpp/blob/62740c8e9180056db77d4dd3e80a6fa7ae71295a/google/cloud/bigtable/table.h#L182-L214
171+
[architecture-connection]: https://github.com/googleapis/google-cloud-cpp/blob/main/ARCHITECTURE.md#the-connection-classes
172+
[howto-mock-data-api]: https://googleapis.dev/cpp/google-cloud-bigtable/latest/bigtable-mocking.html
173+
[guac-dox]: https://googleapis.dev/cpp/google-cloud-common/latest/credentials_8h.html
174+
[new-issue]: https://github.com/googleapis/google-cloud-cpp/issues/new/choose
175+
[cbt-dataclient-migration]: https://googleapis.dev/cpp/google-cloud-bigtable/latest/migrating-from-dataclient.html
176+
[cbt-modern-policies]: https://github.com/googleapis/google-cloud-cpp/blob/62740c8e9180056db77d4dd3e80a6fa7ae71295a/google/cloud/bigtable/options.h#L137-L165
177+
130178
## v1.42.0 - 2022-06
131179

132180
We are happy to announce the following GA libraries. Unless specifically noted,

google/cloud/bigtable/doc/bigtable-mocking.dox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ In this document we describe how to write unit tests that mock
77
reader is familiar with the Google Test and Google Mock frameworks and with
88
the Cloud Bigtable C++ Client.
99

10-
## Mocking a successful `Table::ReadRows()`
10+
## Mocking a successful Table::ReadRows()
1111

1212
First include the headers for the `Table`, the mocking classes, and the Google
1313
Mock framework.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*!
2+
3+
@page migrating-from-dataclient Migrating from `DataClient` to `DataConnection`
4+
5+
In this document we describe how to migrate existing code that uses `DataClient`
6+
to use `DataConnection`.
7+
8+
All examples use the following aliases:
9+
10+
```{.cc}
11+
namespace gc = ::google::cloud;
12+
namespace cbt = ::google::cloud::bigtable;
13+
```
14+
15+
## Simple case
16+
17+
```{.cc}
18+
cbt::Table OldCode() {
19+
auto data_client = cbt::MakeDataClient("project-id", "instance-id");
20+
return cbt::Table(data_client, "table-id");
21+
}
22+
23+
cbt::Table UpdatedCode() {
24+
auto connection = cbt::MakeDataConnection();
25+
return cbt::Table(
26+
connection, cbt::TableResource("project-id", "instance-id", "table-id"));
27+
}
28+
```
29+
30+
Note that the `DataConnection` is not associated with any resource ids. They
31+
are instead packaged as a `TableResource` and passed as a single object to
32+
`Table`.
33+
34+
## Optional configuration
35+
36+
Note that there is only one `Table` constructor that accepts a
37+
`DataConnection`. All configuration is done via the `Options` parameter.
38+
39+
### Set an application profile id
40+
41+
```{.cc}
42+
cbt::Table OldCode() {
43+
auto data_client = cbt::MakeDataClient("project-id", "instance-id");
44+
return cbt::Table(data_client, "app-profile-id", "table-id");
45+
}
46+
47+
cbt::Table UpdatedCode() {
48+
auto connection = cbt::MakeDataConnection();
49+
return cbt::Table(
50+
connection, cbt::TableResource("project-id", "instance-id", "table-id"),
51+
gc::Options{}.set<cbt::AppProfileIdOption>("app-profile-id"));
52+
}
53+
```
54+
55+
### Set a custom retry policy
56+
57+
```{.cc}
58+
cbt::Table OldCode() {
59+
auto data_client = cbt::MakeDataClient("project-id", "instance-id");
60+
return cbt::Table(data_client, "table-id",
61+
cbt::LimitedErrorCountRetryPolicy(7));
62+
}
63+
64+
cbt::Table UpdatedCode() {
65+
auto connection = cbt::MakeDataConnection();
66+
return cbt::Table(connection,
67+
cbt::TableResource("project-id", "instance-id", "table-id"),
68+
gc::Options{}.set<cbt::DataRetryPolicyOption>(
69+
cbt::DataLimitedErrorCountRetryPolicy(7).clone()));
70+
}
71+
```
72+
73+
The retry, backoff, and idempotency policies are packaged in `Options` as
74+
`shared_ptr`s, instead of passed by value as variadic parameters to
75+
`Table(..., Policies&&)`.
76+
77+
Also note that the retry and backoff policy types have changed. If you defined
78+
your own policy, extending `RPCRetryPolicy` or `RPCBackoffPolicy`, it will not
79+
be compatible with the new types. The new policies do not have a
80+
`Setup(grpc::ClientContext&)` function. This function has not been included
81+
because we believe that setting up the `grpc::ClientContext`...
82+
1. Should not be tied to the retry policies.
83+
2. Is unlikely to be needed by external customers.
84+
85+
If you do need a `Setup()` feature, please [open a feature request][new-issue]
86+
explaining your use case, and we will be happy to accommodate you.
87+
88+
[new-issue]: https://github.com/googleapis/google-cloud-cpp/issues/new/choose
89+
90+
*/

google/cloud/bigtable/examples/howto_mock_data_api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ TEST(TableTest, AsyncReadRows) {
111111
auto on_row = [](cbt::Row const&) { return gc::make_ready_future(true); };
112112
auto on_finish = [](gc::Status const&) {};
113113

114-
// Make the client cal.
114+
// Make the client call.
115115
table.AsyncReadRows(on_row, on_finish, cbt::RowSet(),
116116
cbt::Filter::PassAllFilter());
117117
}

google/cloud/spanner/doc/spanner-mocking.dox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ In this document we describe how to write unit tests that mock
77
reader is familiar with the Google Test and Google Mock frameworks and with
88
the Cloud Spanner C++ Client.
99

10-
## Mocking a successful `ExecuteQuery`
10+
## Mocking a successful ExecuteQuery
1111

1212
First include the headers for the Cloud Spanner Client, the mocking class, and
1313
the Google Mock framework.

0 commit comments

Comments
 (0)