Skip to content

Commit 46c9e78

Browse files
authored
cleanup(bigtable): strictly enforce bigtable limits in mutation batcher (#7036)
1 parent 0a67d94 commit 46c9e78

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

google/cloud/bigtable/mutation_batcher.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ inline namespace BIGTABLE_CLIENT_NS {
2525
// Cloud Bigtable doesn't accept more than this in a single request.
2626
auto constexpr kBigtableMutationLimit = 100000;
2727
// Maximum mutations that can be outstanding in the Cloud Bigtable front end.
28+
// NOTE: this is a system-wide limit, but it is only enforced per process.
2829
auto constexpr kBigtableOutstandingMutationLimit = 300000;
2930
// Let's make the default slightly smaller, so that overheads or
3031
// miscalculations don't tip us over.
@@ -41,6 +42,20 @@ MutationBatcher::Options::Options()
4142
max_outstanding_size(kDefaultMaxOutstandingSize),
4243
max_outstanding_mutations(kBigtableOutstandingMutationLimit) {}
4344

45+
MutationBatcher::Options& MutationBatcher::Options::SetMaxMutationsPerBatch(
46+
size_t max_mutations_per_batch_arg) {
47+
max_mutations_per_batch = std::min<std::size_t>(max_mutations_per_batch_arg,
48+
kBigtableMutationLimit);
49+
return *this;
50+
}
51+
52+
MutationBatcher::Options& MutationBatcher::Options::SetMaxOutstandingMutations(
53+
size_t max_outstanding_mutations_arg) {
54+
max_outstanding_mutations = std::min<std::size_t>(
55+
max_outstanding_mutations_arg, kBigtableOutstandingMutationLimit);
56+
return *this;
57+
}
58+
4459
std::pair<future<void>, future<Status>> MutationBatcher::AsyncApply(
4560
CompletionQueue& cq, SingleRowMutation mut) {
4661
AdmissionPromise admission_promise;

google/cloud/bigtable/mutation_batcher.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ class MutationBatcher {
6161
Options();
6262

6363
/// A single RPC will not have more mutations than this.
64-
Options& SetMaxMutationsPerBatch(size_t max_mutations_per_batch_arg) {
65-
max_mutations_per_batch = max_mutations_per_batch_arg;
66-
return *this;
67-
}
64+
Options& SetMaxMutationsPerBatch(size_t max_mutations_per_batch_arg);
6865

6966
/// Sum of mutations' sizes in a single RPC will not be larger than this.
7067
Options& SetMaxSizePerBatch(size_t max_size_per_batch_arg) {
@@ -85,10 +82,7 @@ class MutationBatcher {
8582
}
8683

8784
/// MutationBatcher will at most admit this many mutations.
88-
Options& SetMaxOutstandingMutations(size_t max_outstanding_mutations_arg) {
89-
max_outstanding_mutations = max_outstanding_mutations_arg;
90-
return *this;
91-
}
85+
Options& SetMaxOutstandingMutations(size_t max_outstanding_mutations_arg);
9286

9387
std::size_t max_mutations_per_batch;
9488
std::size_t max_size_per_batch;

google/cloud/bigtable/mutation_batcher_test.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,23 @@ TEST(OptionsTest, Trivial) {
254254
.SetMaxMutationsPerBatch(1)
255255
.SetMaxSizePerBatch(2)
256256
.SetMaxBatches(3)
257-
.SetMaxOutstandingSize(4);
257+
.SetMaxOutstandingSize(4)
258+
.SetMaxOutstandingMutations(5);
258259
ASSERT_EQ(1, opt.max_mutations_per_batch);
259260
ASSERT_EQ(2, opt.max_size_per_batch);
260261
ASSERT_EQ(3, opt.max_batches);
261262
ASSERT_EQ(4, opt.max_outstanding_size);
263+
ASSERT_EQ(5, opt.max_outstanding_mutations);
264+
}
265+
266+
TEST(OptionsTest, StrictLimits) {
267+
MutationBatcher::Options opt = MutationBatcher::Options()
268+
.SetMaxMutationsPerBatch(200000)
269+
.SetMaxOutstandingMutations(400000);
270+
// See `kBigtableMutationLimit`
271+
ASSERT_EQ(100000, opt.max_mutations_per_batch);
272+
// See `kBigtableOutstandingMutationLimit`
273+
ASSERT_EQ(300000, opt.max_outstanding_mutations);
262274
}
263275

264276
TEST_F(MutationBatcherTest, TrivialTest) {

0 commit comments

Comments
 (0)