Skip to content

Commit 494a8a0

Browse files
committed
MB-65719: Enforce that MagmaKVStoreConfig::store is always valid
The member is a pointer to the owning MagmaKVStore instance, thus by logic always not-null. A T& would be the proper type for encoding that semantic. Problem is, the code that constructs the various KVStore/KVStoreConfig implementations makes the conversion to T& non-trivial, so I'm avoiding that refactor at this stage. Change-Id: Id58e2b3e3f0a7db4e7098b15cbe840e3c325a7f6 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/226065 Reviewed-by: Mohammad Zaeem <mohammad.zaeem@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent bdbb77a commit 494a8a0

File tree

1 file changed

+27
-42
lines changed

1 file changed

+27
-42
lines changed

engines/ep/src/kvstore/magma-kvstore/magma-kvstore_config.cc

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,7 @@ MagmaKVStoreConfig::MagmaKVStoreConfig(Configuration& config,
217217
fmt::format("{}-{}", config.getCouchBucket(), config.getUuid()));
218218

219219
magmaCfg.OnBackupCallback = [this](auto vbid, auto& snapshot) {
220-
if (!store) {
221-
throw std::logic_error("OnBackupCallback: MagmaKVStore not set!");
222-
}
220+
Expects(store);
223221
return store->onContinuousBackupCallback(Vbid(vbid), snapshot);
224222
};
225223

@@ -266,17 +264,15 @@ void MagmaKVStoreConfig::setStore(MagmaKVStore* store) {
266264
}
267265

268266
void MagmaKVStoreConfig::setFusionMigrationRateLimit(size_t value) {
267+
Expects(store);
269268
fusionMigrationRateLimit.store(value);
270-
if (store) {
271-
store->setMagmaFusionMigrationRateLimit(value);
272-
}
269+
store->setMagmaFusionMigrationRateLimit(value);
273270
}
274271

275272
void MagmaKVStoreConfig::setFusionSyncRateLimit(size_t value) {
273+
Expects(store);
276274
fusionSyncRateLimit.store(value);
277-
if (store) {
278-
store->setMagmaFusionSyncRateLimit(value);
279-
}
275+
store->setMagmaFusionSyncRateLimit(value);
280276
}
281277

282278
void MagmaKVStoreConfig::setFusionLogstoreURI(std::string_view uri) {
@@ -298,25 +294,22 @@ void MagmaKVStoreConfig::setFusionUploadInterval(std::chrono::seconds value) {
298294
}
299295

300296
void MagmaKVStoreConfig::setMagmaFragmentationPercentage(size_t value) {
297+
Expects(store);
301298
magmaFragmentationPercentage.store(value);
302-
if (store) {
303-
store->setMagmaFragmentationPercentage(value);
304-
}
299+
store->setMagmaFragmentationPercentage(value);
305300
}
306301

307302
void MagmaKVStoreConfig::setStorageThreads(
308303
ThreadPoolConfig::StorageThreadCount value) {
304+
Expects(store);
309305
storageThreads.store(value);
310-
if (store) {
311-
store->calculateAndSetMagmaThreads();
312-
}
306+
store->calculateAndSetMagmaThreads();
313307
}
314308

315309
void MagmaKVStoreConfig::setMagmaFlusherThreadPercentage(size_t value) {
310+
Expects(store);
316311
magmaFlusherPercentage.store(value);
317-
if (store) {
318-
store->calculateAndSetMagmaThreads();
319-
}
312+
store->calculateAndSetMagmaThreads();
320313
}
321314

322315
void MagmaKVStoreConfig::setBucketQuota(size_t value) {
@@ -326,60 +319,52 @@ void MagmaKVStoreConfig::setBucketQuota(size_t value) {
326319
}
327320

328321
void MagmaKVStoreConfig::setMagmaMemQuotaRatio(float value) {
322+
Expects(store);
329323
magmaMemQuotaRatio.store(value);
330-
if (store) {
331-
store->setMaxDataSize(bucketQuota);
332-
}
324+
store->setMaxDataSize(bucketQuota);
333325
}
334326

335327
void MagmaKVStoreConfig::setMagmaEnableBlockCache(bool enable) {
328+
Expects(store);
336329
magmaEnableBlockCache.store(enable);
337-
if (store) {
338-
store->setMagmaEnableBlockCache(enable);
339-
}
330+
store->setMagmaEnableBlockCache(enable);
340331
}
341332

342333
void MagmaKVStoreConfig::setMagmaSeqTreeDataBlockSize(size_t value) {
334+
Expects(store);
343335
magmaSeqTreeDataBlockSize.store(value);
344-
if (store) {
345-
store->setMagmaSeqTreeDataBlockSize(value);
346-
}
336+
store->setMagmaSeqTreeDataBlockSize(value);
347337
}
348338

349339
void MagmaKVStoreConfig::setMagmaMinValueBlockSizeThreshold(size_t value) {
340+
Expects(store);
350341
magmaMinValueBlockSizeThreshold.store(value);
351-
if (store) {
352-
store->setMagmaMinValueBlockSizeThreshold(value);
353-
}
342+
store->setMagmaMinValueBlockSizeThreshold(value);
354343
}
355344

356345
void MagmaKVStoreConfig::setMagmaSeqTreeIndexBlockSize(size_t value) {
346+
Expects(store);
357347
magmaSeqTreeIndexBlockSize.store(value);
358-
if (store) {
359-
store->setMagmaSeqTreeIndexBlockSize(value);
360-
}
348+
store->setMagmaSeqTreeIndexBlockSize(value);
361349
}
362350

363351
void MagmaKVStoreConfig::setMagmaKeyTreeDataBlockSize(size_t value) {
352+
Expects(store);
364353
magmaKeyTreeDataBlockSize.store(value);
365-
if (store) {
366-
store->setMagmaKeyTreeDataBlockSize(value);
367-
}
354+
store->setMagmaKeyTreeDataBlockSize(value);
368355
}
369356

370357
void MagmaKVStoreConfig::setMagmaKeyTreeIndexBlockSize(size_t value) {
358+
Expects(store);
371359
magmaKeyTreeIndexBlockSize.store(value);
372-
if (store) {
373-
store->setMagmaKeyTreeIndexBlockSize(value);
374-
}
360+
store->setMagmaKeyTreeIndexBlockSize(value);
375361
}
376362

377363
void MagmaKVStoreConfig::setContinousBackupInterval(
378364
std::chrono::seconds interval) {
365+
Expects(store);
379366
continuousBackupInterval = interval;
380-
if (store) {
381-
store->setContinuousBackupInterval(interval);
382-
}
367+
store->setContinuousBackupInterval(interval);
383368
}
384369

385370
void MagmaKVStoreConfig::setMakeDirectoryFn(magma::DirectoryConstructor fn) {

0 commit comments

Comments
 (0)