Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enlarge append recycle log threshold #331

Merged
merged 8 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub struct Config {
pub prefill_for_recycle: bool,

/// Maximum capacity for preparing log files for recycling when start.
/// If not `None`, its size is equal to `purge-threshold`.
/// If `None`, its size is equal to `purge-threshold`*1.5.
/// Only available for `prefill-for-recycle` is true.
///
/// Default: None
Expand Down Expand Up @@ -219,10 +219,10 @@ impl Config {
}
if self.enable_log_recycle && self.purge_threshold.0 >= self.target_file_size.0 {
// (1) At most u32::MAX so that the file number can be capped into an u32
// without colliding. (2) Add some more file as an additional buffer to
// avoid jitters.
// without colliding. (2) Increase the threshold by 50% to add some more file
// as an additional buffer to avoid jitters.
std::cmp::min(
(self.purge_threshold.0 / self.target_file_size.0) as usize + 2,
(self.purge_threshold.0 / self.target_file_size.0) as usize * 3 / 2,
u32::MAX as usize,
)
} else {
Expand All @@ -241,7 +241,7 @@ impl Config {
if self.prefill_for_recycle && prefill_limit >= self.target_file_size.0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When prefill_limit is None, use recycle_capacity.

// Keep same with the maximum setting of `recycle_capacity`.
std::cmp::min(
(prefill_limit / self.target_file_size.0) as usize + 2,
(prefill_limit / self.target_file_size.0) as usize * 3 / 2,
u32::MAX as usize,
)
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,7 @@ pub(crate) mod tests {
prefill_for_recycle: true,
..Default::default()
};
let recycle_capacity = cfg.recycle_capacity() as u64;
let fs = Arc::new(DeleteMonitoredFileSystem::new());
let engine = RaftLogEngine::open_with_file_system(cfg, fs.clone()).unwrap();

Expand Down Expand Up @@ -2197,11 +2198,11 @@ pub(crate) mod tests {
assert_eq!(reserved_start_2, reserved_start_3);

// Reuse all of reserved files.
for rid in 1..=50 {
for rid in 1..=recycle_capacity {
engine.append(rid, 1, 11, Some(&entry_data));
}
assert!(fs.reserved_metadata.lock().unwrap().is_empty());
for rid in 1..=50 {
for rid in 1..=recycle_capacity {
engine.clean(rid);
}
engine.purge_manager.must_rewrite_append_queue(None, None);
Expand Down Expand Up @@ -2704,6 +2705,7 @@ pub(crate) mod tests {
purge_threshold: ReadableSize(40),
..cfg.clone()
};
let recycle_capacity = cfg_2.recycle_capacity() as u64;
let engine = RaftLogEngine::open_with_file_system(cfg_2, file_system.clone()).unwrap();
assert!(number_of_files(spill_dir.path()) > 0);
for rid in 1..=10 {
Expand All @@ -2718,7 +2720,7 @@ pub(crate) mod tests {
);
assert!(file_count > engine.file_count(None));
// Append data, recycled files are reused.
for rid in 1..=30 {
for rid in 1..=recycle_capacity - 10 {
engine.append(rid, 20, 30, Some(&entry_data));
}
// No new file is created.
Expand Down