Skip to content

Commit 52ac2e1

Browse files
authored
Fix panic when changing merge policy configs (#5817)
* Rename references to outdated variable name * Filter splits considered mature by the current merge policy
1 parent 2dfb4b4 commit 52ac2e1

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

quickwit/quickwit-indexing/src/actors/merge_planner.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::time::Instant;
1818

1919
use async_trait::async_trait;
2020
use quickwit_actors::{Actor, ActorContext, ActorExitStatus, Handler, Mailbox, QueueCapacity};
21-
use quickwit_metastore::SplitMetadata;
21+
use quickwit_metastore::{SplitMaturity, SplitMetadata};
2222
use quickwit_proto::indexing::MergePipelineId;
2323
use quickwit_proto::types::DocMappingUid;
2424
use serde::Serialize;
@@ -273,6 +273,14 @@ impl MergePlanner {
273273
// - do not belong to the current timeline.
274274
fn record_splits_if_necessary(&mut self, split_metadatas: Vec<SplitMetadata>) {
275275
for new_split in split_metadatas {
276+
if let SplitMaturity::Mature = self
277+
.merge_policy
278+
.split_maturity(new_split.num_docs, new_split.num_merge_ops)
279+
{
280+
// This can happen if the merge policy changed (e.g, decreased
281+
// split_num_docs_target).
282+
continue;
283+
}
276284
if new_split.is_mature(OffsetDateTime::now_utc()) {
277285
continue;
278286
}

quickwit/quickwit-indexing/src/merge_policy/const_write_amplification.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ mod tests {
286286
.into_iter()
287287
.next()
288288
.unwrap();
289-
// Split under max_merge_docs, num_merge_ops < max_merge_ops and created before now() -
290-
// maturation_period is not mature.
289+
// Split under split_num_docs_target, num_merge_ops < max_merge_ops and created before now()
290+
// - maturation_period is not mature.
291291
assert_eq!(
292292
merge_policy.split_maturity(split.num_docs, split.num_merge_ops),
293293
SplitMaturity::Immature {
294294
maturation_period: Duration::from_secs(3600)
295295
}
296296
);
297-
// Split with docs > max_merge_docs is mature.
297+
// Split with docs > split_num_docs_target is mature.
298298
assert_eq!(
299299
merge_policy
300300
.split_maturity(merge_policy.split_num_docs_target + 1, split.num_merge_ops),

quickwit/quickwit-indexing/src/merge_policy/stable_log_merge_policy.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ use crate::merge_policy::{MergeOperation, MergePolicy, splits_short_debug};
4747
/// `l_0 = 3 x self.min_level_num_docs`.
4848
///
4949
/// Assuming level N-1 has been built, level N is given by
50-
/// `l_N = min(num_docs(split_l_{N_1})` * 3, self.max_merge_docs)`.
51-
/// We stop once l_N = self.max_merge_docs is reached.
50+
/// `l_N = min(num_docs(split_l_{N_1})` * 3, self.split_num_docs_target)`.
51+
/// We stop once l_N = self.split_num_docs_target is reached.
5252
///
5353
/// As a result, each level interval is at least 3 times larger than the previous one,
5454
/// forming a logscale over the number of documents.
@@ -153,7 +153,7 @@ enum MergeCandidateSize {
153153
/// This can happen for any of the two following reasons:
154154
/// - the number of splits involved already reached `merge_factor_max`.
155155
/// - the overall number of docs that will end up in the merged segment already exceeds
156-
/// `max_merge_docs`.
156+
/// `split_num_docs_target`.
157157
OneMoreSplitWouldBeTooBig,
158158
}
159159

@@ -213,13 +213,13 @@ impl StableLogMergePolicy {
213213
/// but should behave decently (not create too many levels) if they are not.
214214
///
215215
/// All splits are required to have a number of documents lower than
216-
/// `self.max_merge_docs`
216+
/// `self.split_num_docs_target`
217217
pub(crate) fn build_split_levels(&self, splits: &[SplitMetadata]) -> Vec<Range<usize>> {
218218
assert!(
219219
splits
220220
.iter()
221221
.all(|split| split.num_docs < self.split_num_docs_target),
222-
"All splits are expected to be smaller than `max_merge_docs`."
222+
"All splits are expected to be smaller than `split_num_docs_target`."
223223
);
224224
if splits.is_empty() {
225225
return Vec::new();
@@ -370,7 +370,8 @@ mod tests {
370370
#[test]
371371
fn test_split_is_mature() {
372372
let merge_policy = StableLogMergePolicy::default();
373-
// Split under max_merge_docs and created before now() - maturation_period is not mature.
373+
// Split under split_num_docs_target and created before now() - maturation_period is not
374+
// mature.
374375
assert_eq!(
375376
merge_policy.split_maturity(9_000_000, 0),
376377
SplitMaturity::Immature {
@@ -381,7 +382,7 @@ mod tests {
381382
merge_policy.split_maturity(&merge_policy.split_num_docs_target + 1, 0),
382383
SplitMaturity::Mature
383384
);
384-
// Split under max_merge_docs but with create_timestamp >= now + maturity duration is
385+
// Split under split_num_docs_target but with create_timestamp >= now + maturity duration is
385386
// mature.
386387
assert_eq!(
387388
merge_policy.split_maturity(9_000_000, 0),
@@ -439,8 +440,8 @@ mod tests {
439440
}
440441

441442
#[test]
442-
#[should_panic(expected = "All splits are expected to be smaller than `max_merge_docs`.")]
443-
fn test_stable_log_merge_policy_build_split_panics_if_exceeding_max_merge_docs() {
443+
#[should_panic(expected = "All splits are expected to be smaller than `split_num_docs_target`.")]
444+
fn test_stable_log_merge_policy_build_split_panics_if_exceeding_split_num_docs_target() {
444445
let merge_policy = StableLogMergePolicy::default();
445446
let splits = create_splits(&merge_policy, vec![11_000_000]);
446447
merge_policy.build_split_levels(&splits);
@@ -545,7 +546,7 @@ mod tests {
545546
}
546547

547548
#[test]
548-
fn test_stable_log_merge_policy_above_max_merge_docs_is_ignored() {
549+
fn test_stable_log_merge_policy_above_split_num_docs_target_is_ignored() {
549550
let merge_policy = StableLogMergePolicy::default();
550551
let mut splits = create_splits(
551552
&merge_policy,

0 commit comments

Comments
 (0)