Skip to content

Commit

Permalink
feat: add gc configuration for dfdaemon
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Dec 12, 2023
1 parent 32dd257 commit 6f9c73f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/config/dfdaemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ 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_THRESHOLD_PERCENT is the default threshold percent of the disk usage.
const DEFAULT_GC_POLICY_DIST_THRESHOLD_PERCENT: u8 = 80;

// 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 +365,49 @@ 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_threshold_percent is the threshold percent of the disk usage.
// If the disk usage is greater than the threshold, dfdaemon will do gc.
pub dist_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_threshold_percent: DEFAULT_GC_POLICY_DIST_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 +538,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

0 comments on commit 6f9c73f

Please sign in to comment.