@@ -38,25 +38,19 @@ impl CostModelStorageLayer for BackendManager {
38
38
type EpochId = i32 ;
39
39
type StatId = i32 ;
40
40
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 > {
46
43
let new_event = event:: ActiveModel {
47
44
source_variant : sea_orm:: ActiveValue :: Set ( source) ,
48
45
timestamp : sea_orm:: ActiveValue :: Set ( Utc :: now ( ) ) ,
49
46
data : sea_orm:: ActiveValue :: Set ( sea_orm:: JsonValue :: String ( data) ) ,
50
47
..Default :: default ( )
51
48
} ;
52
49
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
- ) ;
57
50
Ok ( insert_res. last_insert_id )
58
51
}
59
52
53
+ /// TODO: documentation
60
54
async fn update_stats_from_catalog (
61
55
& self ,
62
56
c : CatalogSource ,
@@ -154,6 +148,7 @@ impl CostModelStorageLayer for BackendManager {
154
148
}
155
149
}
156
150
151
+ /// TODO: improve the documentation
157
152
/* Update the statistics in the database.
158
153
* The statistic can be newly inserted or updated. If the statistic value
159
154
* is the same as the latest existing one, the update will be ignored, and
@@ -166,14 +161,14 @@ impl CostModelStorageLayer for BackendManager {
166
161
* If the statistic value is the same as the latest existing one, this function
167
162
* won't create a new epoch.
168
163
*
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
170
165
* New epoch option at the first time, and if the epoch_id is returned, the
171
166
* caller can use the returned epoch_id for the rest of the updates.
172
167
* But if the epoch_id is not returned, the caller should continue using
173
168
* the New epoch option for the next statistic update.
174
169
*/
175
170
async fn update_stats (
176
- & mut self ,
171
+ & self ,
177
172
stat : Stat ,
178
173
epoch_option : EpochOption ,
179
174
) -> StorageResult < Option < Self :: EpochId > > {
@@ -270,11 +265,9 @@ impl CostModelStorageLayer for BackendManager {
270
265
}
271
266
} ;
272
267
// 1. Insert into attr_stats and related junction tables.
273
- let mut insert_new_epoch = false ;
274
268
let epoch_id = match epoch_option {
275
269
EpochOption :: Existed ( e) => e,
276
270
EpochOption :: New ( source, data) => {
277
- insert_new_epoch = true ;
278
271
let new_event = event:: ActiveModel {
279
272
source_variant : sea_orm:: ActiveValue :: Set ( source) ,
280
273
timestamp : sea_orm:: ActiveValue :: Set ( Utc :: now ( ) ) ,
@@ -317,19 +310,11 @@ impl CostModelStorageLayer for BackendManager {
317
310
. exec ( & transaction)
318
311
. await ?;
319
312
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
-
329
313
transaction. commit ( ) . await ?;
330
314
Ok ( Some ( epoch_id) )
331
315
}
332
316
317
+ /// TODO: documentation
333
318
async fn store_expr_stats_mappings (
334
319
& self ,
335
320
expr_id : Self :: ExprId ,
@@ -350,6 +335,7 @@ impl CostModelStorageLayer for BackendManager {
350
335
Ok ( ( ) )
351
336
}
352
337
338
+ /// TODO: documentation
353
339
async fn get_stats_for_table (
354
340
& self ,
355
341
table_id : i32 ,
@@ -377,6 +363,7 @@ impl CostModelStorageLayer for BackendManager {
377
363
}
378
364
}
379
365
366
+ /// TODO: documentation
380
367
async fn get_stats_for_attr (
381
368
& self ,
382
369
mut attr_ids : Vec < Self :: AttrId > ,
@@ -414,6 +401,7 @@ impl CostModelStorageLayer for BackendManager {
414
401
}
415
402
}
416
403
404
+ /// TODO: documentation
417
405
async fn get_cost_analysis (
418
406
& self ,
419
407
expr_id : Self :: ExprId ,
@@ -440,6 +428,7 @@ impl CostModelStorageLayer for BackendManager {
440
428
Ok ( cost. map ( |c| c. cost ) )
441
429
}
442
430
431
+ /// TODO: documentation
443
432
async fn store_cost (
444
433
& self ,
445
434
physical_expression_id : Self :: ExprId ,
0 commit comments