Class MutationBatcher (2.17.0)

Objects of this class pack single row mutations into bulk mutations.

In order to maximize throughput when applying a lot of mutations to Cloud Bigtable, one should pack the mutations in BulkMutations. This class helps in doing so. Create a MutationBatcher and use MutationBatcher::AsyncApply() to apply a large stream of mutations to the same Table. Objects of this class will efficiently create batches of SingleRowMutations and maintain multiple batches "in flight".

This class also offers an easy-to-use flow control mechanism to avoid unbounded growth in its internal buffers.

Applications must provide a CompletionQueue to (asynchronously) execute these operations. The application is responsible of executing the CompletionQueue event loop in one or more threads.

Thread-safety

Instances of this class are guaranteed to work when accessed concurrently from multiple threads.

Constructors

MutationBatcher(Table, Options)

Parameters
Name Description
table Table
options Options

Functions

AsyncApply(CompletionQueue &, SingleRowMutation)

Asynchronously apply mutation.

The mutation will most likely be batched together with others to optimize for throughput. As a result, latency is likely to be worse than Table::AsyncApply.

The completion future will report the mutation's status once it completes.

The admission future should be used for flow control. In order to bound the memory usage used by MutationBatcher, one should not submit more mutations before the admission future is satisfied. Note that while the future is often already satisfied when the function returns, applications should not assume that this is always the case.

One should not make assumptions on which future will be satisfied first.

This quasi-synchronous example shows the intended use:

bigtable::MutationBatcher batcher(bigtable::Table(...args...));
bigtable::CompletionQueue cq;
std::thread cq_runner([]() { cq.Run(); });

while (HasMoreMutations()) {
  auto admission_completion = batcher.AsyncApply(cq, GenerateMutation());
  auto& admission_future = admission_completion.first;
  auto& completion_future = admission_completion.second;
  completion_future.then([](future<Status> completion_status) {
      // handle mutation completion asynchronously
      });
  // Potentially slow down submission not to make buffers in
  // MutationBatcher grow unbounded.
  admission_future.get();
}
// Wait for all mutations to complete
batcher.AsyncWaitForNoPendingRequests().get();
cq.Shutdown();
cq_runner.join();
Parameters
Name Description
cq CompletionQueue &

the completion queue that will execute the asynchronous calls, the application must ensure that one or more threads are blocked on cq.Run().

mut SingleRowMutation

the mutation. Note that this function takes ownership (and then discards) the data in the mutation. In general, a SingleRowMutation can be used to modify and/or delete multiple cells, across different columns and column families.

Returns
Type Description
std::pair< future< void >, future< Status > >

admission and completion futures

AsyncWaitForNoPendingRequests()

Asynchronously wait until all submitted mutations complete.

Returns
Type Description
future< void >

a future which will be satisfied once all mutations submitted before calling this function finish; if there are no such operations, the returned future is already satisfied.

virtual AsyncBulkApplyImpl(Table &, BulkMutation &&)

Parameters
Name Description
table Table &
mut BulkMutation &&
Returns
Type Description
future< std::vector< FailedMutation > >