Skip to content

Commit e1e9664

Browse files
RachelintLeslieKid
authored andcommitted
fix: support to compat the old layered memtable options (apache#1568)
## Rationale We introduce the explicit flag to control should we enable layered memtable, but it has some compatibility problem when upgrading from old version. This pr add an option to support compating the old layered memtable on/off control method. ## Detailed Changes Add an option to support compating the old layered memtable on/off control method. ## Test Plan Manually.
1 parent 88c6b67 commit e1e9664

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

src/analytic_engine/src/instance/open.rs

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl Instance {
154154
preflush_write_buffer_size_ratio: ctx.config.preflush_write_buffer_size_ratio,
155155
manifest_snapshot_every_n_updates: ctx.config.manifest.snapshot_every_n_updates,
156156
enable_primary_key_sampling: ctx.config.enable_primary_key_sampling,
157+
try_compat_old_layered_memtable_opts: ctx.config.try_compat_old_layered_memtable_opts,
157158
metrics_opt: ctx.config.metrics.clone(),
158159
});
159160
let manifest = ManifestImpl::open(

src/analytic_engine/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ pub struct Config {
6969
/// Default options for table
7070
pub table_opts: TableOptions,
7171

72+
/// Should we try to compat the `LayeredMemtableOptions` in `TableOptions`
73+
/// The old one use if `mutable_segment_switch_threshold` > 0 to control
74+
/// the on/off of layered memtable(`0`:off, `>0`:on).
75+
/// The new one use a explicit flag `enable` to do that.
76+
pub try_compat_old_layered_memtable_opts: bool,
77+
7278
pub compaction: SchedulerConfig,
7379

7480
/// Offload the compaction task to remote nodes or not.
@@ -182,6 +188,7 @@ impl Default for Config {
182188
replay_batch_size: 500,
183189
max_replay_tables_per_batch: 64,
184190
table_opts: TableOptions::default(),
191+
try_compat_old_layered_memtable_opts: false,
185192
compaction: SchedulerConfig::default(),
186193
compaction_offload: false,
187194
sst_meta_cache_cap: Some(1000),

src/analytic_engine/src/manifest/details.rs

+1
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ mod tests {
776776
manifest_snapshot_every_n_updates: NonZeroUsize::new(usize::MAX).unwrap(),
777777
metrics_opt: MetricsOptions::default(),
778778
enable_primary_key_sampling: false,
779+
try_compat_old_layered_memtable_opts: false,
779780
},
780781
&purger,
781782
mem_size_options,

src/analytic_engine/src/table/data.rs

+29-9
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ use crate::{
6868
sst_util,
6969
version::{MemTableForWrite, MemTableState, SamplingMemTable, TableVersion},
7070
},
71+
table_options::UpdateMode,
7172
MetricsOptions, TableOptions,
7273
};
7374

@@ -155,6 +156,7 @@ pub struct TableConfig {
155156
pub manifest_snapshot_every_n_updates: NonZeroUsize,
156157
pub metrics_opt: MetricsOptions,
157158
pub enable_primary_key_sampling: bool,
159+
pub try_compat_old_layered_memtable_opts: bool,
158160
}
159161

160162
#[derive(Debug, Clone)]
@@ -314,11 +316,13 @@ impl TableData {
314316
name,
315317
schema,
316318
} = desc;
319+
317320
let TableConfig {
318321
preflush_write_buffer_size_ratio,
319322
manifest_snapshot_every_n_updates,
320323
metrics_opt,
321324
enable_primary_key_sampling,
325+
..
322326
} = config;
323327

324328
let memtable_factory: MemTableFactoryRef = match opts.memtable_type {
@@ -406,6 +410,7 @@ impl TableData {
406410
manifest_snapshot_every_n_updates,
407411
metrics_opt,
408412
enable_primary_key_sampling,
413+
try_compat_old_layered_memtable_opts,
409414
} = config;
410415

411416
let memtable_factory: MemTableFactoryRef = match add_meta.opts.memtable_type {
@@ -421,17 +426,31 @@ impl TableData {
421426
.mutable_segment_switch_threshold
422427
.0 as usize;
423428

424-
ensure!(
425-
mutable_segment_switch_threshold > 0,
426-
InvalidTableOpts {
429+
if mutable_segment_switch_threshold > 0 {
430+
ensure!(
431+
add_meta.opts.update_mode != UpdateMode::Overwrite,
432+
InvalidTableOpts {
433+
msg: "layered memtable is enabled but update mode is Overwrite",
434+
}
435+
);
436+
437+
Arc::new(LayeredMemtableFactory::new(
438+
memtable_factory,
439+
mutable_segment_switch_threshold,
440+
)) as _
441+
} else if try_compat_old_layered_memtable_opts {
442+
// Maybe some old layered memtable opts controlling the on/off of this feature
443+
// by checking `mutable_segment_switch_threshold`(`0`:disable, `>0`:enable)
444+
// were persisted.
445+
// If `try_compat_old_layered_memtable_opts` is true, we will try to follow the
446+
// old behavior.
447+
memtable_factory as _
448+
} else {
449+
return InvalidTableOpts {
427450
msg: "layered memtable is enabled but mutable_switch_threshold is 0",
428451
}
429-
);
430-
431-
Arc::new(LayeredMemtableFactory::new(
432-
memtable_factory,
433-
mutable_segment_switch_threshold,
434-
)) as _
452+
.fail();
453+
}
435454
} else {
436455
memtable_factory as _
437456
};
@@ -1028,6 +1047,7 @@ pub mod tests {
10281047
manifest_snapshot_every_n_updates: self.manifest_snapshot_every_n_updates,
10291048
metrics_opt: MetricsOptions::default(),
10301049
enable_primary_key_sampling: false,
1050+
try_compat_old_layered_memtable_opts: false,
10311051
},
10321052
&purger,
10331053
mem_size_options,

src/analytic_engine/src/table_meta_set_impl.rs

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub(crate) struct TableMetaSetImpl {
5454
pub(crate) preflush_write_buffer_size_ratio: f32,
5555
pub(crate) manifest_snapshot_every_n_updates: NonZeroUsize,
5656
pub(crate) enable_primary_key_sampling: bool,
57+
pub(crate) try_compat_old_layered_memtable_opts: bool,
5758
pub(crate) metrics_opt: MetricsOptions,
5859
}
5960

@@ -140,6 +141,8 @@ impl TableMetaSetImpl {
140141
.manifest_snapshot_every_n_updates,
141142
metrics_opt: self.metrics_opt.clone(),
142143
enable_primary_key_sampling: self.enable_primary_key_sampling,
144+
try_compat_old_layered_memtable_opts: self
145+
.try_compat_old_layered_memtable_opts,
143146
},
144147
&self.file_purger,
145148
mem_size_options,
@@ -271,6 +274,7 @@ impl TableMetaSetImpl {
271274
manifest_snapshot_every_n_updates: self.manifest_snapshot_every_n_updates,
272275
metrics_opt: self.metrics_opt.clone(),
273276
enable_primary_key_sampling: self.enable_primary_key_sampling,
277+
try_compat_old_layered_memtable_opts: self.try_compat_old_layered_memtable_opts,
274278
},
275279
mem_size_options,
276280
allocator,

0 commit comments

Comments
 (0)