@@ -24,9 +24,10 @@ use async_trait::async_trait;
2424use itertools:: Itertools ;
2525
2626use crate :: error:: Result ;
27- use crate :: spec:: { MAIN_BRANCH , SnapshotReference , SnapshotRetention , TableMetadata , ancestors_of } ;
27+ use crate :: spec:: { MAIN_BRANCH , SnapshotReference , SnapshotRetention , TableMetadataRef } ;
2828use crate :: table:: Table ;
2929use crate :: transaction:: { ActionCommit , TransactionAction } ;
30+ use crate :: utils:: ancestors_of;
3031use crate :: { Error , ErrorKind , TableRequirement , TableUpdate } ;
3132
3233/// Default value for max snapshot age in milliseconds.
@@ -103,7 +104,7 @@ impl RemoveSnapshotAction {
103104 fn compute_retained_refs (
104105 & self ,
105106 snapshot_refs : & HashMap < String , SnapshotReference > ,
106- table_meta : & TableMetadata ,
107+ table_meta : & TableMetadataRef ,
107108 ) -> HashMap < String , SnapshotReference > {
108109 let mut retained_refs = HashMap :: new ( ) ;
109110
@@ -144,7 +145,7 @@ impl RemoveSnapshotAction {
144145 fn compute_all_branch_snapshots_to_retain (
145146 & self ,
146147 refs : impl Iterator < Item = SnapshotReference > ,
147- table_meta : & TableMetadata ,
148+ table_meta : & TableMetadataRef ,
148149 ) -> HashSet < i64 > {
149150 let mut branch_snapshots_to_retain = HashSet :: new ( ) ;
150151 for snapshot_ref in refs {
@@ -192,11 +193,11 @@ impl RemoveSnapshotAction {
192193 snapshot_id : i64 ,
193194 expire_snapshots_older_than : i64 ,
194195 min_snapshots_to_keep : usize ,
195- table_meta : & TableMetadata ,
196+ table_meta : & TableMetadataRef ,
196197 ) -> HashSet < i64 > {
197198 let mut ids_to_retain = HashSet :: new ( ) ;
198199 if let Some ( snapshot) = table_meta. snapshot_by_id ( snapshot_id) {
199- let ancestors = ancestors_of ( snapshot. clone ( ) , table_meta ) ;
200+ let ancestors = ancestors_of ( table_meta , snapshot. snapshot_id ( ) ) ;
200201 for ancestor in ancestors {
201202 if ids_to_retain. len ( ) < min_snapshots_to_keep
202203 || ancestor. timestamp_ms ( ) >= expire_snapshots_older_than
@@ -214,15 +215,15 @@ impl RemoveSnapshotAction {
214215 fn unreferenced_snapshots_to_retain (
215216 & self ,
216217 refs : impl Iterator < Item = SnapshotReference > ,
217- table_meta : & TableMetadata ,
218+ table_meta : & TableMetadataRef ,
218219 ) -> HashSet < i64 > {
219220 let mut ids_to_retain = HashSet :: new ( ) ;
220221 let mut referenced_snapshots = HashSet :: new ( ) ;
221222
222223 for snapshot_ref in refs {
223224 if snapshot_ref. is_branch ( ) {
224225 if let Some ( snapshot) = table_meta. snapshot_by_id ( snapshot_ref. snapshot_id ) {
225- let ancestors = ancestors_of ( snapshot. clone ( ) , table_meta ) ;
226+ let ancestors = ancestors_of ( table_meta , snapshot. snapshot_id ( ) ) ;
226227 for ancestor in ancestors {
227228 referenced_snapshots. insert ( ancestor. snapshot_id ( ) ) ;
228229 }
@@ -251,7 +252,7 @@ impl TransactionAction for RemoveSnapshotAction {
251252 return Ok ( ActionCommit :: new ( vec ! [ ] , vec ! [ ] ) ) ;
252253 }
253254
254- let table_meta = table. metadata ( ) . clone ( ) ;
255+ let table_meta = table. metadata_ref ( ) ;
255256
256257 let mut ids_to_retain = HashSet :: new ( ) ;
257258 let retained_refs = self . compute_retained_refs ( & table_meta. refs , & table_meta) ;
0 commit comments