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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eThis documentation details the \u003ccode\u003eMutationBatcher\u003c/code\u003e class, which is designed to optimize the process of applying numerous mutations to Cloud Bigtable by grouping single row mutations into bulk operations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMutationBatcher::AsyncApply()\u003c/code\u003e function efficiently manages a stream of mutations to a \u003ccode\u003eTable\u003c/code\u003e, utilizing batching and maintaining multiple batches "in flight" to improve throughput.\u003c/p\u003e\n"],["\u003cp\u003eThis class includes flow control mechanisms via "admission" futures to manage memory usage and prevent uncontrolled growth in internal buffers when applying mutations.\u003c/p\u003e\n"],["\u003cp\u003eApplications must use a \u003ccode\u003eCompletionQueue\u003c/code\u003e to execute asynchronous operations and are responsible for running the queue's event loop in separate threads.\u003c/p\u003e\n"],["\u003cp\u003eThe class offers thread-safety for concurrent access, with methods like \u003ccode\u003eAsyncApply()\u003c/code\u003e and \u003ccode\u003eAsyncWaitForNoPendingRequests()\u003c/code\u003e for managing asynchronous mutation operations.\u003c/p\u003e\n"]]],[],null,["# Class MutationBatcher (2.31.0)\n\nVersion 2.31.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/bigtable/latest/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.41.0](/cpp/docs/reference/bigtable/2.41.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.40.0](/cpp/docs/reference/bigtable/2.40.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.39.0](/cpp/docs/reference/bigtable/2.39.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.38.0](/cpp/docs/reference/bigtable/2.38.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.37.0](/cpp/docs/reference/bigtable/2.37.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.36.0](/cpp/docs/reference/bigtable/2.36.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.35.0](/cpp/docs/reference/bigtable/2.35.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.34.0](/cpp/docs/reference/bigtable/2.34.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.33.0](/cpp/docs/reference/bigtable/2.33.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.32.0](/cpp/docs/reference/bigtable/2.32.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.31.0](/cpp/docs/reference/bigtable/2.31.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.30.0](/cpp/docs/reference/bigtable/2.30.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.29.0](/cpp/docs/reference/bigtable/2.29.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.28.0](/cpp/docs/reference/bigtable/2.28.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.27.0](/cpp/docs/reference/bigtable/2.27.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.26.0](/cpp/docs/reference/bigtable/2.26.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.25.1](/cpp/docs/reference/bigtable/2.25.1/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.24.0](/cpp/docs/reference/bigtable/2.24.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.23.0](/cpp/docs/reference/bigtable/2.23.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.22.1](/cpp/docs/reference/bigtable/2.22.1/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.21.0](/cpp/docs/reference/bigtable/2.21.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.20.0](/cpp/docs/reference/bigtable/2.20.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.19.0](/cpp/docs/reference/bigtable/2.19.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.18.0](/cpp/docs/reference/bigtable/2.18.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.17.0](/cpp/docs/reference/bigtable/2.17.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.16.0](/cpp/docs/reference/bigtable/2.16.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.15.1](/cpp/docs/reference/bigtable/2.15.1/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.14.0](/cpp/docs/reference/bigtable/2.14.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.13.0](/cpp/docs/reference/bigtable/2.13.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.12.0](/cpp/docs/reference/bigtable/2.12.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher)\n- [2.11.0](/cpp/docs/reference/bigtable/2.11.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher) \nObjects of this class pack single row mutations into bulk mutations. \nIn 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`](/cpp/docs/reference/bigtable/2.31.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher) and use [`MutationBatcher::AsyncApply()`](/cpp/docs/reference/bigtable/2.31.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher#classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher_1ab562811418701f2cbeb3240c15144de1) to apply a large stream of mutations to the same [`Table`](/cpp/docs/reference/bigtable/2.31.0/classgoogle_1_1cloud_1_1bigtable_1_1Table). Objects of this class will efficiently create batches of `SingleRowMutations` and maintain multiple batches \"in flight\".\n\nThis class also offers an easy-to-use flow control mechanism to avoid unbounded growth in its internal buffers.\n\nApplications must provide a [`CompletionQueue`](https://cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1CompletionQueue.html) to (asynchronously) execute these operations. The application is responsible of executing the [`CompletionQueue`](https://cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1CompletionQueue.html) event loop in one or more threads.\n\n###### Thread-safety\n\nInstances of this class are guaranteed to work when accessed concurrently from multiple threads.\n\nConstructors\n------------\n\n### MutationBatcher(Table, Options)\n\nFunctions\n---------\n\n### AsyncApply(CompletionQueue \\&, SingleRowMutation)\n\nAsynchronously apply mutation. \nThe 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`](/cpp/docs/reference/bigtable/2.31.0/classgoogle_1_1cloud_1_1bigtable_1_1Table#classgoogle_1_1cloud_1_1bigtable_1_1Table_1a6785e09ce4806fe450ab48934cf1a1ee).\n\nThe *completion* future will report the mutation's status once it completes.\n\nThe *admission* future should be used for flow control. In order to bound the memory usage used by [`MutationBatcher`](/cpp/docs/reference/bigtable/2.31.0/classgoogle_1_1cloud_1_1bigtable_1_1MutationBatcher), 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.\n\nOne should not make assumptions on which future will be satisfied first.\n\nThis quasi-synchronous example shows the intended use: \n\n bigtable::MutationBatcher batcher(bigtable::Table(...args...));\n bigtable::CompletionQueue cq;\n std::thread cq_runner([]() { cq.Run(); });\n\n while (HasMoreMutations()) {\n auto admission_completion = batcher.AsyncApply(cq, GenerateMutation());\n auto& admission_future = admission_completion.first;\n auto& completion_future = admission_completion.second;\n completion_future.then([](future\u003cStatus\u003e completion_status) {\n // handle mutation completion asynchronously\n });\n // Potentially slow down submission not to make buffers in\n // MutationBatcher grow unbounded.\n admission_future.get();\n }\n // Wait for all mutations to complete\n batcher.AsyncWaitForNoPendingRequests().get();\n cq.Shutdown();\n cq_runner.join();\n\n### AsyncWaitForNoPendingRequests()\n\nAsynchronously wait until all submitted mutations complete.\n\n### virtual AsyncBulkApplyImpl(Table \\&, BulkMutation \\&\\&)"]]