Skip to content

Commit c7f2c00

Browse files
committed
MB-67552: Recompute checkpoint's max size at checkpoint quota change
From MB-48038 where we introduced checkpoint_max_size: That is the maximum size (in bytes) for a single checkpoint. '0' triggers EP auto-setup, where the value is determined based on other system parameters (eg, num of vbuckets, checkpoint quota, max num of checkpoints per vbucket, etc..) for optimal balance and checkpoint memory releasing capabilities. Change-Id: Id31106f372bd30ba52bf637e2c78b4872eb78b93 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/230483 Tested-by: Build Bot <[email protected]> Reviewed-by: Vesko Karaganev <[email protected]>
1 parent 75bcafa commit c7f2c00

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

engines/ep/src/checkpoint_config.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,5 @@ void CheckpointConfig::setMaxCheckpoints(size_t value) {
4848
}
4949

5050
void CheckpointConfig::setCheckpointMaxSize(size_t value) {
51-
Expects(value >= 1);
5251
checkpointMaxSize = value;
5352
}

engines/ep/src/kv_bucket.cc

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,11 @@ cb::engine_errc KVBucket::setCheckpointMemoryRatio(float ratio) {
30783078
return cb::engine_errc::invalid_arguments;
30793079
}
30803080
checkpointMemoryRatio = ratio;
3081+
3082+
if (getConfiguration().getCheckpointMaxSize() == 0) {
3083+
autoConfigCheckpointMaxSize();
3084+
}
3085+
30813086
return cb::engine_errc::success;
30823087
}
30833088

@@ -3161,25 +3166,19 @@ cb::engine_errc KVBucket::autoConfigCheckpointMaxSize() {
31613166
const auto numCheckpointsPerVB = config.getMaxCheckpoints();
31623167

31633168
const auto checkpointQuota = maxSize * ckptMemRatio;
3164-
Expects(checkpointQuota > 0);
3169+
Expects(checkpointQuota >= 0);
31653170

31663171
const size_t newComputedCheckpointMaxSize =
31673172
checkpointQuota / numVBuckets / numCheckpointsPerVB;
3168-
if (newComputedCheckpointMaxSize < 1) {
3169-
throw std::invalid_argument(
3170-
fmt::format("KVBucket::autoConfigCheckpointMaxSize: "
3171-
"newComputedCheckpointMaxSize:{} is < 1. "
3172-
"max_size:{}, "
3173-
"checkpoint mem ratio:{}, "
3174-
"checkpoint quota:{}, "
3175-
"numVBuckets:{}, "
3176-
"numCheckpointsPerVB:{}",
3177-
newComputedCheckpointMaxSize,
3178-
maxSize,
3179-
ckptMemRatio,
3180-
checkpointQuota,
3181-
numVBuckets,
3182-
numCheckpointsPerVB));
3173+
if (newComputedCheckpointMaxSize == 0) {
3174+
EP_LOG_WARN_CTX(
3175+
"KVBucket::autoConfigCheckpointMaxSize: "
3176+
"newComputedCheckpointMaxSize is 0",
3177+
{"max_size", maxSize},
3178+
{"checkpoint_memory_ratio", ckptMemRatio},
3179+
{"checkpoint_quota", checkpointQuota},
3180+
{"num_vbuckets", numVBuckets},
3181+
{"num_checkpoints_per_vb", numCheckpointsPerVB});
31833182
}
31843183

31853184
const auto flushMaxBytes = config.getFlushBatchMaxBytes();

engines/ep/tests/module_tests/checkpoint_test.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,24 @@ TEST_F(SingleThreadedCheckpointTest, CheckpointMaxSize_CapAtFlushMaxBytes) {
13231323
EXPECT_EQ(2_GiB, ckptConfig.getCheckpointMaxSize());
13241324
}
13251325

1326+
TEST_F(SingleThreadedCheckpointTest,
1327+
CheckpointMaxSize_RecomputeAtCheckpointQuotaChange) {
1328+
auto& config = engine->getConfiguration();
1329+
config.setMaxSize(1_GiB);
1330+
config.setCheckpointMemoryRatio(1.0f);
1331+
config.setMaxCheckpoints(2);
1332+
1333+
setVBucketState(vbid, vbucket_state_active);
1334+
auto vb = store->getVBuckets().getBucket(vbid);
1335+
auto& manager = *vb->checkpointManager;
1336+
1337+
const auto& ckptConfig = manager.getCheckpointConfig();
1338+
EXPECT_EQ(512_MiB, ckptConfig.getCheckpointMaxSize());
1339+
1340+
config.setCheckpointMemoryRatio(0.5f);
1341+
EXPECT_EQ(256_MiB, ckptConfig.getCheckpointMaxSize());
1342+
}
1343+
13261344
TEST_F(SingleThreadedCheckpointTest, MemUsageCheckpointCreation) {
13271345
auto& config = engine->getConfiguration();
13281346
config.setMaxSize(100_MiB);

0 commit comments

Comments
 (0)