Skip to content

Commit b4f9763

Browse files
authored
fix: purge oom (#12950)
* fix purge oom * add unit test
1 parent 7c1a8a8 commit b4f9763

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

src/query/service/tests/it/storages/fuse/meta/snapshot.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::collections::HashMap;
1516
use std::ops::Add;
1617

1718
use common_expression::TableSchema;
19+
use storages_common_table_meta::meta::testing::StatisticsV0;
20+
use storages_common_table_meta::meta::testing::TableSnapshotV1;
21+
use storages_common_table_meta::meta::testing::TableSnapshotV2;
1822
use storages_common_table_meta::meta::TableSnapshot;
1923
use uuid::Uuid;
2024

@@ -74,3 +78,32 @@ fn snapshot_timestamp_time_skew_tolerance() {
7478
let prev_ts = prev.timestamp.unwrap();
7579
assert!(current_ts > prev_ts)
7680
}
81+
82+
#[test]
83+
fn test_snapshot_v1_to_v4() {
84+
let summary = StatisticsV0 {
85+
row_count: 0,
86+
block_count: 0,
87+
perfect_block_count: 0,
88+
uncompressed_byte_size: 0,
89+
compressed_byte_size: 0,
90+
index_size: 0,
91+
col_stats: HashMap::new(),
92+
};
93+
let v1 = TableSnapshotV1::new(
94+
Uuid::new_v4(),
95+
&None,
96+
None,
97+
Default::default(),
98+
summary,
99+
vec![],
100+
None,
101+
None,
102+
);
103+
assert!(v1.timestamp.is_some());
104+
105+
let v4: TableSnapshot = TableSnapshotV2::from(v1.clone()).into();
106+
assert_eq!(v4.format_version, v1.format_version());
107+
assert_eq!(v4.snapshot_id, v1.snapshot_id);
108+
assert_eq!(v4.timestamp, v1.timestamp);
109+
}

src/query/storages/common/table-meta/src/meta/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ pub use versions::Versioned;
5050
// - export meta encoding to benchmarking tests
5151
pub mod testing {
5252
pub use super::format::MetaEncoding;
53+
pub use super::v0::statistics::Statistics as StatisticsV0;
54+
pub use super::v1::TableSnapshot as TableSnapshotV1;
5355
pub use super::v2::SegmentInfo as SegmentInfoV2;
5456
pub use super::v2::TableSnapshot as TableSnapshotV2;
5557
pub use super::v3::SegmentInfo as SegmentInfoV3;

src/query/storages/common/table-meta/src/meta/v2/snapshot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl From<v1::TableSnapshot> for TableSnapshot {
127127
// carries the format_version of snapshot being converted.
128128
format_version: s.format_version,
129129
snapshot_id: s.snapshot_id,
130-
timestamp: None,
130+
timestamp: s.timestamp,
131131
prev_snapshot_id: s.prev_snapshot_id,
132132
schema,
133133
summary,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ impl FuseTable {
6363
}
6464
}
6565
let root_snapshot_info = root_snapshot_info_op.unwrap();
66+
if root_snapshot_info.snapshot_lite.timestamp.is_none() {
67+
return Err(ErrorCode::StorageOther(format!(
68+
"gc: snapshot timestamp is none, snapshot location: {}",
69+
root_snapshot_info.snapshot_location
70+
)));
71+
}
6672

6773
let snapshots_io = SnapshotsIO::create(ctx.clone(), self.operator.clone());
6874
let location_gen = self.meta_location_generator();
@@ -116,7 +122,7 @@ impl FuseTable {
116122
let mut segments_to_be_purged = HashSet::new();
117123
let mut ts_to_be_purged = HashSet::new();
118124
for s in snapshots.into_iter() {
119-
if s.timestamp >= base_timestamp {
125+
if s.timestamp.is_some() && s.timestamp >= base_timestamp {
120126
remain_snapshots.push(s);
121127
continue;
122128
}

0 commit comments

Comments
 (0)