Google Cloud Bigtable C++ Client  1.32.1
A C++ Client Library for Google Cloud Bigtable
Classes | Public Member Functions | List of all members
google::cloud::bigtable::v1::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
 

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 constexpr auto ENCRYPTION_VIEW
 Only populate 'name' and fields related to the table's encryption state. More...
 
static constexpr auto FULL
 Populate all the fields in the response. More...
 
static constexpr auto NAME_ONLY
 Populate only the name in the responses. More...
 
static constexpr auto REPLICATION_VIEW
 Populate only the name and the fields related to the table replication state. More...
 
static constexpr auto SCHEMA_VIEW
 Populate only the name and the fields related to the table schema. More...
 
static constexpr auto VIEW_UNSPECIFIED
 Use the default view as defined for each function. More...
 
class TableAdminTester
 Only populate 'name' and fields related to the table's encryption state. More...
 
std::string const & project () const
 Only populate 'name' and fields related to the table's encryption state. More...
 
std::string const & instance_id () const
 Only populate 'name' and fields related to the table's encryption state. More...
 
std::string const & instance_name () const
 Only populate 'name' and fields related to the table's encryption state. 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...
 

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 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";
Implements the API to administer tables in a Cloud Bigtable instance.
Definition: table_admin.h:135
StatusOr<::google::bigtable::admin::v2::Table > GetTable(std::string const &table_id, TableView view=SCHEMA_VIEW)
Get information about a single table.
Definition: table_admin.cc:109
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.cc:23

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.

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

Definition at line 135 of file table_admin.h.

Member Typedef Documentation

◆ TableView

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

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

Definition at line 194 of file table_admin.h.

Constructor & Destructor Documentation

◆ TableAdmin() [1/3]

google::cloud::bigtable::v1::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.

Definition at line 143 of file table_admin.h.

◆ TableAdmin() [2/3]

template<typename... Policies>
google::cloud::bigtable::v1::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.

Definition at line 183 of file table_admin.h.

◆ TableAdmin() [3/3]

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

Member Function Documentation

◆ BackupName()

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

Return the fully qualified name of a Backup.

Definition at line 1002 of file table_admin.h.

◆ CheckConsistency()

StatusOr< Consistency > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id,
std::string const& consistency_token) {
StatusOr<cbt::Consistency> result =
admin.CheckConsistency(table_id, consistency_token);
if (!result) throw std::runtime_error(result.status().message());
if (*result == cbt::Consistency::kConsistent) {
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";
}
}
StatusOr< Consistency > CheckConsistency(std::string const &table_id, std::string const &consistency_token)
Checks consistency of a table.
Definition: table_admin.cc:535

Definition at line 535 of file table_admin.cc.

◆ ClusterName()

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

Return the fully qualified name of a Cluster.

Definition at line 996 of file table_admin.h.

◆ CreateBackup()

StatusOr< google::bigtable::admin::v2::Backup > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, 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);
}
auto expire_time = absl::ToChronoTime(t);
StatusOr<google::bigtable::admin::v2::Backup> backup =
admin.CreateBackup(cbt::TableAdmin::CreateBackupParams(
cluster_id, backup_id, table_id, expire_time));
if (!backup) throw std::runtime_error(backup.status().message());
std::cout << "Backup successfully created: " << backup->DebugString()
<< "\n";
}
StatusOr< google::bigtable::admin::v2::Backup > CreateBackup(CreateBackupParams const &params)
Create a new backup of a table in the instance.
Definition: table_admin.cc:159
absl::Time t

Definition at line 159 of file table_admin.cc.

◆ CreateTable()

StatusOr< btadmin::Table > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id) {
StatusOr<google::bigtable::admin::v2::Table> schema = admin.CreateTable(
table_id,
cbt::TableConfig({{"fam", cbt::GcRule::MaxNumVersions(10)},
{"foo", cbt::GcRule::MaxAge(std::chrono::hours(72))}},
{}));
if (!schema) throw std::runtime_error(schema.status().message());
std::cout << "Table successfully created: " << schema->DebugString()
<< "\n";
}
StatusOr<::google::bigtable::admin::v2::Table > CreateTable(std::string table_id, TableConfig config)
Create a new table in the instance.
Definition: table_admin.cc:55
Specify the initial schema for a new table.
Definition: table_config.h:30

Definition at line 55 of file table_admin.cc.

◆ DeleteBackup() [1/2]

Status google::cloud::bigtable::v1::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;
[](cbt::TableAdmin admin, std::string const& cluster_id,
std::string const& backup_id) {
google::cloud::Status status = admin.DeleteBackup(cluster_id, backup_id);
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "Backup successfully deleted\n";
}
Status DeleteBackup(std::string const &cluster_id, std::string const &backup_id)
Delete a backup.
Definition: table_admin.cc:256

Definition at line 238 of file table_admin.cc.

◆ DeleteBackup() [2/2]

Status google::cloud::bigtable::v1::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;
[](cbt::TableAdmin admin, std::string const& cluster_id,
std::string const& backup_id) {
google::cloud::Status status = admin.DeleteBackup(cluster_id, backup_id);
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "Backup successfully deleted\n";
}

Definition at line 256 of file table_admin.cc.

◆ DeleteTable()

Status google::cloud::bigtable::v1::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;
[](cbt::TableAdmin admin, std::string const& table_id) {
google::cloud::Status status = admin.DeleteTable(table_id);
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "Table successfully deleted\n";
}
Status DeleteTable(std::string const &table_id)
Delete a table.
Definition: table_admin.cc:130

Definition at line 130 of file table_admin.cc.

◆ DropAllRows()

Status google::cloud::bigtable::v1::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;
[](cbt::TableAdmin admin, std::string const& table_id) {
google::cloud::Status status = admin.DropAllRows(table_id);
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "All rows successfully deleted\n";
}
// [END bigtable_delete_rows]
// [END bigtable_truncate_table]
Status DropAllRows(std::string const &table_id)
Delete all the rows in a table.
Definition: table_admin.cc:502

Definition at line 502 of file table_admin.cc.

◆ DropRowsByPrefix()

Status google::cloud::bigtable::v1::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;
[](cbt::TableAdmin admin, std::string const& table_id,
std::string const& prefix) {
google::cloud::Status status = admin.DropRowsByPrefix(table_id, prefix);
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "All rows starting with " << prefix
<< " successfully deleted\n";
}
Status DropRowsByPrefix(std::string const &table_id, std::string row_key_prefix)
Delete all the rows that start with a given prefix.
Definition: table_admin.cc:408

Definition at line 408 of file table_admin.cc.

◆ GenerateConsistencyToken()

StatusOr< std::string > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id) {
StatusOr<std::string> token = admin.GenerateConsistencyToken(table_id);
if (!token) throw std::runtime_error(token.status().message());
std::cout << "generated token is : " << *token << "\n";
}
StatusOr< std::string > GenerateConsistencyToken(std::string const &table_id)
Generates consistency token for a table.
Definition: table_admin.cc:516

Definition at line 516 of file table_admin.cc.

◆ GetBackup()

StatusOr< google::bigtable::admin::v2::Backup > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& cluster_id,
std::string const& backup_id) {
StatusOr<google::bigtable::admin::v2::Backup> backup =
admin.GetBackup(cluster_id, backup_id);
if (!backup) throw std::runtime_error(backup.status().message());
std::cout << backup->name() << " details=\n"
<< backup->DebugString() << "\n";
}
StatusOr< google::bigtable::admin::v2::Backup > GetBackup(std::string const &cluster_id, std::string const &backup_id)
Get information about a single backup.
Definition: table_admin.cc:186

Definition at line 186 of file table_admin.cc.

◆ GetIamPolicy() [1/2]

StatusOr< google::iam::v1::Policy > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& cluster_id,
std::string const& backup_id) {
StatusOr<google::iam::v1::Policy> policy =
admin.GetIamPolicy(cluster_id, backup_id);
if (!policy) throw std::runtime_error(policy.status().message());
std::cout << "The IAM Policy is:\n" << policy->DebugString() << "\n";
}
StatusOr< google::iam::v1::Policy > GetIamPolicy(std::string const &table_id)
Gets the policy for table_id.
Definition: table_admin.cc:589

Definition at line 612 of file table_admin.cc.

◆ GetIamPolicy() [2/2]

StatusOr< google::iam::v1::Policy > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id) {
StatusOr<google::iam::v1::Policy> policy = admin.GetIamPolicy(table_id);
if (!policy) throw std::runtime_error(policy.status().message());
std::cout << "The IAM Policy for " << table_id << " is\n"
<< policy->DebugString() << "\n";
}

Definition at line 589 of file table_admin.cc.

◆ GetTable()

StatusOr< btadmin::Table > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id) {
StatusOr<google::bigtable::admin::v2::Table> table =
admin.GetTable(table_id, cbt::TableAdmin::FULL);
if (!table) throw std::runtime_error(table.status().message());
std::cout << table->name() << " details=\n" << table->DebugString() << "\n";
}

Definition at line 109 of file table_admin.cc.

◆ instance_id()

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

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

Definition at line 217 of file table_admin.h.

◆ instance_name()

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

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

Definition at line 218 of file table_admin.h.

◆ ListBackups()

StatusOr< std::vector< google::bigtable::admin::v2::Backup > > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& cluster_id,
std::string const& filter, std::string const& order_by) {
cbt::TableAdmin::ListBackupsParams list_backups_params;
list_backups_params.set_cluster(cluster_id);
list_backups_params.set_filter(filter);
list_backups_params.set_order_by(order_by);
StatusOr<std::vector<google::bigtable::admin::v2::Backup>> backups =
admin.ListBackups(std::move(list_backups_params));
if (!backups) throw std::runtime_error(backups.status().message());
for (auto const& backup : *backups) {
std::cout << backup.name() << "\n";
}
}
StatusOr< std::vector< google::bigtable::admin::v2::Backup > > ListBackups(ListBackupsParams const &params)
Retrieves a list of backups.
Definition: table_admin.cc:288

Definition at line 288 of file table_admin.cc.

◆ ListTables()

StatusOr< std::vector< btadmin::Table > > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin) {
StatusOr<std::vector<google::bigtable::admin::v2::Table>> tables =
admin.ListTables(cbt::TableAdmin::NAME_ONLY);
if (!tables) throw std::runtime_error(tables.status().message());
for (auto const& table : *tables) {
std::cout << table.name() << "\n";
}
}

Definition at line 75 of file table_admin.cc.

◆ ModifyColumnFamilies()

StatusOr< btadmin::Table > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id) {
StatusOr<google::bigtable::admin::v2::Table> schema =
table_id,
{cbt::ColumnFamilyModification::Drop("foo"),
cbt::ColumnFamilyModification::Update(
"fam", cbt::GcRule::Union(
cbt::GcRule::MaxNumVersions(5),
cbt::GcRule::MaxAge(std::chrono::hours(24 * 7)))),
cbt::ColumnFamilyModification::Create(
"bar", cbt::GcRule::Intersection(
cbt::GcRule::MaxNumVersions(3),
cbt::GcRule::MaxAge(std::chrono::hours(72))))});
if (!schema) throw std::runtime_error(schema.status().message());
std::cout << "Schema modified to: " << schema->DebugString() << "\n";
}
StatusOr<::google::bigtable::admin::v2::Table > ModifyColumnFamilies(std::string const &table_id, std::vector< ColumnFamilyModification > modifications)
Modify the schema for an existing table.
Definition: table_admin.cc:385

Definition at line 385 of file table_admin.cc.

◆ operator=()

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

◆ project()

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

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

Definition at line 216 of file table_admin.h.

◆ RestoreTable() [1/2]

StatusOr< google::bigtable::admin::v2::Table > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id,
std::string const& other_instance_id, std::string const& cluster_id,
std::string const& backup_id) {
StatusOr<google::bigtable::admin::v2::Table> table =
admin.RestoreTable(cbt::TableAdmin::RestoreTableFromInstanceParams{
table_id, cbt::BackupName(admin.project(), other_instance_id,
cluster_id, backup_id)});
if (!table) throw std::runtime_error(table.status().message());
std::cout << "Table successfully restored: " << table->DebugString()
<< "\n";
}
std::string const & project() const
Only populate 'name' and fields related to the table's encryption state.
Definition: table_admin.h:216
StatusOr< google::bigtable::admin::v2::Table > RestoreTable(RestoreTableParams const &params)
Restore a backup into a new table in the instance.
Definition: table_admin.cc:334
std::string BackupName(std::string const &project_id, std::string const &instance_id, std::string const &cluster_id, std::string const &backup_id)

Definition at line 359 of file table_admin.cc.

◆ RestoreTable() [2/2]

StatusOr< google::bigtable::admin::v2::Table > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id,
std::string const& cluster_id, std::string const& backup_id) {
StatusOr<google::bigtable::admin::v2::Table> table = admin.RestoreTable(
cbt::TableAdmin::RestoreTableParams(table_id, cluster_id, backup_id));
if (!table) throw std::runtime_error(table.status().message());
std::cout << "Table successfully restored: " << table->DebugString()
<< "\n";
}

Definition at line 334 of file table_admin.cc.

◆ SetIamPolicy() [1/2]

StatusOr< google::iam::v1::Policy > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& cluster_id,
std::string const& backup_id, std::string const& role,
std::string const& member) {
StatusOr<google::iam::v1::Policy> current =
admin.GetIamPolicy(cluster_id, backup_id);
if (!current) throw std::runtime_error(current.status().message());
// 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(cluster_id, backup_id, *current);
if (!policy) throw std::runtime_error(policy.status().message());
std::cout << "The IAM Policy is:\n" << policy->DebugString() << "\n";
}
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.
Definition: table_admin.cc:635
google::iam::v1::Binding IamBinding(std::string role, InputIt begin, InputIt end)
Create a google::iam::v1::Binding.
Definition: iam_binding.h:160

Definition at line 659 of file table_admin.cc.

◆ SetIamPolicy() [2/2]

StatusOr< google::iam::v1::Policy > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id,
std::string const& role, std::string const& member) {
StatusOr<google::iam::v1::Policy> current = admin.GetIamPolicy(table_id);
if (!current) throw std::runtime_error(current.status().message());
// 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_id, *current);
if (!policy) throw std::runtime_error(policy.status().message());
std::cout << "The IAM Policy for " << table_id << " is\n"
<< policy->DebugString() << "\n";
}

Definition at line 635 of file table_admin.cc.

◆ TableName()

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

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

Definition at line 990 of file table_admin.h.

◆ TestIamPermissions() [1/2]

StatusOr< std::vector< std::string > > google::cloud::bigtable::v1::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;
[](cbt::TableAdmin admin, std::string const& resource,
std::vector<std::string> const& permissions) {
StatusOr<std::vector<std::string>> result =
admin.TestIamPermissions(resource, permissions);
if (!result) throw std::runtime_error(result.status().message());
std::cout << "The current user has the following permissions [";
std::cout << absl::StrJoin(*result, ", ");
std::cout << "]\n";
}
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.
Definition: table_admin.cc:684
See also
https://cloud.google.com/bigtable/docs/access-control for a list of valid permissions on Google Cloud Bigtable.

Definition at line 716 of file table_admin.cc.

◆ TestIamPermissions() [2/2]

StatusOr< std::vector< std::string > > google::cloud::bigtable::v1::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;
[](cbt::TableAdmin admin, std::string const& resource,
std::vector<std::string> const& permissions) {
StatusOr<std::vector<std::string>> result =
admin.TestIamPermissions(resource, permissions);
if (!result) throw std::runtime_error(result.status().message());
std::cout << "The current user has the following permissions [";
std::cout << absl::StrJoin(*result, ", ");
std::cout << "]\n";
}
See also
https://cloud.google.com/bigtable/docs/access-control for a list of valid permissions on Google Cloud Bigtable.

Definition at line 684 of file table_admin.cc.

◆ UpdateBackup()

StatusOr< google::bigtable::admin::v2::Backup > google::cloud::bigtable::v1::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;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, 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);
}
auto expire_time = absl::ToChronoTime(t);
StatusOr<google::bigtable::admin::v2::Backup> backup =
admin.UpdateBackup(cbt::TableAdmin::UpdateBackupParams(
cluster_id, backup_id, expire_time));
if (!backup) throw std::runtime_error(backup.status().message());
std::cout << backup->name() << " details=\n"
<< backup->DebugString() << "\n";
}
StatusOr< google::bigtable::admin::v2::Backup > UpdateBackup(UpdateBackupParams const &params)
Updates a backup of a table in the instance.
Definition: table_admin.cc:219

Definition at line 219 of file table_admin.cc.

◆ WaitForConsistency()

google::cloud::future< StatusOr< Consistency > > google::cloud::bigtable::v1::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;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string const& table_id) {
StatusOr<std::string> consistency_token =
admin.GenerateConsistencyToken(table_id);
if (!consistency_token) {
throw std::runtime_error(consistency_token.status().message());
}
future<StatusOr<cbt::Consistency>> consistent_future =
admin.WaitForConsistency(table_id, *consistency_token);
auto final = consistent_future.then(
[&consistency_token](future<StatusOr<cbt::Consistency>> f) {
auto is_consistent = f.get();
if (!is_consistent) {
throw std::runtime_error(is_consistent.status().message());
}
if (*is_consistent == cbt::Consistency::kConsistent) {
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";
}
});
final.get(); // simplify example by blocking until operation is done.
}
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.
Definition: table_admin.cc:423

Definition at line 423 of file table_admin.cc.

Friends And Related Function Documentation

◆ TableAdminTester

friend class TableAdminTester
friend

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

Definition at line 1009 of file table_admin.h.

Member Data Documentation

◆ ENCRYPTION_VIEW

constexpr TableAdmin::TableView google::cloud::bigtable::v1::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.

Definition at line 196 of file table_admin.h.

◆ FULL

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

Populate all the fields in the response.

Definition at line 199 of file table_admin.h.

◆ NAME_ONLY

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

Populate only the name in the responses.

Definition at line 202 of file table_admin.h.

◆ REPLICATION_VIEW

constexpr TableAdmin::TableView google::cloud::bigtable::v1::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.

Definition at line 206 of file table_admin.h.

◆ SCHEMA_VIEW

constexpr TableAdmin::TableView google::cloud::bigtable::v1::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.

Definition at line 209 of file table_admin.h.

◆ VIEW_UNSPECIFIED

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

Use the default view as defined for each function.

Definition at line 212 of file table_admin.h.