Skip to content

Commit 596cdbd

Browse files
committed
logic test
1 parent 791b0fd commit 596cdbd

File tree

2 files changed

+31
-39
lines changed

2 files changed

+31
-39
lines changed

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

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ pub async fn do_vacuum2(
9595
// Indicates whether to use the current table snapshot as gc root,
9696
// true means vacuum all the historical snapshots.
9797
let mut is_vacuum_all = false;
98-
9998
let mut respect_flash_back_with_lvt = None;
99+
100100
let snapshots_before_lvt = match retention_policy {
101101
RetentionPolicy::ByTimePeriod(delta_duration) => {
102+
info!("using by ByTimePeriod policy {:?}", delta_duration);
102103
let retention_period = if fuse_table.is_transient() {
103104
// For transient table, keep no history data
104105
TimeDelta::zero()
@@ -123,44 +124,15 @@ pub async fn do_vacuum2(
123124
lvt
124125
));
125126

126-
let elapsed = start.elapsed();
127127
let snapshots_before_lvt =
128128
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-
153-
ctx.set_status_info(&format!(
154-
"list snapshots before lvt for table {} takes {:?}, snapshots_dir: {:?}, lvt: {:?}, snapshots: {:?}",
155-
fuse_table.get_table_info().desc,
156-
elapsed,
157-
fuse_table.meta_location_generator().snapshot_location_prefix(),
158-
lvt,
159-
slice_summary(&snapshots_before_lvt)
160-
));
161129
snapshots_before_lvt
162130
}
163-
RetentionPolicy::ByNumOfSnapshotsToKeep(num_snapshot_to_keep) => {
131+
RetentionPolicy::ByNumOfSnapshotsToKeep(num_snapshots_to_keep) => {
132+
info!(
133+
"using by ByNumOfSnapshotsToKeep policy {:?}",
134+
num_snapshots_to_keep
135+
);
164136
// List the snapshot order by timestamp asc, till the current snapshot(inclusively).
165137
let need_one_more = true;
166138
let mut snapshots = list_until_prefix(
@@ -175,11 +147,11 @@ pub async fn do_vacuum2(
175147
.await?;
176148

177149
let len = snapshots.len();
178-
if len <= num_snapshot_to_keep {
150+
if len <= num_snapshots_to_keep {
179151
// Only the current snapshot is there, done
180152
return Ok(vec![]);
181153
}
182-
if num_snapshot_to_keep == 1 {
154+
if num_snapshots_to_keep == 1 {
183155
// Expecting only one snapshot left, which means that we can use the current snapshot
184156
// as gc root, this flag will be propagated to the select_gc_root func later.
185157
is_vacuum_all = true;
@@ -189,12 +161,23 @@ pub async fn do_vacuum2(
189161
// but its commit status is uncertain, its previous snapshot is typically used as the GC root, except in the is_vacuum_all case.
190162
//
191163
// Therefore, during snapshot truncation, we keep 2 extra snapshots; see `select_gc_root` for details.
192-
let num_candidates = len - num_snapshot_to_keep + 2;
164+
let num_candidates = len - num_snapshots_to_keep + 2;
193165
snapshots.truncate(num_candidates);
194166
snapshots
195167
}
196168
};
197169

170+
let elapsed = start.elapsed();
171+
ctx.set_status_info(&format!(
172+
"list snapshots for table {} takes {:?}, snapshots_dir: {:?}, snapshots: {:?}",
173+
fuse_table.get_table_info().desc,
174+
elapsed,
175+
fuse_table
176+
.meta_location_generator()
177+
.snapshot_location_prefix(),
178+
slice_summary(&snapshots_before_lvt)
179+
));
180+
198181
let start = std::time::Instant::now();
199182
let Some((gc_root, snapshots_to_gc, gc_root_meta_ts)) = select_gc_root(
200183
fuse_table,

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ statement ok
185185
alter table t set options(data_retention_num_snapshots_to_keep = 1);
186186

187187
statement ok
188-
insert into t values(1);
188+
insert into t values(5);
189189

190190
statement ok
191191
optimize table t compact;
@@ -208,6 +208,15 @@ select count() from list_stage(location=> '@stage_av') where name like '%_ss%';
208208
----
209209
1
210210

211+
query I
212+
select * from t order by c;
213+
----
214+
1
215+
2
216+
3
217+
4
218+
5
219+
211220

212221
# CASE 3: Create table with invalid data_retention_num_snapshots_to_keep table option
213222

0 commit comments

Comments
 (0)