Skip to content

Commit 56a92ce

Browse files
committed
introduce setting retention_period
1 parent a3aaa22 commit 56a92ce

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/query/service/tests/it/storages/testdata/system-tables.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ DB.Table: 'system'.'settings', Table: settings-table_id:1, ver:0, Engine: System
353353
| max_storage_io_requests | 64 | 64 | SESSION | The maximum number of concurrent IO requests. By default, it is 64. | UInt64 |
354354
| prefer_broadcast_join | 0 | 0 | SESSION | If enable broadcast join, default value: 0 | UInt64 |
355355
| quoted_ident_case_sensitive | 1 | 1 | SESSION | Case sensitivity of quoted identifiers, default value: 1 (aka case-sensitive). | UInt64 |
356+
| retention_period | 12 | 12 | SESSION | The retention_period in hours. By default the value is 12 hours. | UInt64 |
356357
| row_tag | row | row | SESSION | In xml format, this field is represented as a row tag, e.g. <row>...</row>. | String |
357358
| sql_dialect | PostgreSQL | PostgreSQL | SESSION | SQL dialect, support "PostgreSQL" "MySQL" and "Hive", default value: "PostgreSQL". | String |
358359
| storage_read_buffer_size | 1048576 | 1048576 | SESSION | The size of buffer in bytes for buffered reader of dal. By default, it is 1MB. | UInt64 |

src/query/settings/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ impl Settings {
164164
desc: "The maximum memory usage for processing single query, in bytes. By default the value is determined automatically.",
165165
possible_values: None,
166166
},
167+
// retention_period
168+
SettingValue {
169+
// unit of retention_period is hour
170+
default_value: UserSettingValue::UInt64(12),
171+
user_setting: UserSetting::create("retention_period", UserSettingValue::UInt64(12)),
172+
level: ScopeLevel::Session,
173+
desc: "The retention_period in hours. By default the value is 12 hours.",
174+
possible_values: None,
175+
},
167176
// max_storage_io_requests
168177
SettingValue {
169178
default_value: UserSettingValue::UInt64(64),
@@ -519,6 +528,16 @@ impl Settings {
519528
self.try_set_u64(key, val, false)
520529
}
521530

531+
pub fn set_retention_period(&self, hours: u64) -> Result<()> {
532+
let key = "retention_period";
533+
self.try_set_u64(key, hours, false)
534+
}
535+
536+
pub fn get_retention_period(&self) -> Result<u64> {
537+
let key = "retention_period";
538+
self.try_get_u64(key)
539+
}
540+
522541
pub fn get_max_storage_io_requests(&self) -> Result<u64> {
523542
let key = "max_storage_io_requests";
524543
self.try_get_u64(key)

src/query/storages/fuse/fuse/src/operations/gc.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ use crate::io::SegmentsIO;
3939
use crate::io::SnapshotsIO;
4040
use crate::FuseTable;
4141

42-
pub const DEFAULT_RETENTION_PERIOD_HOURS: u32 = 12;
43-
4442
#[derive(Default)]
4543
struct LocationTuple {
4644
block_location: HashSet<String>,
@@ -123,9 +121,10 @@ impl FuseTable {
123121

124122
// partition the orphan snapshots by retention interval
125123
let partitioned_snapshots = Self::apply_retention_rule(
124+
ctx.as_ref(),
126125
min_snapshot_timestamp,
127126
snapshot_lites_extended.orphan_snapshot_lites,
128-
);
127+
)?;
129128

130129
// filter out segments that still referenced by snapshot that within retention period
131130
all_segment_locations = Self::filter_out_segments_within_retention(
@@ -359,18 +358,20 @@ impl FuseTable {
359358
// - those are beyond retention period
360359
// - those are within retention period
361360
fn apply_retention_rule(
361+
ctx: &dyn TableContext,
362362
base_timestamp: Option<DateTime<Utc>>,
363363
snapshot_lites: Vec<(TableSnapshotLite, usize)>,
364-
) -> RetentionPartition {
365-
let retention_interval = Duration::hours(DEFAULT_RETENTION_PERIOD_HOURS as i64);
364+
) -> Result<RetentionPartition> {
365+
// let retention_interval = Duration::hours(DEFAULT_RETENTION_PERIOD_HOURS as i64);
366+
let retention_interval = Duration::hours(ctx.get_settings().get_retention_period()? as i64);
366367
let retention_point = base_timestamp.map(|s| s - retention_interval);
367368
let (beyond_retention, within_retention) = snapshot_lites
368369
.into_iter()
369370
.partition(|(lite, _idx)| lite.timestamp < retention_point);
370-
RetentionPartition {
371+
Ok(RetentionPartition {
371372
beyond_retention,
372373
within_retention,
373-
}
374+
})
374375
}
375376

376377
// filter out segments that are referenced by orphan snapshots

0 commit comments

Comments
 (0)