Skip to content

Commit 3ecfe6c

Browse files
committed
feat(bigtable): add explicit instance MakeDataConnection
1 parent 0a8f509 commit 3ecfe6c

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ for details on updating existing applications using v1.x.y or v2.x.y.
99

1010
## v3.7.0 - TBD
1111

12+
### [Bigtable](/google/cloud/bigtable/README.md)
13+
14+
- Explicit instance declaration is now encouraged during client initialization via a new overload of `MakeDataConnection` that takes a `std::vector<InstanceResource>`. Specifying the target instances at client startup enables optimizing connection pooling (pre-warming/priming channels) and telemetry.
15+
16+
```cpp
17+
#include "google/cloud/bigtable/data_connection.h"
18+
19+
namespace cbt = ::google::cloud::bigtable;
20+
21+
auto connection = cbt::MakeDataConnection(
22+
{cbt::InstanceResource(google::cloud::Project("my-project"), "my-instance")},
23+
google::cloud::Options{});
24+
```
25+
1226
## v3.6.0 - 2026-06
1327
1428
### New Libraries

google/cloud/bigtable/data_connection.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "google/cloud/internal/disable_deprecation_warnings.inc"
1516
#include "google/cloud/bigtable/data_connection.h"
1617
#include "google/cloud/bigtable/internal/bigtable_stub_factory.h"
1718
#include "google/cloud/bigtable/internal/data_connection_impl.h"
@@ -174,6 +175,13 @@ bigtable::RowStream DataConnection::ExecuteQuery(bigtable::ExecuteQueryParams) {
174175
Status(StatusCode::kUnimplemented, "not implemented")));
175176
}
176177

178+
std::shared_ptr<DataConnection> MakeDataConnection(
179+
std::vector<InstanceResource> instances, Options options) {
180+
options.set<experimental::InstanceChannelAffinityOption>(
181+
std::move(instances));
182+
return MakeDataConnection(std::move(options));
183+
}
184+
177185
std::shared_ptr<DataConnection> MakeDataConnection(Options options) {
178186
google::cloud::internal::CheckExpectedOptions<
179187
AppProfileIdOption, CommonOptionList, GrpcOptionList,

google/cloud/bigtable/data_connection.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_DATA_CONNECTION_H
1717

1818
#include "google/cloud/bigtable/filters.h"
19+
#include "google/cloud/bigtable/instance_resource.h"
1920
#include "google/cloud/bigtable/internal/bigtable_stub.h"
2021
#include "google/cloud/bigtable/mutation_branch.h"
2122
#include "google/cloud/bigtable/mutations.h"
@@ -33,6 +34,7 @@
3334
#include "google/cloud/stream_range.h"
3435
#include "google/cloud/version.h"
3536
#include <memory>
37+
#include <vector>
3638

3739
namespace google {
3840
namespace cloud {
@@ -168,6 +170,10 @@ class DataConnection {
168170
* Returns a `DataConnection` object that can be used for interacting with
169171
* the Cloud Bigtable Data API.
170172
*
173+
* Calling this function with a list of target @p instances automatically
174+
* enables dynamic channel pooling for those instances, allowing the connection
175+
* pools to scale dynamically based on outstanding RPC load.
176+
*
171177
* The returned connection object should not be used directly; instead it
172178
* should be given to a `Table` instance, and methods should be invoked on
173179
* `Table`.
@@ -189,6 +195,21 @@ class DataConnection {
189195
* @param options (optional) Configure the `DataConnection` created by this
190196
* function.
191197
*/
198+
std::shared_ptr<DataConnection> MakeDataConnection(
199+
std::vector<InstanceResource> instances, Options options = {});
200+
201+
/**
202+
* Returns a `DataConnection` object that can be used for interacting with
203+
* the Cloud Bigtable Data API.
204+
*
205+
* @deprecated Use the MakeDataConnection overload that accepts a vector of
206+
* instances.
207+
*
208+
* @param options (optional) Configure the `DataConnection` created by this
209+
* function.
210+
*/
211+
GOOGLE_CLOUD_CPP_DEPRECATED(
212+
"Use the MakeDataConnection overload that accepts a vector of instances.")
192213
std::shared_ptr<DataConnection> MakeDataConnection(Options options = {});
193214

194215
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/bigtable/data_connection_test.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "google/cloud/internal/disable_deprecation_warnings.inc"
1516
#include "google/cloud/bigtable/data_connection.h"
1617
#include "google/cloud/bigtable/internal/bigtable_stub_factory.h"
1718
#include "google/cloud/bigtable/options.h"
@@ -100,6 +101,22 @@ TEST(MakeDataConnection, TracingDisabled) {
100101
EXPECT_THAT(span_catcher->GetSpans(), IsEmpty());
101102
}
102103

104+
TEST(MakeDataConnection, WithInstances) {
105+
InstanceResource instance_a{Project("my-project"), "instance-a"};
106+
InstanceResource instance_b{Project("my-project"), "instance-b"};
107+
auto conn = MakeDataConnection(
108+
{instance_a, instance_b},
109+
TestOptions().set<AppProfileIdOption>("user-supplied"));
110+
auto options = conn->options();
111+
EXPECT_TRUE(options.has<DataBackoffPolicyOption>())
112+
<< "Options are not defaulted in MakeDataConnection()";
113+
EXPECT_EQ(options.get<AppProfileIdOption>(), "user-supplied")
114+
<< "User supplied Options are overridden in MakeDataConnection()";
115+
ASSERT_TRUE(options.has<experimental::InstanceChannelAffinityOption>());
116+
EXPECT_THAT(options.get<experimental::InstanceChannelAffinityOption>().size(),
117+
Eq(2));
118+
}
119+
103120
} // namespace
104121
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
105122
} // namespace bigtable

0 commit comments

Comments
 (0)