Skip to content

Commit e41be32

Browse files
committed
logic test
1 parent 873593a commit e41be32

File tree

2 files changed

+124
-26
lines changed

2 files changed

+124
-26
lines changed

src/query/ee/src/storages/fuse/operations/vacuum_table_v2.rs

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,34 @@ pub async fn do_vacuum2(
122122
start.elapsed(),
123123
lvt
124124
));
125-
let snapshots_before_lvt = if is_vacuum_all {
126-
list_until_prefix(
127-
fuse_table,
128-
fuse_table
129-
.meta_location_generator()
130-
.snapshot_location_prefix(),
131-
fuse_table.snapshot_loc().unwrap().as_str(),
132-
true,
133-
None,
134-
)
135-
.await?
136-
} else {
137-
list_until_timestamp(
138-
fuse_table,
139-
fuse_table
140-
.meta_location_generator()
141-
.snapshot_location_prefix(),
142-
lvt,
143-
true,
144-
None,
145-
)
146-
.await?
147-
};
148125

149126
let elapsed = start.elapsed();
127+
let snapshots_before_lvt =
128+
collect_gc_candidate_by_retention_period(fuse_table, lvt, is_vacuum_all).await?;
129+
// let snapshots_before_lvt = if is_vacuum_all {
130+
// list_until_prefix(
131+
// fuse_table,
132+
// fuse_table
133+
// .meta_location_generator()
134+
// .snapshot_location_prefix(),
135+
// fuse_table.snapshot_loc().unwrap().as_str(),
136+
// true,
137+
// None,
138+
// )
139+
// .await?
140+
//} else {
141+
// list_until_timestamp(
142+
// fuse_table,
143+
// fuse_table
144+
// .meta_location_generator()
145+
// .snapshot_location_prefix(),
146+
// lvt,
147+
// true,
148+
// None,
149+
// )
150+
// .await?
151+
//};
152+
150153
ctx.set_status_info(&format!(
151154
"list snapshots before lvt for table {} takes {:?}, snapshots_dir: {:?}, lvt: {:?}, snapshots: {:?}",
152155
fuse_table.get_table_info().desc,
@@ -389,6 +392,38 @@ pub async fn do_vacuum2(
389392
Ok(files_to_gc)
390393
}
391394

395+
async fn collect_gc_candidate_by_retention_period(
396+
fuse_table: &FuseTable,
397+
lvt: DateTime<Utc>,
398+
is_vacuum_all: bool,
399+
) -> Result<Vec<Entry>> {
400+
let snapshots_before_lvt = if is_vacuum_all {
401+
list_until_prefix(
402+
fuse_table,
403+
fuse_table
404+
.meta_location_generator()
405+
.snapshot_location_prefix(),
406+
fuse_table.snapshot_loc().unwrap().as_str(),
407+
true,
408+
None,
409+
)
410+
.await?
411+
} else {
412+
list_until_timestamp(
413+
fuse_table,
414+
fuse_table
415+
.meta_location_generator()
416+
.snapshot_location_prefix(),
417+
lvt,
418+
true,
419+
None,
420+
)
421+
.await?
422+
};
423+
424+
Ok(snapshots_before_lvt)
425+
}
426+
392427
/// Try set lvt as min(latest_snapshot.timestamp, now - retention_time).
393428
///
394429
/// Return `None` means we stop vacuumming, but don't want to report error to user.

tests/sqllogictests/suites/ee/03_ee_vacuum/03_0004_auto_vacuum.test

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,75 @@ select count() from list_stage(location=> '@stage_av') where name like '%_ss%';
145145
----
146146
1
147147

148-
# ---------------------------------------------
149148

150-
# We do not check default retention period works as expected, i.e. by default table historical data
151-
# will be cleaned according to the retention period settings. As tests of streams will check it implicitly
149+
#################################################
150+
# Test autovacuum policy `ByNumSnapshotsToKeep` #
151+
#################################################
152+
153+
# CASE 1: Create table with data_retention_num_snapshots_to_keep table option
154+
statement ok
155+
create or replace table t (c int) 'fs:///tmp/auto_vacuum_case3/' data_retention_num_snapshots_to_keep = 3;
156+
157+
statement ok
158+
create or replace stage stage_av url = 'fs:///tmp/auto_vacuum_case3/';
159+
160+
statement ok
161+
set enable_auto_vacuum = 1;
162+
163+
statement ok
164+
insert into t values(1);
165+
166+
statement ok
167+
insert into t values(2);
168+
169+
statement ok
170+
insert into t values(3);
171+
172+
statement ok
173+
insert into t values(4);
174+
175+
176+
# Insert 4 time, but only 3 snapshots will be kept
177+
onlyif mysql
178+
query I
179+
select count() from list_stage(location=> '@stage_av') where name like '%_ss%';
180+
----
181+
3
182+
183+
# CASE 2: Alter table option
184+
statement ok
185+
alter table t set options(data_retention_num_snapshots_to_keep = 1);
186+
187+
statement ok
188+
insert into t values(1);
189+
190+
statement ok
191+
optimize table t compact;
192+
193+
onlyif mysql
194+
query I
195+
select count() from list_stage(location=> '@stage_av') where name like '%_sg%';
196+
----
197+
1
198+
199+
onlyif mysql
200+
query I
201+
select count() from list_stage(location=> '@stage_av') where name like '%\/_b\/%';
202+
----
203+
1
204+
205+
onlyif mysql
206+
query I
207+
select count() from list_stage(location=> '@stage_av') where name like '%_ss%';
208+
----
209+
1
210+
152211

212+
# CASE 3: Create table with invalid data_retention_num_snapshots_to_keep table option
153213

214+
# data_retention_num_snapshots_to_keep must be greater than 0
215+
statement error
216+
create or replace table t (c int) 'fs:///tmp/auto_vacuum_case3/' data_retention_num_snapshots_to_keep = 0;
154217

155218
statement ok
156219
remove @stage_av;

0 commit comments

Comments
 (0)