@@ -321,6 +321,90 @@ class BigHashConfig {
321
321
uint64_t smallItemMaxSize_{};
322
322
};
323
323
324
+ /* *
325
+ * KangarooConfig provides APIs for users to configure Kangaroo engine, which is
326
+ * one part of NavyConfig.
327
+ *
328
+ * By this class, users can:
329
+ * - enable Kangaroo by setting sizePct > 0
330
+ * - set maximum item size
331
+ * - set bucket size
332
+ * - set bloom filter size (0 to disable bloom filter)
333
+ * - set log percent and number of partitions
334
+ * - get the values of all the above parameters
335
+ */
336
+ class KangarooConfig {
337
+ public:
338
+ // Set Kangaroo device percentage and maximum item size(in bytes) to enable
339
+ // Kangaroo engine. Default value of sizePct and smallItemMaxSize is 0,
340
+ // meaning Kangaroo is not enabled.
341
+ // @throw std::invalid_argument if sizePct is not in the range of
342
+ // [0, 100].
343
+ KangarooConfig& setSizePctAndMaxItemSize (unsigned int sizePct,
344
+ uint64_t smallItemMaxSize);
345
+
346
+ // Set the bucket size in bytes for Kangaroo engine.
347
+ // Default value is 4096.
348
+ KangarooConfig& setBucketSize (uint32_t bucketSize) noexcept {
349
+ bucketSize_ = bucketSize;
350
+ return *this ;
351
+ }
352
+
353
+ // Set bloom filter size per bucket in bytes for Kangaroo engine.
354
+ // 0 means bloom filter will not be applied. Default value is 8.
355
+ KangarooConfig& setBucketBfSize (uint64_t bucketBfSize) noexcept {
356
+ bucketBfSize_ = bucketBfSize;
357
+ return *this ;
358
+ }
359
+
360
+ // Set bloom filter size per bucket in bytes for Kangaroo engine.
361
+ // 0 means bloom filter will not be applied. Default value is 8.
362
+ KangarooConfig& setLog (unsigned int sizePct,
363
+ uint64_t physicalPartitions,
364
+ uint64_t indexPerPhysicalParitions,
365
+ uint32_t threshold);
366
+
367
+ bool isBloomFilterEnabled () const { return bucketBfSize_ > 0 ; }
368
+
369
+ unsigned int getSizePct () const { return sizePct_; }
370
+
371
+ uint32_t getBucketSize () const { return bucketSize_; }
372
+
373
+ uint64_t getBucketBfSize () const { return bucketBfSize_; }
374
+
375
+ uint64_t getSmallItemMaxSize () const { return smallItemMaxSize_; }
376
+
377
+ unsigned int getLogSizePct () const { return logSizePct_; }
378
+
379
+ uint64_t getPhysicalPartitions () const { return physicalPartitions_; }
380
+
381
+ uint64_t getIndexPerPhysicalPartitions () const { return indexPerPhysicalPartitions_; }
382
+
383
+ uint32_t getLogThreshold () const { return threshold_; }
384
+
385
+ private:
386
+ // Percentage of how much of the device out of all is given to Kangaroo
387
+ // engine in Navy, e.g. 50.
388
+ unsigned int sizePct_{0 };
389
+ // Navy Kangaroo engine's bucket size (must be multiple of the minimum
390
+ // device io block size).
391
+ // This size determines how big each bucket is and what is the physical
392
+ // write granularity onto the device.
393
+ uint32_t bucketSize_{4096 };
394
+ // The bloom filter size per bucket in bytes for Navy Kangaroo engine
395
+ uint64_t bucketBfSize_{8 };
396
+ // The maximum item size to put into Navy Kangaroo engine.
397
+ uint64_t smallItemMaxSize_{};
398
+ // Percent of Kangaroo to dedicate to KangarooLog
399
+ unsigned int logSizePct_{0 };
400
+ // Number of physical partitions of KangarooLog
401
+ uint64_t physicalPartitions_{1 };
402
+ // Number of index partitions of KangarooLog
403
+ uint64_t indexPerPhysicalPartitions_{1 };
404
+ // Threshold for moving items from KangarooLog to sets
405
+ uint32_t threshold_{1 };
406
+ };
407
+
324
408
/* *
325
409
* NavyConfig provides APIs for users to set up Navy related settings for
326
410
* NvmCache.
@@ -341,6 +425,7 @@ class NavyConfig {
341
425
bool usesSimpleFile () const noexcept { return !fileName_.empty (); }
342
426
bool usesRaidFiles () const noexcept { return raidPaths_.size () > 0 ; }
343
427
bool isBigHashEnabled () const { return bigHashConfig_.getSizePct () > 0 ; }
428
+ bool isKangarooEnabled () const { return kangarooConfig_.getSizePct () > 0 ; }
344
429
std::map<std::string, std::string> serialize () const ;
345
430
346
431
// Getters:
@@ -371,15 +456,21 @@ class NavyConfig {
371
456
// Returns the threshold of classifying an item as small item or large item
372
457
// for Navy engine.
373
458
uint64_t getSmallItemThreshold () const {
374
- if (!isBigHashEnabled ()) {
459
+ if (isBigHashEnabled ()) {
460
+ return bigHashConfig_.getSmallItemMaxSize ();
461
+ } else if (isKangarooEnabled ()) {
462
+ return kangarooConfig_.getSmallItemMaxSize ();
463
+ } else {
375
464
return 0 ;
376
465
}
377
- return bigHashConfig_.getSmallItemMaxSize ();
378
466
}
379
467
380
468
// Return a const BlockCacheConfig to read values of its parameters.
381
469
const BigHashConfig& bigHash () const { return bigHashConfig_; }
382
470
471
+ // Return a const KangarooConfig to read values of its parameters.
472
+ const KangarooConfig& kangaroo () const { return kangarooConfig_; }
473
+
383
474
// Return a const BlockCacheConfig to read values of its parameters.
384
475
const BlockCacheConfig& blockCache () const { return blockCacheConfig_; }
385
476
@@ -506,6 +597,21 @@ class NavyConfig {
506
597
uint64_t bigHashSmallItemMaxSize);
507
598
// Return BigHashConfig for configuration.
508
599
BigHashConfig& bigHash () noexcept { return bigHashConfig_; }
600
+
601
+ // ============ Kangaroo settings =============
602
+ // (Deprecated) Set the parameters for Kangaroo.
603
+ // @throw std::invalid_argument if kangarooSizePct is not in the range of
604
+ // 0~100.
605
+ void setKangaroo (unsigned int kangarooSizePct,
606
+ uint32_t kangarooBucketSize,
607
+ uint64_t kangarooBucketBfSize,
608
+ uint64_t kangarooSmallItemMaxSize,
609
+ uint64_t kangarooLogSizePct,
610
+ uint64_t kangarooLogThreshold,
611
+ uint64_t kangarooLogPhysicalPartitions,
612
+ uint32_t kangarooLogIndexPerPhysicalPartitions);
613
+ // Return KangarooConfig for configuration.
614
+ KangarooConfig& kangaroo () noexcept { return kangarooConfig_; }
509
615
510
616
// ============ Job scheduler settings =============
511
617
void setReaderAndWriterThreads (unsigned int readerThreads,
@@ -556,6 +662,9 @@ class NavyConfig {
556
662
557
663
// ============ BigHash settings =============
558
664
BigHashConfig bigHashConfig_{};
665
+
666
+ // ============ Kangaroo settings =============
667
+ KangarooConfig kangarooConfig_{};
559
668
560
669
// ============ Job scheduler settings =============
561
670
// Number of asynchronous worker thread for read operation.
0 commit comments