Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
google::cloud::bigtable::TableAdmin Class Reference

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

#include <google/cloud/bigtable/table_admin.h>

Classes

struct  CreateBackupParams
 Parameters for CreateBackup. More...
 
struct  ListBackupsParams
 Parameters for ListBackups. More...
 
struct  RestoreTableFromInstanceParams
 Parameters for RestoreTable. More...
 
struct  RestoreTableParams
 Parameters for RestoreTable. More...
 
struct  UpdateBackupParams
 Parameters for UpdateBackup. More...
 

Public Member Functions

 TableAdmin (std::shared_ptr< AdminClient > client, std::string instance_id)
 
template<typename... Policies>
 TableAdmin (std::shared_ptr< AdminClient > client, std::string instance_id, Policies &&... policies)
 Create a new TableAdmin using explicit policies to handle RPC errors. More...
 
 TableAdmin (TableAdmin const &)=default
 
TableAdminoperator= (TableAdmin const &)=default
 
std::string const & project () const
 
std::string const & instance_id () const
 
std::string const & instance_name () const
 
TableAdmin WithNewTarget (std::string project_id, std::string instance_id) const
 Returns a TableAdmin that reuses the connection and configuration of this TableAdmin, but with a different resource name. More...
 
StatusOr<::google::bigtable::admin::v2::Table > CreateTable (std::string table_id, TableConfig config)
 Create a new table in the instance. More...
 
StatusOr< std::vector<::google::bigtable::admin::v2::Table > > ListTables (::google::bigtable::admin::v2::Table::View view)
 Return all the tables in the instance. More...
 
StatusOr<::google::bigtable::admin::v2::Table > GetTable (std::string const &table_id, TableView view=SCHEMA_VIEW)
 Get information about a single table. More...
 
Status DeleteTable (std::string const &table_id)
 Delete a table. More...
 
StatusOr< google::bigtable::admin::v2::Backup > CreateBackup (CreateBackupParams const &params)
 Create a new backup of a table in the instance. More...
 
StatusOr< google::bigtable::admin::v2::Backup > GetBackup (std::string const &cluster_id, std::string const &backup_id)
 Get information about a single backup. More...
 
StatusOr< google::bigtable::admin::v2::Backup > UpdateBackup (UpdateBackupParams const &params)
 Updates a backup of a table in the instance. More...
 
Status DeleteBackup (std::string const &cluster_id, std::string const &backup_id)
 Delete a backup. More...
 
Status DeleteBackup (google::bigtable::admin::v2::Backup const &backup)
 Delete a backup. More...
 
StatusOr< std::vector< google::bigtable::admin::v2::Backup > > ListBackups (ListBackupsParams const &params)
 Retrieves a list of backups. More...
 
StatusOr< google::bigtable::admin::v2::Table > RestoreTable (RestoreTableParams const &params)
 Restore a backup into a new table in the instance. More...
 
StatusOr< google::bigtable::admin::v2::Table > RestoreTable (RestoreTableFromInstanceParams params)
 Restore a backup into a new table in the instance. More...
 
StatusOr<::google::bigtable::admin::v2::Table > ModifyColumnFamilies (std::string const &table_id, std::vector< ColumnFamilyModification > modifications)
 Modify the schema for an existing table. More...
 
Status DropRowsByPrefix (std::string const &table_id, std::string row_key_prefix)
 Delete all the rows that start with a given prefix. More...
 
StatusOr< std::string > GenerateConsistencyToken (std::string const &table_id)
 Generates consistency token for a table. More...
 
StatusOr< ConsistencyCheckConsistency (std::string const &table_id, std::string const &consistency_token)
 Checks consistency of a table. More...
 
google::cloud::future< StatusOr< Consistency > > WaitForConsistency (std::string const &table_id, std::string const &consistency_token)
 Checks consistency of a table with multiple calls using a separate thread. More...
 
Status DropAllRows (std::string const &table_id)
 Delete all the rows in a table. More...
 
StatusOr< google::iam::v1::Policy > GetIamPolicy (std::string const &table_id)
 Gets the policy for table_id. More...
 
StatusOr< google::iam::v1::Policy > GetIamPolicy (std::string const &cluster_id, std::string const &backup_id)
 Gets the policy for backup_id. More...
 
StatusOr< google::iam::v1::Policy > SetIamPolicy (std::string const &table_id, google::iam::v1::Policy const &iam_policy)
 Sets the IAM policy for a table. More...
 
StatusOr< google::iam::v1::Policy > SetIamPolicy (std::string const &cluster_id, std::string const &backup_id, google::iam::v1::Policy const &iam_policy)
 Sets the IAM policy for a backup. More...
 
StatusOr< std::vector< std::string > > TestIamPermissions (std::string const &table_id, std::vector< std::string > const &permissions)
 Returns a permission set that the caller has on the specified table. More...
 
StatusOr< std::vector< std::string > > TestIamPermissions (std::string const &cluster_id, std::string const &backup_id, std::vector< std::string > const &permissions)
 Returns a permission set that the caller has on the specified backup. More...
 
std::string TableName (std::string const &table_id) const
 Return the fully qualified name of a table in this object's instance. More...
 
std::string ClusterName (std::string const &cluster_id) const
 Return the fully qualified name of a Cluster. More...
 
std::string BackupName (std::string const &cluster_id, std::string const &backup_id) const
 Return the fully qualified name of a Backup. More...
 

Friends

bool operator== (TableAdmin const &a, TableAdmin const &b) noexcept
 
bool operator!= (TableAdmin const &a, TableAdmin const &b) noexcept
 

Convenience shorthands for the schema views.

using TableView = ::google::bigtable::admin::v2::Table::View
 Only populate 'name' and fields related to the table's encryption state. More...
 
static auto constexpr ENCRYPTION_VIEW
 Only populate 'name' and fields related to the table's encryption state. More...
 
static auto constexpr FULL
 Populate all the fields in the response. More...
 
static auto constexpr NAME_ONLY
 Populate only the name in the responses. More...
 
static auto constexpr REPLICATION_VIEW
 Populate only the name and the fields related to the table replication state. More...
 
static auto constexpr SCHEMA_VIEW
 Populate only the name and the fields related to the table schema. More...
 
static auto constexpr VIEW_UNSPECIFIED
 Use the default view as defined for each function. More...
 

Detailed Description

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.
namespace cbt = google::cloud::bigtable;
namespace btadmin = google::bigtable::admin::v2;
cbt::TableAdmin admin = ...;
google::cloud::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";
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28

In addition, the main page contains examples using StatusOr<T> to handle errors.

Retry, Backoff, and Idempotency Policies
The library automatically retries requests that fail with transient errors, and uses truncated 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 objects will compare equal iff they were created with the same DataClient and target the same Instance resource. Note that TableAdmin objects can compare equal with different retry/backoff/polling policies.
See also
https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
https://cloud.google.com/bigtable/docs/overview for an overview of the Cloud Bigtable data model.
https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an introduction of the main APIs into Cloud Bigtable.
https://cloud.google.com/bigtable/docs/reference/service-apis-overview for an overview of the underlying Cloud Bigtable API.
google::cloud::StatusOr for a description of the error reporting class used by this library.
LimitedTimeRetryPolicy and LimitedErrorCountRetryPolicy for alternative retry policies.
ExponentialBackoffPolicy to configure different parameters for the exponential backoff policy.
SafeIdempotentMutationPolicy and AlwaysRetryMutationPolicy for alternative idempotency policies.

Member Typedef Documentation

◆ TableView

using google::cloud::bigtable::TableAdmin::TableView = ::google::bigtable::admin::v2::Table::View

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

Constructor & Destructor Documentation

◆ TableAdmin() [1/3]

google::cloud::bigtable::TableAdmin::TableAdmin ( std::shared_ptr< AdminClient client,
std::string  instance_id 
)
inline
Parameters
clientthe interface to create grpc stubs, report errors, etc.
instance_idthe 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() [2/3]

template<typename... Policies>
google::cloud::bigtable::TableAdmin::TableAdmin ( std::shared_ptr< AdminClient client,
std::string  instance_id,
Policies &&...  policies 
)
inline

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

Parameters
clientthe interface to create grpc stubs, report errors, etc.
instance_idthe 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.
policiesthe set of policy overrides for this object.
Template Parameters
Policiesthe types of the policies to override, the types must derive from one of the following types:
  • RPCBackoffPolicy how to backoff from a failed RPC. Currently only ExponentialBackoffPolicy is implemented. You can also create your own policies that backoff using a different algorithm.
  • RPCRetryPolicy for how long to retry failed RPCs. Use LimitedErrorCountRetryPolicy to limit the number of failures allowed. Use LimitedTimeRetryPolicy to bound the time for any request. You can also create your own policies that combine time and error counts.
  • PollingPolicy for how long will the class wait for google.longrunning.Operation to complete. This class combines both the backoff policy for checking long running operations and the retry policy.
See also
GenericPollingPolicy, ExponentialBackoffPolicy, LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.

◆ TableAdmin() [3/3]

google::cloud::bigtable::TableAdmin::TableAdmin ( TableAdmin const &  )
default

Member Function Documentation

◆ BackupName()

std::string google::cloud::bigtable::TableAdmin::BackupName ( std::string const &  cluster_id,
std::string const &  backup_id 
) const
inline

Return the fully qualified name of a Backup.

◆ CheckConsistency()

StatusOr< Consistency > google::cloud::bigtable::TableAdmin::CheckConsistency ( std::string const &  table_id,
std::string const &  consistency_token 
)

Checks consistency of a table.

Parameters
table_idthe id of the table for which we want to check consistency.
consistency_tokenthe consistency token of the table.
Returns
the consistency status for the 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);
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";
}
}
Status const & status() const &
std::string const & instance_id() const
Definition: table_admin.h:259

◆ ClusterName()

std::string google::cloud::bigtable::TableAdmin::ClusterName ( std::string const &  cluster_id) const
inline

Return the fully qualified name of a Cluster.

◆ CreateBackup()

StatusOr< google::bigtable::admin::v2::Backup > google::cloud::bigtable::TableAdmin::CreateBackup ( CreateBackupParams const &  params)

Create a new backup of a table in the instance.

Parameters
paramsinstance of CreateBackupParams.
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));
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";
}

◆ CreateTable()

StatusOr<::google::bigtable::admin::v2::Table > google::cloud::bigtable::TableAdmin::CreateTable ( std::string  table_id,
TableConfig  config 
)

Create a new table in the instance.

Parameters
table_idthe 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.
configthe initial schema for the table.
Returns
the attributes of the newly created table. Notice that the server only populates the table_name() field at this time.
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);
admin.CreateTable(instance_name, table_id, std::move(t));
if (!schema) throw std::move(schema).status();
std::cout << "Table successfully created: " << schema->DebugString()
<< "\n";
}
std::string const & instance_name() const
Definition: table_admin.h:260

◆ DeleteBackup() [1/2]

Status google::cloud::bigtable::TableAdmin::DeleteBackup ( google::bigtable::admin::v2::Backup const &  backup)

Delete a backup.

Parameters
backuptypically returned by a call to GetBackup or ListBackups.
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";
}
std::string const & message() const

◆ DeleteBackup() [2/2]

Status google::cloud::bigtable::TableAdmin::DeleteBackup ( std::string const &  cluster_id,
std::string const &  backup_id 
)

Delete a backup.

Parameters
cluster_idthe 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_idthe 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.
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";
}

◆ DeleteTable()

Status google::cloud::bigtable::TableAdmin::DeleteTable ( std::string const &  table_id)

Delete a table.

Parameters
table_idthe 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
status of the operation.
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";
}

◆ DropAllRows()

Status google::cloud::bigtable::TableAdmin::DropAllRows ( std::string const &  table_id)

Delete all the rows in a table.

Parameters
table_idthe id of the table within the instance associated with this object. The full name of the table is this->instance_name() + "/tables/" + table_id
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]

◆ DropRowsByPrefix()

Status google::cloud::bigtable::TableAdmin::DropRowsByPrefix ( std::string const &  table_id,
std::string  row_key_prefix 
)

Delete all the rows that start with a given prefix.

Parameters
table_idthe 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_prefixdrop any rows that start with this 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";
}

◆ GenerateConsistencyToken()

StatusOr< std::string > google::cloud::bigtable::TableAdmin::GenerateConsistencyToken ( std::string const &  table_id)

Generates consistency token for a table.

Parameters
table_idthe id of the table for which we want to generate consistency token.
Returns
the consistency token for 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);
token = admin.GenerateConsistencyToken(table_name);
if (!token) throw std::move(token).status();
std::cout << "generated token is : " << token->consistency_token() << "\n";
}

◆ GetBackup()

StatusOr< google::bigtable::admin::v2::Backup > google::cloud::bigtable::TableAdmin::GetBackup ( std::string const &  cluster_id,
std::string const &  backup_id 
)

Get information about a single backup.

Parameters
cluster_idthe 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_idthe 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.
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);
admin.GetBackup(backup_name);
if (!backup) throw std::move(backup).status();
std::cout << backup->name() << " details=\n"
<< backup->DebugString() << "\n";
}

◆ GetIamPolicy() [1/2]

StatusOr< google::iam::v1::Policy > google::cloud::bigtable::TableAdmin::GetIamPolicy ( std::string const &  cluster_id,
std::string const &  backup_id 
)

Gets the policy for backup_id.

Parameters
cluster_idthe associated cluster that contains backup.
backup_idthe backup to query.
Returns
google::iam::v1::Policy the full IAM policy for the 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::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";
}

◆ GetIamPolicy() [2/2]

StatusOr< google::iam::v1::Policy > google::cloud::bigtable::TableAdmin::GetIamPolicy ( std::string const &  table_id)

Gets the policy for table_id.

Parameters
table_idthe table to query.
Returns
google::iam::v1::Policy the full IAM policy for the 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::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";
}

◆ GetTable()

StatusOr<::google::bigtable::admin::v2::Table > google::cloud::bigtable::TableAdmin::GetTable ( std::string const &  table_id,
TableView  view = SCHEMA_VIEW 
)

Get information about a single table.

Parameters
table_idthe id of the table within the instance associated with this object. The full name of the table is this->instance_name() + "/tables/" + table_id
viewdescribes 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
the information about the table or status.
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);
admin.GetTable(std::move(r));
if (!table) throw std::move(table).status();
std::cout << table->name() << " details=\n" << table->DebugString() << "\n";
}

◆ instance_id()

std::string const & google::cloud::bigtable::TableAdmin::instance_id ( ) const
inline

◆ instance_name()

std::string const & google::cloud::bigtable::TableAdmin::instance_name ( ) const
inline

◆ ListBackups()

StatusOr< std::vector< google::bigtable::admin::v2::Backup > > google::cloud::bigtable::TableAdmin::ListBackups ( ListBackupsParams const &  params)

Retrieves a list of backups.

Parameters
paramsinstance of ListBackupsParams.
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);
admin.ListBackups(std::move(r));
for (auto& backup : backups) {
if (!backup) throw std::move(backup).status();
std::cout << backup->name() << "\n";
}
}

◆ ListTables()

StatusOr< std::vector<::google::bigtable::admin::v2::Table > > google::cloud::bigtable::TableAdmin::ListTables ( ::google::bigtable::admin::v2::Table::View  view)

Return all the tables in the instance.

Parameters
viewdefine 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.
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);
admin.ListTables(std::move(r));
for (auto& table : tables) {
if (!table) throw std::move(table).status();
std::cout << table->name() << "\n";
}
}

◆ ModifyColumnFamilies()

StatusOr<::google::bigtable::admin::v2::Table > google::cloud::bigtable::TableAdmin::ModifyColumnFamilies ( std::string const &  table_id,
std::vector< ColumnFamilyModification modifications 
)

Modify the schema for an existing table.

Parameters
table_idthe id of the table within the instance associated with this object. The full name of the table is this->instance_name() + "/tables/" + table_id
modificationsthe list of modifications to the schema.
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);
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";
}

◆ operator=()

TableAdmin & google::cloud::bigtable::TableAdmin::operator= ( TableAdmin const &  )
default

◆ project()

std::string const & google::cloud::bigtable::TableAdmin::project ( ) const
inline

◆ RestoreTable() [1/2]

StatusOr< google::bigtable::admin::v2::Table > google::cloud::bigtable::TableAdmin::RestoreTable ( RestoreTableFromInstanceParams  params)

Restore a backup into a new table in the instance.

Parameters
paramsinstance of RestoreTableFromInstanceParams.
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);
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";
}

◆ RestoreTable() [2/2]

StatusOr< google::bigtable::admin::v2::Table > google::cloud::bigtable::TableAdmin::RestoreTable ( RestoreTableParams const &  params)

Restore a backup into a new table in the instance.

Parameters
paramsinstance of RestoreTableParams.
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);
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";
}

◆ SetIamPolicy() [1/2]

StatusOr< google::iam::v1::Policy > google::cloud::bigtable::TableAdmin::SetIamPolicy ( std::string const &  cluster_id,
std::string const &  backup_id,
google::iam::v1::Policy const &  iam_policy 
)

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.

Parameters
cluster_idwhich is the cluster containing the backup.
backup_idwhich backup to set the IAM policy for.
iam_policygoogle::iam::v1::Policy object containing role and members.
Returns
google::iam::v1::Policy the current IAM policy for the table.
Warning
ETags are currently not used by Cloud Bigtable.
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";
}

◆ SetIamPolicy() [2/2]

StatusOr< google::iam::v1::Policy > google::cloud::bigtable::TableAdmin::SetIamPolicy ( std::string const &  table_id,
google::iam::v1::Policy const &  iam_policy 
)

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.

Parameters
table_idwhich table to set the IAM policy for.
iam_policygoogle::iam::v1::Policy object containing role and members.
Returns
google::iam::v1::Policy the current IAM policy for the table.
Warning
ETags are currently not used by Cloud Bigtable.
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";
}

◆ TableName()

std::string google::cloud::bigtable::TableAdmin::TableName ( std::string const &  table_id) const
inline

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

◆ TestIamPermissions() [1/2]

StatusOr< std::vector< std::string > > google::cloud::bigtable::TableAdmin::TestIamPermissions ( std::string const &  cluster_id,
std::string const &  backup_id,
std::vector< std::string > const &  permissions 
)

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

Parameters
cluster_idthe ID of the cluster that contains the backup.
backup_idthe ID of the backup to query.
permissionsset of permissions to check for the resource.
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.

◆ TestIamPermissions() [2/2]

StatusOr< std::vector< std::string > > google::cloud::bigtable::TableAdmin::TestIamPermissions ( std::string const &  table_id,
std::vector< std::string > const &  permissions 
)

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

Parameters
table_idthe ID of the table to query.
permissionsset of permissions to check for the resource.
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.

◆ UpdateBackup()

StatusOr< google::bigtable::admin::v2::Backup > google::cloud::bigtable::TableAdmin::UpdateBackup ( UpdateBackupParams const &  params)

Updates a backup of a table in the instance.

Parameters
paramsinstance of UpdateBackupParams.
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");
admin.UpdateBackup(std::move(b), std::move(mask));
if (!backup) throw std::move(backup).status();
std::cout << backup->name() << " details=\n"
<< backup->DebugString() << "\n";
}

◆ WaitForConsistency()

google::cloud::future< StatusOr< Consistency > > google::cloud::bigtable::TableAdmin::WaitForConsistency ( std::string const &  table_id,
std::string const &  consistency_token 
)

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

Parameters
table_idthe id of the table for which we want to check consistency.
consistency_tokenthe consistency token of the table.
Returns
the consistency status for the 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::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);
consistency_token = admin.GenerateConsistencyToken(table_name);
if (!consistency_token) {
throw std::move(consistency_token).status();
}
// Start a thread to perform the background work.
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();
}

◆ WithNewTarget()

TableAdmin google::cloud::bigtable::TableAdmin::WithNewTarget ( std::string  project_id,
std::string  instance_id 
) const
inline

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

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( TableAdmin const &  a,
TableAdmin const &  b 
)
friend

◆ operator==

bool operator== ( TableAdmin const &  a,
TableAdmin const &  b 
)
friend

Member Data Documentation

◆ ENCRYPTION_VIEW

auto constexpr google::cloud::bigtable::TableAdmin::ENCRYPTION_VIEW
staticconstexpr
Initial value:
=
google::bigtable::admin::v2::Table::ENCRYPTION_VIEW

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

◆ FULL

auto constexpr google::cloud::bigtable::TableAdmin::FULL
staticconstexpr
Initial value:
=
google::bigtable::admin::v2::Table::FULL

Populate all the fields in the response.

◆ NAME_ONLY

auto constexpr google::cloud::bigtable::TableAdmin::NAME_ONLY
staticconstexpr
Initial value:
=
google::bigtable::admin::v2::Table::NAME_ONLY

Populate only the name in the responses.

◆ REPLICATION_VIEW

auto constexpr google::cloud::bigtable::TableAdmin::REPLICATION_VIEW
staticconstexpr
Initial value:
=
google::bigtable::admin::v2::Table::REPLICATION_VIEW

Populate only the name and the fields related to the table replication state.

◆ SCHEMA_VIEW

auto constexpr google::cloud::bigtable::TableAdmin::SCHEMA_VIEW
staticconstexpr
Initial value:
=
google::bigtable::admin::v2::Table::SCHEMA_VIEW

Populate only the name and the fields related to the table schema.

◆ VIEW_UNSPECIFIED

auto constexpr google::cloud::bigtable::TableAdmin::VIEW_UNSPECIFIED
staticconstexpr
Initial value:
=
google::bigtable::admin::v2::Table::VIEW_UNSPECIFIED

Use the default view as defined for each function.