chore: add test for can_move on row count

pull/24376/head
Paul Dix 2021-07-01 15:45:56 -04:00
parent 91f5478012
commit 61917c107f
2 changed files with 14 additions and 5 deletions

View File

@ -449,6 +449,10 @@ fn elapsed_seconds(a: DateTime<Utc>, b: DateTime<Utc>) -> u32 {
///
/// Note: Does not check the chunk is the correct state
fn can_move<C: LifecycleChunk>(rules: &LifecycleRules, chunk: &C, now: DateTime<Utc>) -> bool {
if chunk.row_count() >= DEFAULT_MUB_ROW_THRESHOLD {
return true;
}
match (rules.mutable_linger_seconds, chunk.time_of_last_write()) {
(Some(linger), Some(last_write)) if elapsed_seconds(now, last_write) >= linger.get() => {
match (
@ -465,9 +469,9 @@ fn can_move<C: LifecycleChunk>(rules: &LifecycleRules, chunk: &C, now: DateTime<
}
}
// Move it if over the row count threshold or don't move since it's either empty or the linger time hasn't expired.
// TODO: make this a configuration variable
_ => chunk.row_count() >= DEFAULT_MUB_ROW_THRESHOLD,
// Disable movement if no mutable_linger set,
// or the chunk is empty, or the linger hasn't expired
_ => false,
}
}
@ -879,6 +883,11 @@ mod tests {
let chunk = TestChunk::new(0, Some(0), Some(70), ChunkStorage::OpenMutableBuffer);
assert!(!can_move(&rules, &chunk, from_secs(71)));
assert!(can_move(&rules, &chunk, from_secs(81)));
// If over the default row count threshold, we should be able to move
let chunk = TestChunk::new(0, None, None, ChunkStorage::OpenMutableBuffer)
.with_row_count(DEFAULT_MUB_ROW_THRESHOLD);
assert!(can_move(&rules, &chunk, from_secs(0)));
}
#[test]

View File

@ -683,7 +683,7 @@ impl Db {
continue;
}
let _ = partition.create_open_chunk(mb_chunk);
partition.create_open_chunk(mb_chunk);
}
};
@ -2391,7 +2391,7 @@ mod tests {
("access", "exclusive"),
])
.counter()
.eq(2.)
.eq(1.)
.unwrap();
test_db