Skip to content

Commit ccd2b06

Browse files
authored
fix!: correct index cache config (#5381)
* fix: correct index cache config * chore: update config.md
1 parent 0db10a3 commit ccd2b06

File tree

9 files changed

+51
-70
lines changed

9 files changed

+51
-70
lines changed

config/config.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@
145145
| `region_engine.mito.index` | -- | -- | The options for index in Mito engine. |
146146
| `region_engine.mito.index.aux_path` | String | `""` | Auxiliary directory path for the index in filesystem, used to store intermediate files for<br/>creating the index and staging files for searching the index, defaults to `{data_home}/index_intermediate`.<br/>The default name for this directory is `index_intermediate` for backward compatibility.<br/><br/>This path contains two subdirectories:<br/>- `__intm`: for storing intermediate files used during creating index.<br/>- `staging`: for storing staging files used during searching index. |
147147
| `region_engine.mito.index.staging_size` | String | `2GB` | The max capacity of the staging directory. |
148+
| `region_engine.mito.index.metadata_cache_size` | String | `64MiB` | Cache size for inverted index metadata. |
149+
| `region_engine.mito.index.content_cache_size` | String | `128MiB` | Cache size for inverted index content. |
150+
| `region_engine.mito.index.content_cache_page_size` | String | `64KiB` | Page size for inverted index content cache. |
148151
| `region_engine.mito.inverted_index` | -- | -- | The options for inverted index in Mito engine. |
149152
| `region_engine.mito.inverted_index.create_on_flush` | String | `auto` | Whether to create the index on flush.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
150153
| `region_engine.mito.inverted_index.create_on_compaction` | String | `auto` | Whether to create the index on compaction.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
151154
| `region_engine.mito.inverted_index.apply_on_query` | String | `auto` | Whether to apply the index on query<br/>- `auto`: automatically (default)<br/>- `disable`: never |
152155
| `region_engine.mito.inverted_index.mem_threshold_on_create` | String | `auto` | Memory threshold for performing an external sort during index creation.<br/>- `auto`: automatically determine the threshold based on the system memory size (default)<br/>- `unlimited`: no memory limit<br/>- `[size]` e.g. `64MB`: fixed memory threshold |
153156
| `region_engine.mito.inverted_index.intermediate_path` | String | `""` | Deprecated, use `region_engine.mito.index.aux_path` instead. |
154-
| `region_engine.mito.inverted_index.metadata_cache_size` | String | `64MiB` | Cache size for inverted index metadata. |
155-
| `region_engine.mito.inverted_index.content_cache_size` | String | `128MiB` | Cache size for inverted index content. |
156-
| `region_engine.mito.inverted_index.content_cache_page_size` | String | `64KiB` | Page size for inverted index content cache. |
157157
| `region_engine.mito.fulltext_index` | -- | -- | The options for full-text index in Mito engine. |
158158
| `region_engine.mito.fulltext_index.create_on_flush` | String | `auto` | Whether to create the index on flush.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
159159
| `region_engine.mito.fulltext_index.create_on_compaction` | String | `auto` | Whether to create the index on compaction.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
@@ -481,15 +481,15 @@
481481
| `region_engine.mito.index` | -- | -- | The options for index in Mito engine. |
482482
| `region_engine.mito.index.aux_path` | String | `""` | Auxiliary directory path for the index in filesystem, used to store intermediate files for<br/>creating the index and staging files for searching the index, defaults to `{data_home}/index_intermediate`.<br/>The default name for this directory is `index_intermediate` for backward compatibility.<br/><br/>This path contains two subdirectories:<br/>- `__intm`: for storing intermediate files used during creating index.<br/>- `staging`: for storing staging files used during searching index. |
483483
| `region_engine.mito.index.staging_size` | String | `2GB` | The max capacity of the staging directory. |
484+
| `region_engine.mito.index.metadata_cache_size` | String | `64MiB` | Cache size for inverted index metadata. |
485+
| `region_engine.mito.index.content_cache_size` | String | `128MiB` | Cache size for inverted index content. |
486+
| `region_engine.mito.index.content_cache_page_size` | String | `64KiB` | Page size for inverted index content cache. |
484487
| `region_engine.mito.inverted_index` | -- | -- | The options for inverted index in Mito engine. |
485488
| `region_engine.mito.inverted_index.create_on_flush` | String | `auto` | Whether to create the index on flush.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
486489
| `region_engine.mito.inverted_index.create_on_compaction` | String | `auto` | Whether to create the index on compaction.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
487490
| `region_engine.mito.inverted_index.apply_on_query` | String | `auto` | Whether to apply the index on query<br/>- `auto`: automatically (default)<br/>- `disable`: never |
488491
| `region_engine.mito.inverted_index.mem_threshold_on_create` | String | `auto` | Memory threshold for performing an external sort during index creation.<br/>- `auto`: automatically determine the threshold based on the system memory size (default)<br/>- `unlimited`: no memory limit<br/>- `[size]` e.g. `64MB`: fixed memory threshold |
489492
| `region_engine.mito.inverted_index.intermediate_path` | String | `""` | Deprecated, use `region_engine.mito.index.aux_path` instead. |
490-
| `region_engine.mito.inverted_index.metadata_cache_size` | String | `64MiB` | Cache size for inverted index metadata. |
491-
| `region_engine.mito.inverted_index.content_cache_size` | String | `128MiB` | Cache size for inverted index content. |
492-
| `region_engine.mito.inverted_index.content_cache_page_size` | String | `64KiB` | Page size for inverted index content cache. |
493493
| `region_engine.mito.fulltext_index` | -- | -- | The options for full-text index in Mito engine. |
494494
| `region_engine.mito.fulltext_index.create_on_flush` | String | `auto` | Whether to create the index on flush.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
495495
| `region_engine.mito.fulltext_index.create_on_compaction` | String | `auto` | Whether to create the index on compaction.<br/>- `auto`: automatically (default)<br/>- `disable`: never |

config/datanode.example.toml

+9-9
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,15 @@ aux_path = ""
516516
## The max capacity of the staging directory.
517517
staging_size = "2GB"
518518

519+
## Cache size for inverted index metadata.
520+
metadata_cache_size = "64MiB"
521+
522+
## Cache size for inverted index content.
523+
content_cache_size = "128MiB"
524+
525+
## Page size for inverted index content cache.
526+
content_cache_page_size = "64KiB"
527+
519528
## The options for inverted index in Mito engine.
520529
[region_engine.mito.inverted_index]
521530

@@ -543,15 +552,6 @@ mem_threshold_on_create = "auto"
543552
## Deprecated, use `region_engine.mito.index.aux_path` instead.
544553
intermediate_path = ""
545554

546-
## Cache size for inverted index metadata.
547-
metadata_cache_size = "64MiB"
548-
549-
## Cache size for inverted index content.
550-
content_cache_size = "128MiB"
551-
552-
## Page size for inverted index content cache.
553-
content_cache_page_size = "64KiB"
554-
555555
## The options for full-text index in Mito engine.
556556
[region_engine.mito.fulltext_index]
557557

config/standalone.example.toml

+9-9
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,15 @@ aux_path = ""
565565
## The max capacity of the staging directory.
566566
staging_size = "2GB"
567567

568+
## Cache size for inverted index metadata.
569+
metadata_cache_size = "64MiB"
570+
571+
## Cache size for inverted index content.
572+
content_cache_size = "128MiB"
573+
574+
## Page size for inverted index content cache.
575+
content_cache_page_size = "64KiB"
576+
568577
## The options for inverted index in Mito engine.
569578
[region_engine.mito.inverted_index]
570579

@@ -592,15 +601,6 @@ mem_threshold_on_create = "auto"
592601
## Deprecated, use `region_engine.mito.index.aux_path` instead.
593602
intermediate_path = ""
594603

595-
## Cache size for inverted index metadata.
596-
metadata_cache_size = "64MiB"
597-
598-
## Cache size for inverted index content.
599-
content_cache_size = "128MiB"
600-
601-
## Page size for inverted index content cache.
602-
content_cache_page_size = "64KiB"
603-
604604
## The options for full-text index in Mito engine.
605605
[region_engine.mito.fulltext_index]
606606

src/mito2/src/cache.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ impl CacheStrategy {
218218

219219
/// Calls [CacheManager::index_cache()].
220220
/// It returns None if the strategy is [CacheStrategy::Compaction] or [CacheStrategy::Disabled].
221-
pub fn index_cache(&self) -> Option<&InvertedIndexCacheRef> {
221+
pub fn inverted_index_cache(&self) -> Option<&InvertedIndexCacheRef> {
222222
match self {
223-
CacheStrategy::EnableAll(cache_manager) => cache_manager.index_cache(),
223+
CacheStrategy::EnableAll(cache_manager) => cache_manager.inverted_index_cache(),
224224
CacheStrategy::Compaction(_) | CacheStrategy::Disabled => None,
225225
}
226226
}
@@ -409,7 +409,7 @@ impl CacheManager {
409409
self.write_cache.as_ref()
410410
}
411411

412-
pub(crate) fn index_cache(&self) -> Option<&InvertedIndexCacheRef> {
412+
pub(crate) fn inverted_index_cache(&self) -> Option<&InvertedIndexCacheRef> {
413413
self.index_cache.as_ref()
414414
}
415415

src/mito2/src/config.rs

+7-29
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ pub(crate) const DEFAULT_SCAN_CHANNEL_SIZE: usize = 32;
3535
const GLOBAL_WRITE_BUFFER_SIZE_FACTOR: u64 = 8;
3636
/// Use `1/SST_META_CACHE_SIZE_FACTOR` of OS memory size as SST meta cache size in default mode
3737
const SST_META_CACHE_SIZE_FACTOR: u64 = 32;
38-
/// Use `1/INDEX_CONTENT_CACHE_SIZE_FACTOR` of OS memory size for inverted index file content cache by default.
39-
const INDEX_CONTENT_CACHE_SIZE_FACTOR: u64 = 32;
4038
/// Use `1/MEM_CACHE_SIZE_FACTOR` of OS memory size as mem cache size in default mode
4139
const MEM_CACHE_SIZE_FACTOR: u64 = 16;
4240
/// Use `1/PAGE_CACHE_SIZE_FACTOR` of OS memory size as page cache size in default mode
@@ -307,6 +305,10 @@ pub struct IndexConfig {
307305

308306
/// Cache size for metadata of puffin files. Setting it to 0 to disable the cache.
309307
pub metadata_cache_size: ReadableSize,
308+
/// Cache size for inverted index content. Setting it to 0 to disable the cache.
309+
pub content_cache_size: ReadableSize,
310+
/// Page size for inverted index content.
311+
pub content_cache_page_size: ReadableSize,
310312
}
311313

312314
impl Default for IndexConfig {
@@ -316,6 +318,8 @@ impl Default for IndexConfig {
316318
staging_size: ReadableSize::gb(2),
317319
write_buffer_size: ReadableSize::mb(8),
318320
metadata_cache_size: ReadableSize::mb(64),
321+
content_cache_size: ReadableSize::mb(128),
322+
content_cache_page_size: ReadableSize::kb(64),
319323
}
320324
}
321325
}
@@ -411,45 +415,19 @@ pub struct InvertedIndexConfig {
411415
#[deprecated = "use [IndexConfig::write_buffer_size] instead"]
412416
#[serde(skip_serializing)]
413417
pub write_buffer_size: ReadableSize,
414-
415-
/// Cache size for metadata of inverted index. Setting it to 0 to disable the cache.
416-
pub metadata_cache_size: ReadableSize,
417-
/// Cache size for inverted index content. Setting it to 0 to disable the cache.
418-
pub content_cache_size: ReadableSize,
419-
/// Page size for inverted index content.
420-
pub content_cache_page_size: ReadableSize,
421-
}
422-
423-
impl InvertedIndexConfig {
424-
/// Adjusts the cache size of [InvertedIndexConfig] according to system memory size.
425-
fn adjust_cache_size(&mut self, sys_memory: ReadableSize) {
426-
let content_cache_size = cmp::min(
427-
sys_memory / INDEX_CONTENT_CACHE_SIZE_FACTOR,
428-
ReadableSize::mb(128),
429-
);
430-
self.content_cache_size = content_cache_size;
431-
}
432418
}
433419

434420
impl Default for InvertedIndexConfig {
435421
#[allow(deprecated)]
436422
fn default() -> Self {
437-
let mut index_config = Self {
423+
Self {
438424
create_on_flush: Mode::Auto,
439425
create_on_compaction: Mode::Auto,
440426
apply_on_query: Mode::Auto,
441427
mem_threshold_on_create: MemoryThreshold::Auto,
442428
write_buffer_size: ReadableSize::mb(8),
443429
intermediate_path: String::new(),
444-
metadata_cache_size: ReadableSize::mb(64),
445-
content_cache_size: ReadableSize::mb(128),
446-
content_cache_page_size: ReadableSize::kb(64),
447-
};
448-
449-
if let Some(sys_memory) = common_config::utils::get_sys_total_memory() {
450-
index_config.adjust_cache_size(sys_memory);
451430
}
452-
index_config
453431
}
454432
}
455433

src/mito2/src/read/scan_region.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl ScanRegion {
433433
Some(file_cache)
434434
}();
435435

436-
let index_cache = self.cache_strategy.index_cache().cloned();
436+
let inverted_index_cache = self.cache_strategy.inverted_index_cache().cloned();
437437

438438
let puffin_metadata_cache = self.cache_strategy.puffin_metadata_cache().cloned();
439439

@@ -452,7 +452,7 @@ impl ScanRegion {
452452
self.access_layer.puffin_manager_factory().clone(),
453453
)
454454
.with_file_cache(file_cache)
455-
.with_index_cache(index_cache)
455+
.with_inverted_index_cache(inverted_index_cache)
456456
.with_puffin_metadata_cache(puffin_metadata_cache)
457457
.build(&self.request.filters)
458458
.inspect_err(|err| warn!(err; "Failed to build invereted index applier"))
@@ -473,7 +473,7 @@ impl ScanRegion {
473473
Some(file_cache)
474474
}();
475475

476-
let index_cache = self.cache_strategy.bloom_filter_index_cache().cloned();
476+
let bloom_filter_index_cache = self.cache_strategy.bloom_filter_index_cache().cloned();
477477

478478
let puffin_metadata_cache = self.cache_strategy.puffin_metadata_cache().cloned();
479479

@@ -484,7 +484,7 @@ impl ScanRegion {
484484
self.access_layer.puffin_manager_factory().clone(),
485485
)
486486
.with_file_cache(file_cache)
487-
.with_bloom_filter_index_cache(index_cache)
487+
.with_bloom_filter_index_cache(bloom_filter_index_cache)
488488
.with_puffin_metadata_cache(puffin_metadata_cache)
489489
.build(&self.request.filters)
490490
.inspect_err(|err| warn!(err; "Failed to build bloom filter index applier"))

src/mito2/src/sst/index/inverted_index/applier/builder.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) struct InvertedIndexApplierBuilder<'a> {
6565
puffin_manager_factory: PuffinManagerFactory,
6666

6767
/// Cache for inverted index.
68-
index_cache: Option<InvertedIndexCacheRef>,
68+
inverted_index_cache: Option<InvertedIndexCacheRef>,
6969

7070
/// Cache for puffin metadata.
7171
puffin_metadata_cache: Option<PuffinMetadataCacheRef>,
@@ -88,7 +88,7 @@ impl<'a> InvertedIndexApplierBuilder<'a> {
8888
output: HashMap::default(),
8989
puffin_manager_factory,
9090
file_cache: None,
91-
index_cache: None,
91+
inverted_index_cache: None,
9292
puffin_metadata_cache: None,
9393
}
9494
}
@@ -108,9 +108,12 @@ impl<'a> InvertedIndexApplierBuilder<'a> {
108108
self
109109
}
110110

111-
/// Sets the index cache.
112-
pub fn with_index_cache(mut self, index_cache: Option<InvertedIndexCacheRef>) -> Self {
113-
self.index_cache = index_cache;
111+
/// Sets the inverted index cache.
112+
pub fn with_inverted_index_cache(
113+
mut self,
114+
inverted_index_cache: Option<InvertedIndexCacheRef>,
115+
) -> Self {
116+
self.inverted_index_cache = inverted_index_cache;
114117
self
115118
}
116119

@@ -142,7 +145,7 @@ impl<'a> InvertedIndexApplierBuilder<'a> {
142145
)
143146
.with_file_cache(self.file_cache)
144147
.with_puffin_metadata_cache(self.puffin_metadata_cache)
145-
.with_index_cache(self.index_cache),
148+
.with_index_cache(self.inverted_index_cache),
146149
))
147150
}
148151

src/mito2/src/sst/index/inverted_index/creator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ mod tests {
456456
indexed_column_ids.clone(),
457457
factory.clone(),
458458
)
459-
.with_index_cache(Some(cache))
459+
.with_inverted_index_cache(Some(cache))
460460
.with_puffin_metadata_cache(Some(puffin_metadata_cache))
461461
.build(&[expr])
462462
.unwrap()

src/mito2/src/worker.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ impl WorkerGroup {
167167
.vector_cache_size(config.vector_cache_size.as_bytes())
168168
.page_cache_size(config.page_cache_size.as_bytes())
169169
.selector_result_cache_size(config.selector_result_cache_size.as_bytes())
170-
.index_metadata_size(config.inverted_index.metadata_cache_size.as_bytes())
171-
.index_content_size(config.inverted_index.content_cache_size.as_bytes())
172-
.index_content_page_size(config.inverted_index.content_cache_page_size.as_bytes())
170+
.index_metadata_size(config.index.metadata_cache_size.as_bytes())
171+
.index_content_size(config.index.content_cache_size.as_bytes())
172+
.index_content_page_size(config.index.content_cache_page_size.as_bytes())
173173
.puffin_metadata_size(config.index.metadata_cache_size.as_bytes())
174174
.write_cache(write_cache)
175175
.build(),

0 commit comments

Comments
 (0)