@@ -38,25 +38,19 @@ impl CostModelStorageLayer for BackendManager {
3838 type EpochId = i32 ;
3939 type StatId = i32 ;
4040
41- async fn create_new_epoch (
42- & mut self ,
43- source : String ,
44- data : String ,
45- ) -> StorageResult < Self :: EpochId > {
41+ /// TODO: documentation
42+ async fn create_new_epoch ( & self , source : String , data : String ) -> StorageResult < Self :: EpochId > {
4643 let new_event = event:: ActiveModel {
4744 source_variant : sea_orm:: ActiveValue :: Set ( source) ,
4845 timestamp : sea_orm:: ActiveValue :: Set ( Utc :: now ( ) ) ,
4946 data : sea_orm:: ActiveValue :: Set ( sea_orm:: JsonValue :: String ( data) ) ,
5047 ..Default :: default ( )
5148 } ;
5249 let insert_res = Event :: insert ( new_event) . exec ( & self . db ) . await ?;
53- self . latest_epoch_id . store (
54- insert_res. last_insert_id as usize ,
55- std:: sync:: atomic:: Ordering :: Relaxed ,
56- ) ;
5750 Ok ( insert_res. last_insert_id )
5851 }
5952
53+ /// TODO: documentation
6054 async fn update_stats_from_catalog (
6155 & self ,
6256 c : CatalogSource ,
@@ -154,6 +148,7 @@ impl CostModelStorageLayer for BackendManager {
154148 }
155149 }
156150
151+ /// TODO: improve the documentation
157152 /* Update the statistics in the database.
158153 * The statistic can be newly inserted or updated. If the statistic value
159154 * is the same as the latest existing one, the update will be ignored, and
@@ -166,14 +161,14 @@ impl CostModelStorageLayer for BackendManager {
166161 * If the statistic value is the same as the latest existing one, this function
167162 * won't create a new epoch.
168163 *
169- * For batch updates, if the caller can directly call this function with
164+ * For batch updates, the caller can directly call this function with
170165 * New epoch option at the first time, and if the epoch_id is returned, the
171166 * caller can use the returned epoch_id for the rest of the updates.
172167 * But if the epoch_id is not returned, the caller should continue using
173168 * the New epoch option for the next statistic update.
174169 */
175170 async fn update_stats (
176- & mut self ,
171+ & self ,
177172 stat : Stat ,
178173 epoch_option : EpochOption ,
179174 ) -> StorageResult < Option < Self :: EpochId > > {
@@ -270,11 +265,9 @@ impl CostModelStorageLayer for BackendManager {
270265 }
271266 } ;
272267 // 1. Insert into attr_stats and related junction tables.
273- let mut insert_new_epoch = false ;
274268 let epoch_id = match epoch_option {
275269 EpochOption :: Existed ( e) => e,
276270 EpochOption :: New ( source, data) => {
277- insert_new_epoch = true ;
278271 let new_event = event:: ActiveModel {
279272 source_variant : sea_orm:: ActiveValue :: Set ( source) ,
280273 timestamp : sea_orm:: ActiveValue :: Set ( Utc :: now ( ) ) ,
@@ -317,19 +310,11 @@ impl CostModelStorageLayer for BackendManager {
317310 . exec ( & transaction)
318311 . await ?;
319312
320- // TODO(lanlou): consider the update conflict for latest_epoch_id in multiple threads
321- // Assume the txn fails to commit, and the epoch_id is updated. But the epoch_id
322- // is always increasing and won't be overwritten even if the record is deleted, it
323- // might be fine.
324- if insert_new_epoch {
325- self . latest_epoch_id
326- . store ( epoch_id as usize , std:: sync:: atomic:: Ordering :: Relaxed ) ;
327- }
328-
329313 transaction. commit ( ) . await ?;
330314 Ok ( Some ( epoch_id) )
331315 }
332316
317+ /// TODO: documentation
333318 async fn store_expr_stats_mappings (
334319 & self ,
335320 expr_id : Self :: ExprId ,
@@ -350,6 +335,7 @@ impl CostModelStorageLayer for BackendManager {
350335 Ok ( ( ) )
351336 }
352337
338+ /// TODO: documentation
353339 async fn get_stats_for_table (
354340 & self ,
355341 table_id : i32 ,
@@ -377,6 +363,7 @@ impl CostModelStorageLayer for BackendManager {
377363 }
378364 }
379365
366+ /// TODO: documentation
380367 async fn get_stats_for_attr (
381368 & self ,
382369 mut attr_ids : Vec < Self :: AttrId > ,
@@ -414,6 +401,7 @@ impl CostModelStorageLayer for BackendManager {
414401 }
415402 }
416403
404+ /// TODO: documentation
417405 async fn get_cost_analysis (
418406 & self ,
419407 expr_id : Self :: ExprId ,
@@ -440,6 +428,7 @@ impl CostModelStorageLayer for BackendManager {
440428 Ok ( cost. map ( |c| c. cost ) )
441429 }
442430
431+ /// TODO: documentation
443432 async fn store_cost (
444433 & self ,
445434 physical_expression_id : Self :: ExprId ,
0 commit comments