Class TableAdmin (2.16.0)

Implements the API to administer tables in a Cloud Bigtable instance.

Thread-safety

Instances of this class created via copy-construction or copy-assignment share the underlying pool of connections. Access to these copies via multiple threads is guaranteed to work. Two threads operating concurrently on the same instance of this class is not guaranteed to work.

Cost

Creating a new object of type TableAdmin is comparable to creating a few objects of type std::string or a few objects of type std::shared_ptr<int>. The class represents a shallow handle to a remote object.

Error Handling

This class uses StatusOr<T> to report errors. When an operation fails to perform its work the returned StatusOr<T> contains the error details. If the ok() member function in the StatusOr<T> returns true then it contains the expected result. Operations that do not return a value simply return a google::cloud::Status indicating success or the details of the error Please consult the StatusOr<T> documentation for more details.```cpp namespace cbt = google:☁️:bigtable; namespace btadmin = google::bigtable::admin::v2; cbt::TableAdmin admin = ...; google:☁️:StatusOr<btadmin::Table> metadata = admin.GetTable(...);

if (!metadata) { std::cerr << "Error fetching table metadata\n"; return; }

// Use "metadata" as a smart pointer here, e.g.: std::cout << "The full table name is " << table->name() << " the table has " << table->column_families_size() << " column families\n";


In addition, the [main page](xref:index) contains examples using [`StatusOr`](xref:classgoogle_1_1cloud_1_1StatusOr)`<T>` to handle errors.



###### Retry, Backoff, and Idempotency Policies

The library automatically retries requests that fail with transient errors, and uses [truncated exponential backoff](https://cloud.google.com/storage/docs/exponential-backoff) to backoff between retries. The default policies are to continue retrying for up to 10 minutes. On each transient failure the backoff period is doubled, starting with an initial backoff of 100 milliseconds. The backoff period growth is truncated at 60 seconds. The default idempotency policy is to only retry idempotent operations. Note that most operations that change state are **not** idempotent.
The application can override these policies when constructing objects of this class. The documentation for the constructors show examples of this in action.



###### Equality

[`TableAdmin`](xref:classgoogle_1_1cloud_1_1bigtable_1_1TableAdmin) objects will compare equal iff they were created with the same [`DataClient`](xref:classgoogle_1_1cloud_1_1bigtable_1_1DataClient) and target the same Instance resource. Note that [`TableAdmin`](xref:classgoogle_1_1cloud_1_1bigtable_1_1TableAdmin) objects can compare equal with different retry/backoff/polling policies.

###### See Also

[https://cloud.google.com/bigtable/](https://cloud.google.com/bigtable/) for an overview of Cloud Bigtable.

###### See Also

[https://cloud.google.com/bigtable/docs/overview](https://cloud.google.com/bigtable/docs/overview) for an overview of the Cloud Bigtable data model.

###### See Also

[https://cloud.google.com/bigtable/docs/instances-clusters-nodes](https://cloud.google.com/bigtable/docs/instances-clusters-nodes) for an introduction of the main APIs into Cloud Bigtable.

###### See Also

[https://cloud.google.com/bigtable/docs/reference/service-apis-overview](https://cloud.google.com/bigtable/docs/reference/service-apis-overview) for an overview of the underlying Cloud Bigtable API.

###### See Also

[`google::cloud::StatusOr`](xref:classgoogle_1_1cloud_1_1StatusOr) for a description of the error reporting class used by this library.

###### See Also

[`LimitedTimeRetryPolicy`](xref:classgoogle_1_1cloud_1_1bigtable_1_1LimitedTimeRetryPolicy) and [`LimitedErrorCountRetryPolicy`](xref:classgoogle_1_1cloud_1_1bigtable_1_1LimitedErrorCountRetryPolicy) for alternative retry policies.

###### See Also

[`ExponentialBackoffPolicy`](xref:classgoogle_1_1cloud_1_1bigtable_1_1ExponentialBackoffPolicy) to configure different parameters for the exponential backoff policy.

###### See Also

[`SafeIdempotentMutationPolicy`](xref:classgoogle_1_1cloud_1_1bigtable_1_1SafeIdempotentMutationPolicy) and [`AlwaysRetryMutationPolicy`](xref:classgoogle_1_1cloud_1_1bigtable_1_1AlwaysRetryMutationPolicy) for alternative idempotency policies. 

Constructors

TableAdmin(std::shared_ptr< AdminClient >, std::string)

Parameters
Name Description
client std::shared_ptr< AdminClient >

the interface to create grpc stubs, report errors, etc.

instance_id std::string

the id of the instance, e.g., "my-instance", the full name (e.g. '/projects/my-project/instances/my-instance') is built using the project id in the client parameter.

TableAdmin(std::shared_ptr< AdminClient >, std::string, Policies &&...)

Create a new TableAdmin using explicit policies to handle RPC errors.

Parameters
Name Description
client std::shared_ptr< AdminClient >

the interface to create grpc stubs, report errors, etc.

instance_id std::string

the id of the instance, e.g., "my-instance", the full name (e.g. '/projects/my-project/instances/my-instance') is built using the project id in the client parameter.

policies Policies &&...

the set of policy overrides for this object.

typename...

TableAdmin(TableAdmin const &)

Parameter
Name Description
TableAdmin const &

Operators

operator=(TableAdmin const &)

Parameter
Name Description
TableAdmin const &
Returns
Type Description
TableAdmin &

Functions

project() const

Returns
Type Description
std::string const &

instance_id() const

Returns
Type Description
std::string const &

instance_name() const

Returns
Type Description
std::string const &

WithNewTarget(std::string, std::string) const

Returns a TableAdmin that reuses the connection and configuration of this TableAdmin, but with a different resource name.

Parameters
Name Description
project_id std::string
instance_id std::string
Returns
Type Description
TableAdmin

CreateTable(std::string, TableConfig)

Create a new table in the instance.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id) {
    std::string instance_name = cbt::InstanceName(project_id, instance_id);
    // Example garbage collection rule.
    google::bigtable::admin::v2::Table t;
    auto& families = *t.mutable_column_families();
    families["fam"].mutable_gc_rule()->set_max_num_versions(10);

    StatusOr<google::bigtable::admin::v2::Table> schema =
        admin.CreateTable(instance_name, table_id, std::move(t));
    if (!schema) throw std::move(schema).status();
    std::cout << "Table successfully created: " << schema->DebugString()
              << "\n";
  }
Parameters
Name Description
table_id std::string

the name of the table relative to the instance managed by this object. The full table name is projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id> where PROJECT_ID is obtained from the associated AdminClient and INSTANCE_ID is the instance_id() of this object.

config TableConfig

the initial schema for the table.

Returns
Type Description
StatusOr<::google::bigtable::admin::v2::Table >

the attributes of the newly created table. Notice that the server only populates the table_name() field at this time.

ListTables(::google::bigtable::admin::v2::Table::View)

Return all the tables in the instance.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StreamRange;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id) {
    std::string instance_name = cbt::InstanceName(project_id, instance_id);

    google::bigtable::admin::v2::ListTablesRequest r;
    r.set_parent(instance_name);
    r.set_view(google::bigtable::admin::v2::Table::NAME_ONLY);

    StreamRange<google::bigtable::admin::v2::Table> tables =
        admin.ListTables(std::move(r));
    for (auto& table : tables) {
      if (!table) throw std::move(table).status();
      std::cout << table->name() << "\n";
    }
  }
Parameter
Name Description
view ::google::bigtable::admin::v2::Table::View

define what information about the tables is retrieved.

  • VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
  • NAME: return only the name of the table.
  • VIEW_SCHEMA: return the name and the schema.
  • FULL: return all the information about the table.
Returns
Type Description
StatusOr< std::vector<::google::bigtable::admin::v2::Table > >

GetTable(std::string const &, TableView)

Get information about a single table.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);

    google::bigtable::admin::v2::GetTableRequest r;
    r.set_name(table_name);
    r.set_view(google::bigtable::admin::v2::Table::FULL);

    StatusOr<google::bigtable::admin::v2::Table> table =
        admin.GetTable(std::move(r));
    if (!table) throw std::move(table).status();
    std::cout << table->name() << " details=\n" << table->DebugString() << "\n";
  }
Parameters
Name Description
table_id std::string const &

the id of the table within the instance associated with this object. The full name of the table is this->instance_name()+ "/tables/" + table_id

view TableView

describes how much information to get about the name.

  • VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
  • NAME: return only the name of the table.
  • VIEW_SCHEMA: return the name and the schema.
  • FULL: return all the information about the table.
Returns
Type Description
StatusOr<::google::bigtable::admin::v2::Table >

the information about the table or status.

DeleteTable(std::string const &)

Delete a table.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::Status;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    Status status = admin.DeleteTable(table_name);
    if (!status.ok()) throw std::runtime_error(status.message());
    std::cout << "Table successfully deleted\n";
  }
Parameter
Name Description
table_id std::string const &

the id of the table within the instance associated with this object. The full name of the table is this->instance_name()+ "/tables/" + table_id

Returns
Type Description
Status

status of the operation.

CreateBackup(CreateBackupParams const &)

Create a new backup of a table in the instance.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::future;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id,
     std::string const& cluster_id, std::string const& backup_id,
     std::string const& expire_time_string) {
    absl::Time t;
    std::string err;
    if (!absl::ParseTime(absl::RFC3339_full, expire_time_string, &t, &err)) {
      throw std::runtime_error("Unable to parse expire_time:" + err);
    }
    std::string cluster_name =
        cbt::ClusterName(project_id, instance_id, cluster_id);
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);

    google::bigtable::admin::v2::Backup b;
    b.set_source_table(table_name);
    b.mutable_expire_time()->set_seconds(absl::ToUnixSeconds(t));

    future<StatusOr<google::bigtable::admin::v2::Backup>> backup_future =
        admin.CreateBackup(cluster_name, backup_id, std::move(b));
    auto backup = backup_future.get();
    if (!backup) throw std::move(backup).status();
    std::cout << "Backup successfully created: " << backup->DebugString()
              << "\n";
  }
Parameter
Name Description
params CreateBackupParams const &

instance of CreateBackupParams.

Returns
Type Description
StatusOr< google::bigtable::admin::v2::Backup >

GetBackup(std::string const &, std::string const &)

Get information about a single backup.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& cluster_id,
     std::string const& backup_id) {
    std::string backup_name =
        cbt::BackupName(project_id, instance_id, cluster_id, backup_id);
    StatusOr<google::bigtable::admin::v2::Backup> backup =
        admin.GetBackup(backup_name);
    if (!backup) throw std::move(backup).status();
    std::cout << backup->name() << " details=\n"
              << backup->DebugString() << "\n";
  }
Parameters
Name Description
cluster_id std::string const &

the name of the cluster relative to the instance managed by the TableAdmin object. The full cluster name is projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id> where PROJECT_ID is obtained from the associated AdminClient and INSTANCE_ID is the instance_id() of the TableAdmin object.

backup_id std::string const &

the name of the backup relative to the cluster specified. The full backup name is projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id> where PROJECT_ID is obtained from the associated AdminClient, INSTANCE_ID is the instance_id() of the TableAdmin object, and CLUSTER_ID is the cluster_id previously specified.

Returns
Type Description
StatusOr< google::bigtable::admin::v2::Backup >

UpdateBackup(UpdateBackupParams const &)

Updates a backup of a table in the instance.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& cluster_id,
     std::string const& backup_id, std::string const& expire_time_string) {
    absl::Time t;
    std::string err;
    if (!absl::ParseTime(absl::RFC3339_full, expire_time_string, &t, &err)) {
      throw std::runtime_error("Unable to parse expire_time:" + err);
    }
    std::string backup_name =
        cbt::BackupName(project_id, instance_id, cluster_id, backup_id);

    google::bigtable::admin::v2::Backup b;
    b.set_name(backup_name);
    b.mutable_expire_time()->set_seconds(absl::ToUnixSeconds(t));

    google::protobuf::FieldMask mask;
    mask.add_paths("expire_time");

    StatusOr<google::bigtable::admin::v2::Backup> backup =
        admin.UpdateBackup(std::move(b), std::move(mask));
    if (!backup) throw std::move(backup).status();
    std::cout << backup->name() << " details=\n"
              << backup->DebugString() << "\n";
  }
Parameter
Name Description
params UpdateBackupParams const &

instance of UpdateBackupParams.

Returns
Type Description
StatusOr< google::bigtable::admin::v2::Backup >

DeleteBackup(std::string const &, std::string const &)

Delete a backup.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::Status;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& cluster_id,
     std::string const& backup_id) {
    std::string backup_name =
        cbt::BackupName(project_id, instance_id, cluster_id, backup_id);
    Status status = admin.DeleteBackup(backup_name);
    if (!status.ok()) throw std::runtime_error(status.message());
    std::cout << "Backup successfully deleted\n";
  }
Parameters
Name Description
cluster_id std::string const &

the name of the cluster relative to the instance managed by the TableAdmin object. The full cluster name is projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id> where PROJECT_ID is obtained from the associated AdminClient and INSTANCE_ID is the instance_id() of the TableAdmin object.

backup_id std::string const &

the name of the backup relative to the cluster specified. The full backup name is projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id> where PROJECT_ID is obtained from the associated AdminClient, INSTANCE_ID is the instance_id() of the TableAdmin object, and CLUSTER_ID is the cluster_id previously specified.

Returns
Type Description
Status

DeleteBackup(google::bigtable::admin::v2::Backup const &)

Delete a backup.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::Status;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& cluster_id,
     std::string const& backup_id) {
    std::string backup_name =
        cbt::BackupName(project_id, instance_id, cluster_id, backup_id);
    Status status = admin.DeleteBackup(backup_name);
    if (!status.ok()) throw std::runtime_error(status.message());
    std::cout << "Backup successfully deleted\n";
  }
Parameter
Name Description
backup google::bigtable::admin::v2::Backup const &

typically returned by a call to GetBackup or ListBackups.

Returns
Type Description
Status

ListBackups(ListBackupsParams const &)

Retrieves a list of backups.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StreamRange;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& cluster_id,
     std::string const& filter, std::string const& order_by) {
    std::string cluster_name =
        cbt::ClusterName(project_id, instance_id, cluster_id);

    google::bigtable::admin::v2::ListBackupsRequest r;
    r.set_parent(cluster_name);
    r.set_filter(filter);
    r.set_order_by(order_by);

    StreamRange<google::bigtable::admin::v2::Backup> backups =
        admin.ListBackups(std::move(r));
    for (auto& backup : backups) {
      if (!backup) throw std::move(backup).status();
      std::cout << backup->name() << "\n";
    }
  }
Parameter
Name Description
params ListBackupsParams const &

instance of ListBackupsParams.

Returns
Type Description
StatusOr< std::vector< google::bigtable::admin::v2::Backup > >

RestoreTable(RestoreTableParams const &)

Restore a backup into a new table in the instance.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::future;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id,
     std::string const& cluster_id, std::string const& backup_id) {
    std::string instance_name = cbt::InstanceName(project_id, instance_id);
    std::string backup_name =
        cbt::BackupName(project_id, instance_id, cluster_id, backup_id);

    google::bigtable::admin::v2::RestoreTableRequest r;
    r.set_parent(instance_name);
    r.set_table_id(table_id);
    r.set_backup(backup_name);

    future<StatusOr<google::bigtable::admin::v2::Table>> table_future =
        admin.RestoreTable(std::move(r));
    auto table = table_future.get();
    if (!table) throw std::move(table).status();
    std::cout << "Table successfully restored: " << table->DebugString()
              << "\n";
  }
Parameter
Name Description
params RestoreTableParams const &

instance of RestoreTableParams.

Returns
Type Description
StatusOr< google::bigtable::admin::v2::Table >

RestoreTable(RestoreTableFromInstanceParams)

Restore a backup into a new table in the instance.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::future;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id,
     std::string const& other_instance_id, std::string const& cluster_id,
     std::string const& backup_id) {
    std::string instance_name = cbt::InstanceName(project_id, instance_id);
    std::string backup_name =
        cbt::BackupName(project_id, other_instance_id, cluster_id, backup_id);

    google::bigtable::admin::v2::RestoreTableRequest r;
    r.set_parent(instance_name);
    r.set_table_id(table_id);
    r.set_backup(backup_name);

    future<StatusOr<google::bigtable::admin::v2::Table>> table_future =
        admin.RestoreTable(std::move(r));
    auto table = table_future.get();
    if (!table) throw std::move(table).status();
    std::cout << "Table successfully restored: " << table->DebugString()
              << "\n";
  }
Parameter
Name Description
params RestoreTableFromInstanceParams

instance of RestoreTableFromInstanceParams.

Returns
Type Description
StatusOr< google::bigtable::admin::v2::Table >

ModifyColumnFamilies(std::string const &, std::vector< ColumnFamilyModification >)

Modify the schema for an existing table.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::bigtable::admin::v2::ModifyColumnFamiliesRequest;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    auto constexpr kSecondsPerDay =
        std::chrono::seconds(std::chrono::hours(24)).count();

    // Drop
    ModifyColumnFamiliesRequest::Modification m1;
    m1.set_id("foo");
    m1.set_drop(true);

    // Update
    ModifyColumnFamiliesRequest::Modification m2;
    m2.set_id("fam");
    m2.mutable_update()->mutable_gc_rule()->set_max_num_versions(5);

    // Create
    ModifyColumnFamiliesRequest::Modification m3;
    m3.set_id("fam");
    m3.mutable_update()->mutable_gc_rule()->mutable_max_age()->set_seconds(
        7 * kSecondsPerDay);

    StatusOr<google::bigtable::admin::v2::Table> schema =
        admin.ModifyColumnFamilies(
            table_name, {std::move(m1), std::move(m2), std::move(m3)});

    if (!schema) throw std::move(schema).status();
    std::cout << "Schema modified to: " << schema->DebugString() << "\n";
  }
Parameters
Name Description
table_id std::string const &

the id of the table within the instance associated with this object. The full name of the table is this->instance_name()+ "/tables/" + table_id

modifications std::vector< ColumnFamilyModification >

the list of modifications to the schema.

Returns
Type Description
StatusOr<::google::bigtable::admin::v2::Table >

DropRowsByPrefix(std::string const &, std::string)

Delete all the rows that start with a given prefix.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::Status;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id,
     std::string const& prefix) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);

    google::bigtable::admin::v2::DropRowRangeRequest r;
    r.set_name(table_name);
    r.set_row_key_prefix(prefix);

    Status status = admin.DropRowRange(std::move(r));
    if (!status.ok()) throw std::runtime_error(status.message());
    std::cout << "All rows starting with " << prefix
              << " successfully deleted\n";
  }
Parameters
Name Description
table_id std::string const &

the id of the table within the instance associated with this object. The full name of the table is this->instance_name()+ "/tables/" + table_id

row_key_prefix std::string

drop any rows that start with this prefix.

Returns
Type Description
Status

GenerateConsistencyToken(std::string const &)

Generates consistency token for a table.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    StatusOr<google::bigtable::admin::v2::GenerateConsistencyTokenResponse>
        token = admin.GenerateConsistencyToken(table_name);
    if (!token) throw std::move(token).status();
    std::cout << "generated token is : " << token->consistency_token() << "\n";
  }
Parameter
Name Description
table_id std::string const &

the id of the table for which we want to generate consistency token.

Returns
Type Description
StatusOr< std::string >

the consistency token for table.

CheckConsistency(std::string const &, std::string const &)

Checks consistency of a table.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id,
     std::string const& consistency_token) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    StatusOr<google::bigtable::admin::v2::CheckConsistencyResponse> result =
        admin.CheckConsistency(table_name, consistency_token);
    if (!result) throw std::move(result).status();
    if (result->consistent()) {
      std::cout << "Table is consistent with token " << consistency_token
                << "\n";
    } else {
      std::cout
          << "Table is not yet consistent, Please try again later with the"
          << " same token (" << consistency_token << ")\n";
    }
  }
Parameters
Name Description
table_id std::string const &

the id of the table for which we want to check consistency.

consistency_token std::string const &

the consistency token of the table.

Returns
Type Description
StatusOr< Consistency >

the consistency status for the table.

WaitForConsistency(std::string const &, std::string const &)

Checks consistency of a table with multiple calls using a separate thread.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::CompletionQueue;
  using ::google::cloud::future;
  using ::google::cloud::Status;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    StatusOr<google::bigtable::admin::v2::GenerateConsistencyTokenResponse>
        consistency_token = admin.GenerateConsistencyToken(table_name);
    if (!consistency_token) {
      throw std::move(consistency_token).status();
    }
    // Start a thread to perform the background work.
    CompletionQueue cq;
    std::thread cq_runner([&cq] { cq.Run(); });

    std::string token = consistency_token->consistency_token();
    future<Status> consistent_future =
        cbta::AsyncWaitForConsistency(cq, admin, table_name, token);

    // Simplify the example by blocking until the operation is done.
    Status status = consistent_future.get();
    if (!status.ok()) throw std::runtime_error(status.message());
    std::cout << "Table is consistent with token " << token << "\n";

    // Shutdown the work queue and join the background thread
    cq.Shutdown();
    cq_runner.join();
  }
Parameters
Name Description
table_id std::string const &

the id of the table for which we want to check consistency.

consistency_token std::string const &

the consistency token of the table.

Returns
Type Description
google::cloud::future< StatusOr< Consistency > >

the consistency status for the table.

DropAllRows(std::string const &)

Delete all the rows in a table.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  // [START bigtable_truncate_table]
  // [START bigtable_delete_rows]
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::Status;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);

    google::bigtable::admin::v2::DropRowRangeRequest r;
    r.set_name(table_name);
    r.set_delete_all_data_from_table(true);

    Status status = admin.DropRowRange(std::move(r));
    if (!status.ok()) throw std::runtime_error(status.message());
    std::cout << "All rows successfully deleted\n";
  }
  // [END bigtable_delete_rows]
  // [END bigtable_truncate_table]
Parameter
Name Description
table_id std::string const &

the id of the table within the instance associated with this object. The full name of the table is this->instance_name()+ "/tables/" + table_id

Returns
Type Description
Status

GetIamPolicy(std::string const &)

Gets the policy for table_id.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    StatusOr<google::iam::v1::Policy> policy = admin.GetIamPolicy(table_name);
    if (!policy) throw std::move(policy).status();
    std::cout << "The IAM Policy for " << table_id << " is\n"
              << policy->DebugString() << "\n";
  }
Parameter
Name Description
table_id std::string const &

the table to query.

Returns
Type Description
StatusOr< google::iam::v1::Policy >

google::iam::v1::Policy the full IAM policy for the table.

GetIamPolicy(std::string const &, std::string const &)

Gets the policy for backup_id.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& cluster_id,
     std::string const& backup_id) {
    std::string backup_name =
        cbt::BackupName(project_id, instance_id, cluster_id, backup_id);
    StatusOr<google::iam::v1::Policy> policy = admin.GetIamPolicy(backup_name);
    if (!policy) throw std::move(policy).status();
    std::cout << "The IAM Policy is:\n" << policy->DebugString() << "\n";
  }
Parameters
Name Description
cluster_id std::string const &

the associated cluster that contains backup.

backup_id std::string const &

the backup to query.

Returns
Type Description
StatusOr< google::iam::v1::Policy >

google::iam::v1::Policy the full IAM policy for the backup.

SetIamPolicy(std::string const &, google::iam::v1::Policy const &)

Sets the IAM policy for a table.

This is the preferred way to overload IamBindings. This is more closely coupled to the underlying protocol, enable more actions and is more likely to tolerate future protocol changes.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id,
     std::string const& role, std::string const& member) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    StatusOr<google::iam::v1::Policy> current = admin.GetIamPolicy(table_name);
    if (!current) throw std::move(current).status();
    // This example adds the member to all existing bindings for that role. If
    // there are no such bindings, it adds a new one. This might not be what the
    // user wants, e.g. in case of conditional bindings.
    size_t num_added = 0;
    for (auto& binding : *current->mutable_bindings()) {
      if (binding.role() == role) {
        binding.add_members(member);
        ++num_added;
      }
    }
    if (num_added == 0) {
      *current->add_bindings() = cbt::IamBinding(role, {member});
    }
    StatusOr<google::iam::v1::Policy> policy =
        admin.SetIamPolicy(table_name, *current);
    if (!policy) throw std::move(policy).status();
    std::cout << "The IAM Policy for " << table_id << " is\n"
              << policy->DebugString() << "\n";
  }
Parameters
Name Description
table_id std::string const &

which table to set the IAM policy for.

iam_policy google::iam::v1::Policy const &

google::iam::v1::Policy object containing role and members.

Returns
Type Description
StatusOr< google::iam::v1::Policy >

google::iam::v1::Policy the current IAM policy for the table.

SetIamPolicy(std::string const &, std::string const &, google::iam::v1::Policy const &)

Sets the IAM policy for a backup.

This is the preferred way to overload IamBindings. This is more closely coupled to the underlying protocol, enable more actions and is more likely to tolerate future protocol changes.

Idempotency

This operation is always treated as non-idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;
  using ::google::cloud::StatusOr;
  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& cluster_id,
     std::string const& backup_id, std::string const& role,
     std::string const& member) {
    std::string backup_name =
        cbt::BackupName(project_id, instance_id, cluster_id, backup_id);
    StatusOr<google::iam::v1::Policy> current = admin.GetIamPolicy(backup_name);
    if (!current) throw std::move(current).status();
    // This example adds the member to all existing bindings for that role. If
    // there are no such bindings, it adds a new one. This might not be what the
    // user wants, e.g. in case of conditional bindings.
    size_t num_added = 0;
    for (auto& binding : *current->mutable_bindings()) {
      if (binding.role() == role) {
        binding.add_members(member);
        ++num_added;
      }
    }
    if (num_added == 0) {
      *current->add_bindings() = cbt::IamBinding(role, {member});
    }
    StatusOr<google::iam::v1::Policy> policy =
        admin.SetIamPolicy(backup_name, *current);
    if (!policy) throw std::move(policy).status();
    std::cout << "The IAM Policy is:\n" << policy->DebugString() << "\n";
  }
Parameters
Name Description
cluster_id std::string const &

which is the cluster containing the backup.

backup_id std::string const &

which backup to set the IAM policy for.

iam_policy google::iam::v1::Policy const &

google::iam::v1::Policy object containing role and members.

Returns
Type Description
StatusOr< google::iam::v1::Policy >

google::iam::v1::Policy the current IAM policy for the table.

TestIamPermissions(std::string const &, std::vector< std::string > const &)

Returns a permission set that the caller has on the specified table.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  using ::google::cloud::StatusOr;
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;

  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id,
     std::vector<std::string> const& permissions) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    auto result = admin.TestIamPermissions(table_name, permissions);
    if (!result) throw std::move(result).status();
    std::cout << "The current user has the following permissions [";
    std::cout << absl::StrJoin(result->permissions(), ", ");
    std::cout << "]\n";
  }
See Also

https://cloud.google.com/bigtable/docs/access-control for a list of valid permissions on Google Cloud Bigtable.

Parameters
Name Description
table_id std::string const &

the ID of the table to query.

permissions std::vector< std::string > const &

set of permissions to check for the resource.

Returns
Type Description
StatusOr< std::vector< std::string > >

TestIamPermissions(std::string const &, std::string const &, std::vector< std::string > const &)

Returns a permission set that the caller has on the specified backup.

Idempotency

This operation is read-only and therefore it is always idempotent.

Thread-safety

Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.

Example
  using ::google::cloud::StatusOr;
  namespace cbt = ::google::cloud::bigtable;
  namespace cbta = ::google::cloud::bigtable_admin;

  [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
     std::string const& instance_id, std::string const& table_id,
     std::vector<std::string> const& permissions) {
    std::string table_name = cbt::TableName(project_id, instance_id, table_id);
    auto result = admin.TestIamPermissions(table_name, permissions);
    if (!result) throw std::move(result).status();
    std::cout << "The current user has the following permissions [";
    std::cout << absl::StrJoin(result->permissions(), ", ");
    std::cout << "]\n";
  }
See Also

https://cloud.google.com/bigtable/docs/access-control for a list of valid permissions on Google Cloud Bigtable.

Parameters
Name Description
cluster_id std::string const &

the ID of the cluster that contains the backup.

backup_id std::string const &

the ID of the backup to query.

permissions std::vector< std::string > const &

set of permissions to check for the resource.

Returns
Type Description
StatusOr< std::vector< std::string > >

TableName(std::string const &) const

Return the fully qualified name of a table in this object's instance.

Parameter
Name Description
table_id std::string const &
Returns
Type Description
std::string

ClusterName(std::string const &) const

Return the fully qualified name of a Cluster.

Parameter
Name Description
cluster_id std::string const &
Returns
Type Description
std::string

BackupName(std::string const &, std::string const &) const

Return the fully qualified name of a Backup.

Parameters
Name Description
cluster_id std::string const &
backup_id std::string const &
Returns
Type Description
std::string

Type Aliases

TableView

Alias Of: ::google::bigtable::admin::v2::Table::View

Only populate 'name' and fields related to the table's encryption state.