Skip to content

Commit

Permalink
cleanup: use preferred cbt API in gcs2cbt (#8913)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc authored May 7, 2022
1 parent d107832 commit baa88cf
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions google/cloud/examples/gcs2cbt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "google/cloud/bigtable/admin/bigtable_table_admin_client.h"
#include "google/cloud/bigtable/mutation_batcher.h"
#include "google/cloud/bigtable/table.h"
#include "google/cloud/bigtable/table_admin.h"
#include "google/cloud/storage/client.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/internal/random.h"
Expand Down Expand Up @@ -59,10 +59,7 @@ int main(int argc, char* argv[]) try {

// Create a connection to Cloud Bigtable and an object to manipulate the
// specific table used in this demo.
cbt::Table table(cbt::CreateDefaultDataClient(
options.project_id, options.instance_id,
cbt::ClientOptions().set_connection_pool_size(
std::thread::hardware_concurrency())),
cbt::Table table(cbt::MakeDataClient(options.project_id, options.instance_id),
options.table_id);
cbt::MutationBatcher batcher(table);

Expand All @@ -79,7 +76,7 @@ int main(int argc, char* argv[]) try {
}();

std::cout << "Starting " << thread_pool_size << " workers ..." << std::flush;
google::cloud::bigtable::CompletionQueue cq;
google::cloud::CompletionQueue cq;
std::vector<std::thread> thread_pool;
for (std::size_t i = 0; i != thread_pool_size; ++i) {
thread_pool.emplace_back([&cq] { cq.Run(); });
Expand Down Expand Up @@ -252,6 +249,7 @@ Options ParseArgsNoAutoRun(int argc, char const* const argv[]) {
Options AutoRun() {
using ::google::cloud::internal::GetEnv;
using ::google::cloud::internal::Sample;
namespace cbta = ::google::cloud::bigtable_admin;

for (auto const& var :
{"GOOGLE_CLOUD_PROJECT", "GOOGLE_CLOUD_CPP_BIGTABLE_TEST_INSTANCE_ID",
Expand All @@ -276,12 +274,16 @@ Options AutoRun() {
)""";
gcs_client.InsertObject(bucket_name, kObjectName, kTestData).value();

cbt::TableAdmin admin(
cbt::CreateDefaultAdminClient(project_id, cbt::ClientOptions{}),
instance_id);
auto schema = admin.CreateTable(
kTableId,
cbt::TableConfig({{"fam", cbt::GcRule::MaxNumVersions(2)}}, {}));
google::bigtable::admin::v2::GcRule gc;
gc.set_max_num_versions(2);
google::bigtable::admin::v2::Table t;
auto& families = *t.mutable_column_families();
*families["fam"].mutable_gc_rule() = std::move(gc);

cbta::BigtableTableAdminClient admin(
cbta::MakeBigtableTableAdminConnection());
auto schema = admin.CreateTable(cbt::InstanceName(project_id, instance_id),
kTableId, t);
// Throw the error unless it is "already exists"
if (!schema &&
schema.status().code() != google::cloud::StatusCode::kAlreadyExists) {
Expand Down

0 comments on commit baa88cf

Please sign in to comment.