Skip to content
Merged
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ the APIs in these libraries are stable, and are ready for production use.

- [Agent Registry API](/google/cloud/agentregistry/README.md)

### [Bigtable](/google/cloud/bigtable/README.md)

- 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.

```cpp
#include "google/cloud/bigtable/data_connection.h"

namespace cbt = ::google::cloud::bigtable;

auto connection = cbt::MakeDataConnection(
{cbt::InstanceResource(google::cloud::Project("my-project"), "my-instance")},
google::cloud::Options{});
```

## v3.6.0 - 2026-06

### New Libraries
Expand Down
11 changes: 7 additions & 4 deletions google/cloud/bigtable/benchmarks/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ void Benchmark::DeleteTable() {
Table Benchmark::MakeTable(Options connection_opts) const {
auto connection_options = MergeOptions(std::move(connection_opts), opts_);
auto table_opts = Options{}.set<AppProfileIdOption>(options_.app_profile_id);
return Table(MakeDataConnection(std::move(connection_options)),
TableResource(options_.project_id, options_.instance_id,
options_.table_id),
std::move(table_opts));
return Table(
MakeDataConnection({InstanceResource(Project(options_.project_id),
options_.instance_id)},
std::move(connection_options)),
TableResource(options_.project_id, options_.instance_id,
options_.table_id),
std::move(table_opts));
}

google::cloud::StatusOr<BenchmarkResult> Benchmark::PopulateTable() {
Expand Down
16 changes: 12 additions & 4 deletions google/cloud/bigtable/benchmarks/embedded_server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ TEST(EmbeddedServer, TableApply) {
.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
.set<EndpointOption>(server->address());

Table table(MakeDataConnection(options),
Table table(MakeDataConnection(
{InstanceResource(Project("fake-project"), "fake-instance")},
std::move(options)),
TableResource("fake-project", "fake-instance", "fake-table"));

SingleRowMutation mutation("row1",
Expand All @@ -101,7 +103,9 @@ TEST(EmbeddedServer, TableBulkApply) {
.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
.set<EndpointOption>(server->address());

Table table(MakeDataConnection(options),
Table table(MakeDataConnection(
{InstanceResource(Project("fake-project"), "fake-instance")},
std::move(options)),
TableResource("fake-project", "fake-instance", "fake-table"));

BulkMutation bulk;
Expand All @@ -128,7 +132,9 @@ TEST(EmbeddedServer, ReadRows1) {
.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
.set<EndpointOption>(server->address());

Table table(MakeDataConnection(options),
Table table(MakeDataConnection(
{InstanceResource(Project("fake-project"), "fake-instance")},
std::move(options)),
TableResource("fake-project", "fake-instance", "fake-table"));

EXPECT_EQ(0, server->read_rows_count());
Expand All @@ -150,7 +156,9 @@ TEST(EmbeddedServer, ReadRows100) {
.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
.set<EndpointOption>(server->address());

Table table(MakeDataConnection(options),
Table table(MakeDataConnection(
{InstanceResource(Project("fake-project"), "fake-instance")},
std::move(options)),
TableResource("fake-project", "fake-instance", "fake-table"));

EXPECT_EQ(0, server->read_rows_count());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ int main(int argc, char* argv[]) {

auto table = cbt::Table(
cbt::MakeDataConnection(
{cbt::InstanceResource(google::cloud::Project(options->project_id),
options->instance_id)},
Options{}.set<google::cloud::GrpcBackgroundThreadPoolSizeOption>(
options->max_batches)),
cbt::TableResource(options->project_id, options->instance_id, *table_id));
Expand Down
8 changes: 8 additions & 0 deletions google/cloud/bigtable/data_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "google/cloud/internal/disable_deprecation_warnings.inc"
#include "google/cloud/bigtable/data_connection.h"
#include "google/cloud/bigtable/internal/bigtable_stub_factory.h"
#include "google/cloud/bigtable/internal/data_connection_impl.h"
Expand Down Expand Up @@ -174,6 +175,13 @@ bigtable::RowStream DataConnection::ExecuteQuery(bigtable::ExecuteQueryParams) {
Status(StatusCode::kUnimplemented, "not implemented")));
}

std::shared_ptr<DataConnection> MakeDataConnection(
std::vector<InstanceResource> instances, Options options) {
options.set<experimental::InstanceChannelAffinityOption>(
std::move(instances));
return MakeDataConnection(std::move(options));
}

std::shared_ptr<DataConnection> MakeDataConnection(Options options) {
google::cloud::internal::CheckExpectedOptions<
AppProfileIdOption, CommonOptionList, GrpcOptionList,
Expand Down
24 changes: 24 additions & 0 deletions google/cloud/bigtable/data_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_DATA_CONNECTION_H

#include "google/cloud/bigtable/filters.h"
#include "google/cloud/bigtable/instance_resource.h"
#include "google/cloud/bigtable/internal/bigtable_stub.h"
#include "google/cloud/bigtable/mutation_branch.h"
#include "google/cloud/bigtable/mutations.h"
Expand All @@ -33,6 +34,7 @@
#include "google/cloud/stream_range.h"
#include "google/cloud/version.h"
#include <memory>
#include <vector>

namespace google {
namespace cloud {
Expand Down Expand Up @@ -168,6 +170,10 @@ class DataConnection {
* Returns a `DataConnection` object that can be used for interacting with
* the Cloud Bigtable Data API.
*
* Calling this function with a list of target @p instances automatically
* enables dynamic channel pooling for those instances, allowing the connection
* pools to scale dynamically based on outstanding RPC load.
*
* The returned connection object should not be used directly; instead it
* should be given to a `Table` instance, and methods should be invoked on
* `Table`.
Expand All @@ -186,9 +192,27 @@ class DataConnection {
* `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment and unexpected
* options will be logged.
*
* @param instances The target instances to connect to. Specifying target
* instances enables dynamic channel pooling and other connection-level
* optimizations.
* @param options (optional) Configure the `DataConnection` created by this
* function.
*/
std::shared_ptr<DataConnection> MakeDataConnection(
std::vector<InstanceResource> instances, Options options = {});

/**
* Returns a `DataConnection` object that can be used for interacting with
* the Cloud Bigtable Data API.
*
* @deprecated Use the MakeDataConnection overload that accepts a vector of
* instances.
*
* @param options (optional) Configure the `DataConnection` created by this
* function.
*/
GOOGLE_CLOUD_CPP_DEPRECATED(
"Use the MakeDataConnection overload that accepts a vector of instances.")
Comment on lines +214 to +215

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: deprecating an API that 100% of customers use seems like a big push for an optional feature.

I am sure @igorbernstein2 told you to do it though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing the existing fixed connection pool with the dynamic pool is less of an optional feature and more of an evolution of the library. The dynamic pool has performance benefits from channel priming and is more efficient with resources. Deprecating the existing MakeDataConnection helps provide "better defaults" when using the library.

std::shared_ptr<DataConnection> MakeDataConnection(Options options = {});

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Expand Down
17 changes: 17 additions & 0 deletions google/cloud/bigtable/data_connection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "google/cloud/internal/disable_deprecation_warnings.inc"
#include "google/cloud/bigtable/data_connection.h"
#include "google/cloud/bigtable/internal/bigtable_stub_factory.h"
#include "google/cloud/bigtable/options.h"
Expand Down Expand Up @@ -100,6 +101,22 @@ TEST(MakeDataConnection, TracingDisabled) {
EXPECT_THAT(span_catcher->GetSpans(), IsEmpty());
}

TEST(MakeDataConnection, WithInstances) {
InstanceResource instance_a{Project("my-project"), "instance-a"};
InstanceResource instance_b{Project("my-project"), "instance-b"};
auto conn = MakeDataConnection(
{instance_a, instance_b},
TestOptions().set<AppProfileIdOption>("user-supplied"));
auto options = conn->options();
EXPECT_TRUE(options.has<DataBackoffPolicyOption>())
<< "Options are not defaulted in MakeDataConnection()";
EXPECT_EQ(options.get<AppProfileIdOption>(), "user-supplied")
<< "User supplied Options are overridden in MakeDataConnection()";
ASSERT_TRUE(options.has<experimental::InstanceChannelAffinityOption>());
EXPECT_THAT(options.get<experimental::InstanceChannelAffinityOption>().size(),
Eq(2));
}

} // namespace
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable
Expand Down
9 changes: 7 additions & 2 deletions google/cloud/bigtable/examples/bigtable_examples_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "google/cloud/internal/disable_deprecation_warnings.inc"
#include "google/cloud/bigtable/examples/bigtable_examples_common.h"
#include "google/cloud/internal/getenv.h"
#include "absl/strings/str_join.h"
Expand Down Expand Up @@ -53,7 +54,9 @@ Commands::value_type MakeCommandEntry(std::string const& name,
throw Usage{std::move(os).str()};
}
google::cloud::bigtable::Table table(
google::cloud::bigtable::MakeDataConnection(),
google::cloud::bigtable::MakeDataConnection(
{google::cloud::bigtable::InstanceResource(
google::cloud::Project(argv[0]), argv[1])}),
google::cloud::bigtable::TableResource(argv[0], argv[1], argv[2]));
argv.erase(argv.begin(), argv.begin() + 3);
function(table, argv);
Expand Down Expand Up @@ -118,7 +121,9 @@ Commands::value_type MakeCommandEntry(std::string const& name,
throw Usage{std::move(os).str()};
}
google::cloud::bigtable::Table table(
google::cloud::bigtable::MakeDataConnection(),
google::cloud::bigtable::MakeDataConnection(
{google::cloud::bigtable::InstanceResource(
google::cloud::Project(argv[0]), argv[1])}),
google::cloud::bigtable::TableResource(argv[0], argv[1], argv[2]));
google::cloud::CompletionQueue cq;
std::thread t([&cq] { cq.Run(); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void HelloWorldAppProfile(std::vector<std::string> const& argv) {
std::string const& profile_id = argv[3];

// Create an object to access the Cloud Bigtable Data API.
auto connection = cbt::MakeDataConnection();
auto connection = cbt::MakeDataConnection(
{cbt::InstanceResource(google::cloud::Project(project_id), instance_id)});

// Use the default profile to write some data.
cbt::Table write(connection,
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/bigtable/examples/bigtable_hello_world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void BigtableHelloWorld(std::vector<std::string> const& argv) {

//! [connect data]
// Create an object to access the Cloud Bigtable Data API.
cbt::Table table(cbt::MakeDataConnection(),
cbt::Table table(cbt::MakeDataConnection({cbt::InstanceResource(
google::cloud::Project(project_id), instance_id)}),
cbt::TableResource(project_id, instance_id, table_id));
//! [connect data]
//! [connect admin] [END bigtable_hw_connect]
Expand Down
26 changes: 22 additions & 4 deletions google/cloud/bigtable/examples/client_samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ void TableSetEndpoint(std::vector<std::string> const& argv) {
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(
"private.googleapis.com");
auto resource = bigtable::TableResource(project_id, instance_id, table_id);
return bigtable::Table(bigtable::MakeDataConnection(options), resource);
return bigtable::Table(
bigtable::MakeDataConnection(
{bigtable::InstanceResource(google::cloud::Project(project_id),
instance_id)},
std::move(options)),
resource);
Comment thread
scotthart marked this conversation as resolved.
}
//! [table-set-endpoint]
(argv.at(0), argv.at(1), argv.at(2));
Expand All @@ -66,7 +71,10 @@ void SetRetryPolicy(std::vector<std::string> const& argv) {
/*maximum_delay=*/std::chrono::seconds(45),
/*scaling=*/2.0)
.clone());
auto connection = cbt::MakeDataConnection(options);
auto connection = cbt::MakeDataConnection(
{cbt::InstanceResource(google::cloud::Project(project_id),
instance_id)},
std::move(options));

auto const table_name =
cbt::TableResource(project_id, instance_id, table_id);
Expand Down Expand Up @@ -111,7 +119,12 @@ void TableWithServiceAccount(std::vector<std::string> const& argv) {
google::cloud::Options{}.set<google::cloud::UnifiedCredentialsOption>(
google::cloud::MakeServiceAccountCredentials(contents));
auto resource = bigtable::TableResource(project_id, instance_id, table_id);
return bigtable::Table(bigtable::MakeDataConnection(options), resource);
return bigtable::Table(
bigtable::MakeDataConnection(
{bigtable::InstanceResource(google::cloud::Project(project_id),
instance_id)},
std::move(options)),
resource);
Comment thread
scotthart marked this conversation as resolved.
}
//! [table-with-service-account]
(argv.at(0), argv.at(1), argv.at(2), argv.at(3));
Expand All @@ -137,7 +150,12 @@ void TableSetUniverseDomain(std::vector<std::string> const& argv) {

if (!ud_options.ok()) throw std::move(ud_options).status();
auto resource = bigtable::TableResource(project_id, instance_id, table_id);
return bigtable::Table(bigtable::MakeDataConnection(*ud_options), resource);
return bigtable::Table(
bigtable::MakeDataConnection(
{bigtable::InstanceResource(google::cloud::Project(project_id),
instance_id)},
*std::move(ud_options)),
resource);
Comment thread
scotthart marked this conversation as resolved.
}
//! [table-set-universe-domain]
(argv.at(0), argv.at(1), argv.at(2));
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/bigtable/examples/data_async_snippets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ void RunAll(std::vector<std::string> const& argv) {
if (!schema) throw std::move(schema).status();

using ::google::cloud::Options;
cbt::Table table(cbt::MakeDataConnection(),
cbt::Table table(cbt::MakeDataConnection({cbt::InstanceResource(
google::cloud::Project(project_id), instance_id)}),
cbt::TableResource(project_id, instance_id, table_id),
Options{}.set<cbt::IdempotentMutationPolicyOption>(
cbt::AlwaysRetryMutationPolicy().clone()));
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/bigtable/examples/data_filter_snippets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ void RunAll(std::vector<std::string> const& argv) {
table_id, std::move(t));
if (!schema) throw std::move(schema).status();

cbt::Table table(cbt::MakeDataConnection(),
cbt::Table table(cbt::MakeDataConnection({cbt::InstanceResource(
google::cloud::Project(project_id), instance_id)}),
cbt::TableResource(project_id, instance_id, table_id));

std::cout << "\nPreparing data for multiple examples" << std::endl;
Expand Down
Loading
Loading