Skip to content

Commit e35bacc

Browse files
authored
fix: purge may not work on tables after a flash back operation (#16812)
* fix: purge may not work on tables after a flash back operation * fix * fix test * fix test
1 parent b9d4c60 commit e35bacc

File tree

5 files changed

+9
-30
lines changed

5 files changed

+9
-30
lines changed

src/query/service/tests/it/storages/fuse/operations/navigate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ async fn test_navigate_for_purge() -> Result<()> {
168168

169169
// keep the first snapshot of the insertion
170170
let table = fixture.latest_default_table().await?;
171-
let first_snapshot = FuseTable::try_from_table(table.as_ref())?
171+
let _first_snapshot = FuseTable::try_from_table(table.as_ref())?
172172
.snapshot_loc()
173173
.await?
174174
.unwrap();
@@ -233,7 +233,7 @@ async fn test_navigate_for_purge() -> Result<()> {
233233
// navigate from the instant that is just one ms before the timestamp of the latest snapshot.
234234
let (navigate, files) = fuse_table.list_by_time_point(time_point).await?;
235235
assert_eq!(2, files.len());
236-
assert_eq!(navigate, first_snapshot);
236+
assert_eq!(navigate, third_snapshot);
237237

238238
// 5. navigate by snapshot id.
239239
let snapshot_id = snapshots[1].0.snapshot_id.simple().to_string();

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use databend_common_exception::Result;
2424
use databend_common_exception::ResultExt;
2525
use databend_common_meta_app::schema::TableInfo;
2626
use databend_common_meta_app::schema::TableStatistics;
27-
use databend_storages_common_cache::LoadParams;
2827
use databend_storages_common_table_meta::meta::TableSnapshot;
2928
use databend_storages_common_table_meta::table::OPT_KEY_SNAPSHOT_LOCATION;
3029
use databend_storages_common_table_meta::table::OPT_KEY_SOURCE_TABLE_ID;
@@ -274,29 +273,11 @@ impl FuseTable {
274273
));
275274
}
276275

277-
let location = files[0].clone();
278-
let reader = MetaReaders::table_snapshot_reader(self.get_operator());
279-
let ver = TableMetaLocationGenerator::snapshot_version(location.as_str());
280-
let load_params = LoadParams {
281-
location,
282-
len_hint: None,
283-
ver,
284-
put_cache: false,
276+
let Some(location) = self.snapshot_loc().await? else {
277+
return Err(ErrorCode::TableHistoricalDataNotFound("No historical data"));
285278
};
286-
let snapshot = reader.read(&load_params).await?;
287-
// Take the prev snapshot as base snapshot to avoid get orphan snapshot.
288-
let prev = snapshot.prev_snapshot_id;
289-
match prev {
290-
Some((id, v)) => {
291-
let new_loc = self
292-
.meta_location_generator()
293-
.snapshot_location_from_uuid(&id, v)?;
294-
Ok((new_loc, files))
295-
}
296-
None => Err(ErrorCode::TableHistoricalDataNotFound(
297-
"No historical data found at given point",
298-
)),
299-
}
279+
280+
Ok((location, files))
300281
}
301282

302283
#[async_backtrace::framed]

tests/sqllogictests/suites/base/09_fuse_engine/09_0008_fuse_optimize_table.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ query II
102102
select segment_count,block_count from fuse_snapshot('db_09_0008', 't') limit 2
103103
----
104104
1 1
105-
4 4
106-
107105

108106

109107
query I

tests/suites/0_stateless/20+_others/20_0011_purge_before.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ checking that after purge (by snapshot id) there should be 4 rows left
66
true
77
checking that there should are 3 snapshots before purge
88
true
9-
checking that after purge (by timestamp) there should be at least 2 snapshots left
9+
checking that after purge (by timestamp) there should be 1 snapshot left
1010
true
1111
checking that after purge (by timestamp) there should be 4 rows left
1212
true

tests/suites/0_stateless/20+_others/20_0011_purge_before.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ TIMEPOINT=$(echo "select timestamp from fuse_snapshot('default', 't20_0011') whe
5252

5353
## verify
5454
echo "set data_retention_time_in_days=0; optimize table t20_0011 purge before (TIMESTAMP => '$TIMEPOINT'::TIMESTAMP)" | $BENDSQL_CLIENT_CONNECT
55-
echo "checking that after purge (by timestamp) there should be at least 2 snapshots left"
56-
echo "select count(*)>=2 from fuse_snapshot('default', 't20_0011')" | $BENDSQL_CLIENT_CONNECT
55+
echo "checking that after purge (by timestamp) there should be 1 snapshot left"
56+
echo "select count(*)=1 from fuse_snapshot('default', 't20_0011')" | $BENDSQL_CLIENT_CONNECT
5757
echo "checking that after purge (by timestamp) there should be 4 rows left"
5858
echo "select count(*)=4 from t20_0011" | $BENDSQL_CLIENT_CONNECT
5959

0 commit comments

Comments
 (0)