Google Cloud Bigtable C++ Client  0.11.0
A C++ Client Library for Google Cloud Bigtable
Public Member Functions | List of all members
google::cloud::bigtable::v0::TableAdmin Class Reference

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

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

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
 
StatusOr<::google::bigtable::admin::v2::Table > CreateTable (std::string table_id, TableConfig config)
 Create a new table in the instance. More...
 
future< StatusOr< google::bigtable::admin::v2::Table > > AsyncCreateTable (CompletionQueue &cq, std::string table_id, TableConfig config)
 Sends an asynchronous request to 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...
 
future< StatusOr< std::vector<::google::bigtable::admin::v2::Table > > > AsyncListTables (CompletionQueue &cq, google::bigtable::admin::v2::Table::View view)
 Sends an asynchronous request to get 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...
 
future< StatusOr< google::bigtable::admin::v2::Table > > AsyncGetTable (CompletionQueue &cq, std::string const &table_id, google::bigtable::admin::v2::Table::View view)
 Sends an asynchronous request to get information about an existing table. More...
 
Status DeleteTable (std::string const &table_id)
 Delete a table. More...
 
future< Status > AsyncDeleteTable (CompletionQueue &cq, std::string const &table_id)
 Start a request to asynchronously delete a table. 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...
 
future< StatusOr<::google::bigtable::admin::v2::Table > > AsyncModifyColumnFamilies (CompletionQueue &cq, std::string const &table_id, std::vector< ColumnFamilyModification > modifications)
 Make an asynchronous request to modify the column families of a 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...
 
future< Status > AsyncDropRowsByPrefix (CompletionQueue &cq, std::string const &table_id, std::string row_key_prefix)
 Make an asynchronous request to 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...
 
future< StatusOr< std::string > > AsyncGenerateConsistencyToken (CompletionQueue &cq, std::string const &table_id)
 Make an asynchronous request to 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...
 
future< StatusOr< Consistency > > AsyncCheckConsistency (CompletionQueue &cq, std::string const &table_id, std::string const &consistency_token)
 Make an asynchronous request to check 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...
 
google::cloud::future< StatusOr< Consistency > > AsyncWaitForConsistency (CompletionQueue &cq, std::string const &table_id, std::string const &consistency_token)
 Asynchronously wait until a table is consistent with the given token. More...
 
Status DropAllRows (std::string const &table_id)
 Delete all the rows in a table. More...
 
future< Status > AsyncDropAllRows (CompletionQueue &cq, std::string const &table_id)
 Make an asynchronous request to delete all the rows in a table. 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)
 Return the fully qualified name of a Cluster. More...
 

Convenience shorthands for the schema views.

using TableView = google::bigtable::admin::v2::Table::View
 
static constexpr TableView VIEW_UNSPECIFIED
 Use the default view as defined for each function. More...
 
static constexpr TableView NAME_ONLY
 Populate only the name in the responses. More...
 
static constexpr TableView SCHEMA_VIEW
 Populate only the name and the fields related to the table schema. More...
 
static constexpr TableView REPLICATION_VIEW
 Populate only the name and the fields related to the table replication state. More...
 
static constexpr TableView FULL = google::bigtable::admin::v2::Table::FULL
 Populate all the fields in the response. 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 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";

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::v0::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 127 of file table_admin.h.

Member Typedef Documentation

◆ TableView

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

Definition at line 185 of file table_admin.h.

Constructor & Destructor Documentation

◆ TableAdmin() [1/3]

google::cloud::bigtable::v0::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 135 of file table_admin.h.

◆ TableAdmin() [2/3]

template<typename... Policies>
google::cloud::bigtable::v0::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 174 of file table_admin.h.

◆ TableAdmin() [3/3]

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

Member Function Documentation

◆ AsyncCheckConsistency()

future< StatusOr< Consistency > > google::cloud::bigtable::v0::TableAdmin::AsyncCheckConsistency ( CompletionQueue cq,
std::string const &  table_id,
std::string const &  consistency_token 
)

Make an asynchronous request to check consistency of a table.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
Parameters
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
table_idthe id of the table for which we want to check consistency.
consistency_tokenthe consistency token of the table.
Returns
consistency status or status of the operation.
Idempotency
This operation is read-only and therefore it is always idempotent.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id,
std::string consistency_token) {
future<void> final =
admin.AsyncCheckConsistency(cq, table_id, consistency_token)
.then([consistency_token](future<StatusOr<cbt::Consistency>> f) {
auto consistency = f.get();
if (!consistency) {
throw std::runtime_error(consistency.status().message());
}
if (*consistency == cbt::Consistency::kConsistent) {
std::cout << "Table is consistent\n";
} else {
std::cout << "Table is not yet consistent, Please try again"
<< " later with the same token (" << consistency_token
<< ")\n";
}
});
final.get(); // block to simplify example.
}

Definition at line 497 of file table_admin.cc.

◆ AsyncCreateTable()

future< StatusOr< btadmin::Table > > google::cloud::bigtable::v0::TableAdmin::AsyncCreateTable ( CompletionQueue cq,
std::string  table_id,
TableConfig  config 
)

Sends an asynchronous request to create a new table in the instance.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
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.
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
Returns
a future that will be satisfied when the request succeeds or the retry policy expires. In the first case, the future will contain the response from the service. In the second the future is satisfied with an exception. Note that the service only fills out the table_name field for this request.
Idempotency
This operation is always treated as non-idempotent.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id) {
future<StatusOr<google::bigtable::admin::v2::Table>> table_future =
admin.AsyncCreateTable(
cq, table_id,
cbt::TableConfig(
{{"fam", cbt::GcRule::MaxNumVersions(10)},
{"foo", cbt::GcRule::MaxAge(std::chrono::hours(72))}},
{}));
auto final = table_future.then(
[](future<StatusOr<google::bigtable::admin::v2::Table>> f) {
auto table = f.get();
if (!table) {
throw std::runtime_error(table.status().message());
}
std::cout << "Table created as " << table->name() << "\n";
return google::cloud::Status();
});
final.get(); // block to simplify the example.
}

Definition at line 68 of file table_admin.cc.

◆ AsyncDeleteTable()

future< Status > google::cloud::bigtable::v0::TableAdmin::AsyncDeleteTable ( CompletionQueue cq,
std::string const &  table_id 
)

Start a request to asynchronously delete a table.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
Parameters
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
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.
Example
using google::cloud::future;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id) {
future<google::cloud::Status> status_future =
admin.AsyncDeleteTable(cq, table_id);
auto final =
status_future.then([table_id](future<google::cloud::Status> f) {
auto status = f.get();
if (!status.ok()) {
throw std::runtime_error(status.message());
}
std::cout << "Successfully deleted table: " << table_id << "\n";
});
final.get(); // block to simplify example.
}

Definition at line 203 of file table_admin.cc.

◆ AsyncDropAllRows()

future< Status > google::cloud::bigtable::v0::TableAdmin::AsyncDropAllRows ( CompletionQueue cq,
std::string const &  table_id 
)

Make an asynchronous request to delete all the rows in a table.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
Parameters
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
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.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id) {
future<google::cloud::Status> status_future =
admin.AsyncDropAllRows(cq, table_id);
auto final =
status_future.then([table_id](future<google::cloud::Status> f) {
auto status = f.get();
if (!status.ok()) {
throw std::runtime_error(status.message());
}
std::cout << "Successfully dropped all rows for table_id " << table_id
<< "\n";
});
final.get(); // block to simplify example.
}

Definition at line 407 of file table_admin.cc.

◆ AsyncDropRowsByPrefix()

future< Status > google::cloud::bigtable::v0::TableAdmin::AsyncDropRowsByPrefix ( CompletionQueue cq,
std::string const &  table_id,
std::string  row_key_prefix 
)

Make an asynchronous request to delete all the rows that start with a given prefix.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
Parameters
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
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.
Returns
status of the operation.
Idempotency
This operation is always treated as non-idempotent.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id,
std::string row_key) {
future<google::cloud::Status> status_future =
admin.AsyncDropRowsByPrefix(cq, table_id, row_key);
auto final = status_future.then([row_key](future<google::cloud::Status> f) {
auto status = f.get();
if (!status.ok()) {
throw std::runtime_error(status.message());
}
std::cout << "Successfully dropped rows with prefix " << row_key << "\n";
});
final.get(); // block to simplify example.
}

Definition at line 290 of file table_admin.cc.

◆ AsyncGenerateConsistencyToken()

future< StatusOr< std::string > > google::cloud::bigtable::v0::TableAdmin::AsyncGenerateConsistencyToken ( CompletionQueue cq,
std::string const &  table_id 
)

Make an asynchronous request to generates consistency token for a table.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
Parameters
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
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
consistency token or status of the operation.
Idempotency
This operation is read-only and therefore it is always idempotent.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id) {
future<StatusOr<std::string>> token_future =
admin.AsyncGenerateConsistencyToken(cq, table_id);
auto final = token_future.then([](future<StatusOr<std::string>> f) {
auto token = f.get();
if (!token) {
throw std::runtime_error(token.status().message());
}
std::cout << "generated token is : " << *token << "\n";
});
final.get(); // block to simplify example.
}

Definition at line 448 of file table_admin.cc.

◆ AsyncGetTable()

future< StatusOr< google::bigtable::admin::v2::Table > > google::cloud::bigtable::v0::TableAdmin::AsyncGetTable ( CompletionQueue cq,
std::string const &  table_id,
google::bigtable::admin::v2::Table::View  view 
)

Sends an asynchronous request to get information about an existing table.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
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.
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
Returns
a future that will be satisfied when the request succeeds or the retry policy expires. In the first case, the future will contain the response from the service. In the second the future is satisfied with an exception.
Idempotency
This operation is read-only and therefore it is always idempotent.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id) {
future<StatusOr<google::bigtable::admin::v2::Table>> table_future =
admin.AsyncGetTable(cq, table_id,
google::bigtable::admin::v2::Table::FULL);
auto final = table_future.then(
[](future<StatusOr<google::bigtable::admin::v2::Table>> f) {
auto table = f.get();
if (!table) {
throw std::runtime_error(table.status().message());
}
std::cout << table->name() << "\n";
for (auto const& family : table->column_families()) {
std::string const& family_name = family.first;
std::string gc_rule;
google::protobuf::TextFormat::PrintToString(family.second.gc_rule(),
&gc_rule);
std::cout << "\t" << family_name << "\t\t" << gc_rule << "\n";
}
return google::cloud::Status();
});
final.get(); // block to simplify the example.
}

Definition at line 87 of file table_admin.cc.

◆ AsyncListTables()

future< StatusOr< std::vector< btadmin::Table > > > google::cloud::bigtable::v0::TableAdmin::AsyncListTables ( CompletionQueue cq,
google::bigtable::admin::v2::Table::View  view 
)

Sends an asynchronous request to get all the tables in the instance.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
Parameters
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
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
a future that will be satisfied when the request succeeds or the retry policy expires. In the first case, the future will contain the response from the service. In the second the future is satisfied with an exception.
Idempotency
This operation is read-only and therefore it is always idempotent.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq) {
future<StatusOr<std::vector<google::bigtable::admin::v2::Table>>>
tables_future = admin.AsyncListTables(cq, cbt::TableAdmin::NAME_ONLY);
auto final = tables_future.then(
[](future<StatusOr<std::vector<google::bigtable::admin::v2::Table>>>
f) {
auto tables = f.get();
if (!tables) {
throw std::runtime_error(tables.status().message());
}
for (auto const& table : *tables) {
std::cout << table.name() << "\n";
}
return google::cloud::Status();
});
final.get(); // block to simplify the example.
}

Definition at line 140 of file table_admin.cc.

◆ AsyncModifyColumnFamilies()

future< StatusOr< btadmin::Table > > google::cloud::bigtable::v0::TableAdmin::AsyncModifyColumnFamilies ( CompletionQueue cq,
std::string const &  table_id,
std::vector< ColumnFamilyModification modifications 
)

Make an asynchronous request to modify the column families of a table.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
Parameters
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
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.
modificationsthe list of modifications to the schema.
Returns
the information about table or status.
Idempotency
This operation is always treated as non-idempotent.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id) {
future<StatusOr<google::bigtable::admin::v2::Table>> table_future =
admin.AsyncModifyColumnFamilies(
cq, 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))))});
auto final = table_future.then(
[](future<StatusOr<google::bigtable::admin::v2::Table>> f) {
auto table = f.get();
if (!table) {
throw std::runtime_error(table.status().message());
}
std::cout << table->name() << ":\n";
std::cout << table->DebugString() << "\n";
});
final.get(); // block to simplify example.
}

Definition at line 252 of file table_admin.cc.

◆ AsyncWaitForConsistency()

google::cloud::future< StatusOr< Consistency > > google::cloud::bigtable::v0::TableAdmin::AsyncWaitForConsistency ( CompletionQueue cq,
std::string const &  table_id,
std::string const &  consistency_token 
)

Asynchronously wait until a table is consistent with the given token.

Warning
This is an early version of the asynchronous APIs for Cloud Bigtable. These APIs might be changed in backward-incompatible ways. It is not subject to any SLA or deprecation policy.
Parameters
cqthe completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().
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.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, cbt::CompletionQueue cq, std::string table_id,
std::string consistency_token) {
future<StatusOr<cbt::Consistency>> result =
admin.AsyncWaitForConsistency(cq, table_id, consistency_token);
auto final = result.then([&](future<StatusOr<cbt::Consistency>> f) {
auto consistent = f.get();
if (!consistent) {
throw std::runtime_error(consistent.status().message());
}
if (*consistent == cbt::Consistency::kConsistent) {
std::cout << "The table " << table_id << " is now consistent with"
<< " the 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(); // block to simplify example.
}

Definition at line 326 of file table_admin.cc.

◆ CheckConsistency()

StatusOr< Consistency > google::cloud::bigtable::v0::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.
Example
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string table_id,
std::string 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";
}
}

Definition at line 475 of file table_admin.cc.

◆ ClusterName()

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

Return the fully qualified name of a Cluster.

Definition at line 666 of file table_admin.h.

◆ CreateTable()

StatusOr< btadmin::Table > google::cloud::bigtable::v0::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.
Example
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string 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";
}

Definition at line 48 of file table_admin.cc.

◆ DeleteTable()

Status google::cloud::bigtable::v0::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.
Example
[](cbt::TableAdmin admin, std::string 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";
}

Definition at line 186 of file table_admin.cc.

◆ DropAllRows()

Status google::cloud::bigtable::v0::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.
Example
// [START bigtable_truncate_table] [START bigtable_delete_rows]
[](cbt::TableAdmin admin, std::string 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_truncate_table] [END bigtable_delete_rows]

Definition at line 393 of file table_admin.cc.

◆ DropRowsByPrefix()

Status google::cloud::bigtable::v0::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.
Example
[](cbt::TableAdmin admin, std::string table_id, std::string 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";
}

Definition at line 275 of file table_admin.cc.

◆ GenerateConsistencyToken()

StatusOr< std::string > google::cloud::bigtable::v0::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.
Example
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string 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";
}

Definition at line 429 of file table_admin.cc.

◆ GetTable()

StatusOr< btadmin::Table > google::cloud::bigtable::v0::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.
Example
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string 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 165 of file table_admin.cc.

◆ instance_id()

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

Definition at line 204 of file table_admin.h.

◆ instance_name()

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

Definition at line 205 of file table_admin.h.

◆ ListTables()

StatusOr< std::vector< btadmin::Table > > google::cloud::bigtable::v0::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.
Example
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 107 of file table_admin.cc.

◆ ModifyColumnFamilies()

StatusOr< btadmin::Table > google::cloud::bigtable::v0::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.
Example
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string table_id) {
StatusOr<google::bigtable::admin::v2::Table> schema =
admin.ModifyColumnFamilies(
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";
}

Definition at line 229 of file table_admin.cc.

◆ operator=()

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

◆ project()

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

Definition at line 203 of file table_admin.h.

◆ TableName()

std::string google::cloud::bigtable::v0::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 661 of file table_admin.h.

◆ WaitForConsistency()

google::cloud::future< StatusOr< Consistency > > google::cloud::bigtable::v0::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.
Exceptions
std::exceptionif the operation cannot be completed.
Idempotency
This operation is read-only and therefore it is always idempotent.
Example
using google::cloud::future;
using google::cloud::StatusOr;
[](cbt::TableAdmin admin, std::string 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.
}

Definition at line 313 of file table_admin.cc.

Member Data Documentation

◆ FULL

constexpr TableAdmin::TableView google::cloud::bigtable::v0::TableAdmin::FULL = google::bigtable::admin::v2::Table::FULL
static

Populate all the fields in the response.

Definition at line 200 of file table_admin.h.

◆ NAME_ONLY

constexpr TableAdmin::TableView google::cloud::bigtable::v0::TableAdmin::NAME_ONLY
static
Initial value:
=
google::bigtable::admin::v2::Table::NAME_ONLY

Populate only the name in the responses.

Definition at line 190 of file table_admin.h.

◆ REPLICATION_VIEW

constexpr TableAdmin::TableView google::cloud::bigtable::v0::TableAdmin::REPLICATION_VIEW
static
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 197 of file table_admin.h.

◆ SCHEMA_VIEW

constexpr TableAdmin::TableView google::cloud::bigtable::v0::TableAdmin::SCHEMA_VIEW
static
Initial value:
=
google::bigtable::admin::v2::Table::SCHEMA_VIEW

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

Definition at line 193 of file table_admin.h.

◆ VIEW_UNSPECIFIED

constexpr TableAdmin::TableView google::cloud::bigtable::v0::TableAdmin::VIEW_UNSPECIFIED
static
Initial value:
=
google::bigtable::admin::v2::Table::VIEW_UNSPECIFIED

Use the default view as defined for each function.

Definition at line 187 of file table_admin.h.