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

feat: add gc configuration for dfdaemon #142

Merged
merged 1 commit into from
Dec 13, 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
63 changes: 63 additions & 0 deletions src/config/dfdaemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ const DEFAULT_DYNCONFIG_REFRESH_INTERVAL: Duration = Duration::from_secs(1800);
// DEFAULT_SEED_PEER_KEEPALIVE_INTERVAL is the default interval to keepalive with manager.
const DEFAULT_SEED_PEER_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(15);

// DEFAULT_GC_INTERVAL is the default interval to do gc.
const DEFAULT_GC_INTERVAL: Duration = Duration::from_secs(120);

// DEFAULT_GC_POLICY_TASK_TTL is the default ttl of the task.
const DEFAULT_GC_POLICY_TASK_TTL: Duration = Duration::from_secs(21_600);

// DEFAULT_GC_POLICY_DIST_HIGH_THRESHOLD_PERCENT is the default high threshold percent of the disk usage.
const DEFAULT_GC_POLICY_DIST_HIGH_THRESHOLD_PERCENT: u8 = 80;

// DEFAULT_GC_POLICY_DIST_LOW_THRESHOLD_PERCENT is the default low threshold percent of the disk usage.
const DEFAULT_GC_POLICY_DIST_LOW_THRESHOLD_PERCENT: u8 = 70;

// default_dfdaemon_config_path is the default config path for dfdaemon.
pub fn default_dfdaemon_config_path() -> PathBuf {
super::default_config_dir().join("dfdaemon.yaml")
Expand Down Expand Up @@ -356,6 +368,54 @@ impl Default for Dynconfig {
#[serde(default, rename_all = "camelCase")]
pub struct Storage {}

// Policy is the policy configuration for gc.
#[derive(Debug, Clone, Validate, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Policy {
// task_ttl is the ttl of the task.
pub task_ttl: Duration,

// dist_high_threshold_percent is the high threshold percent of the disk usage.
// If the disk usage is greater than the threshold, dfdaemon will do gc.
pub dist_high_threshold_percent: u8,

// dist_low_threshold_percent is the low threshold percent of the disk usage.
// If the disk usage is less than the threshold, dfdaemon will stop gc.
pub dist_low_threshold_percent: u8,
}

// Policy implements default value for Policy.
impl Default for Policy {
fn default() -> Self {
Self {
task_ttl: DEFAULT_GC_POLICY_TASK_TTL,
dist_high_threshold_percent: DEFAULT_GC_POLICY_DIST_HIGH_THRESHOLD_PERCENT,
dist_low_threshold_percent: DEFAULT_GC_POLICY_DIST_LOW_THRESHOLD_PERCENT,
}
}
}

// GC is the gc configuration for dfdaemon.
#[derive(Debug, Clone, Validate, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct GC {
// interval is the interval to do gc.
pub interval: Duration,

// policy is the gc policy.
pub policy: Policy,
}

// GC implements default value for GC.
impl Default for GC {
fn default() -> Self {
Self {
interval: DEFAULT_GC_INTERVAL,
policy: Policy::default(),
}
}
}

// Proxy is the proxy configuration for dfdaemon.
#[derive(Debug, Clone, Default, Validate, Deserialize)]
#[serde(default, rename_all = "camelCase")]
Expand Down Expand Up @@ -486,6 +546,9 @@ pub struct Config {
// storage is the storage configuration for dfdaemon.
pub storage: Storage,

// gc is the gc configuration for dfdaemon.
pub gc: GC,

// proxy is the proxy configuration for dfdaemon.
pub proxy: Proxy,

Expand Down
15 changes: 15 additions & 0 deletions src/gc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2023 The Dragonfly Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod announcer;
pub mod backend;
pub mod config;
pub mod dynconfig;
pub mod gc;
pub mod grpc;
pub mod health;
pub mod metrics;
Expand Down