@@ -30,7 +30,9 @@ use risingwave_pb::hummock::{
30
30
} ;
31
31
use tracing:: warn;
32
32
33
- use crate :: change_log:: { ChangeLogDeltaCommon , TableChangeLogCommon } ;
33
+ use crate :: change_log:: {
34
+ ChangeLogDeltaCommon , EpochNewChangeLogCommon , TableChangeLog , TableChangeLogCommon ,
35
+ } ;
34
36
use crate :: compaction_group:: hummock_version_ext:: build_initial_compaction_group_levels;
35
37
use crate :: compaction_group:: StaticCompactionGroupId ;
36
38
use crate :: level:: LevelsCommon ;
@@ -217,18 +219,20 @@ impl HummockVersionStateTableInfo {
217
219
}
218
220
219
221
#[ derive( Debug , Clone , PartialEq ) ]
220
- pub struct HummockVersionCommon < T > {
222
+ pub struct HummockVersionCommon < T , L = T > {
221
223
pub id : HummockVersionId ,
222
224
pub levels : HashMap < CompactionGroupId , LevelsCommon < T > > ,
223
225
#[ deprecated]
224
226
pub ( crate ) max_committed_epoch : u64 ,
225
227
pub table_watermarks : HashMap < TableId , Arc < TableWatermarks > > ,
226
- pub table_change_log : HashMap < TableId , TableChangeLogCommon < T > > ,
228
+ pub table_change_log : HashMap < TableId , TableChangeLogCommon < L > > ,
227
229
pub state_table_info : HummockVersionStateTableInfo ,
228
230
}
229
231
230
232
pub type HummockVersion = HummockVersionCommon < SstableInfo > ;
231
233
234
+ pub type LocalHummockVersion = HummockVersionCommon < SstableInfo , ( ) > ;
235
+
232
236
impl Default for HummockVersion {
233
237
fn default ( ) -> Self {
234
238
HummockVersion :: from ( & PbHummockVersion :: default ( ) )
@@ -433,13 +437,6 @@ impl HummockVersion {
433
437
}
434
438
}
435
439
436
- pub fn table_committed_epoch ( & self , table_id : TableId ) -> Option < u64 > {
437
- self . state_table_info
438
- . info ( )
439
- . get ( & table_id)
440
- . map ( |info| info. committed_epoch )
441
- }
442
-
443
440
pub fn create_init_version ( default_compaction_config : Arc < CompactionConfig > ) -> HummockVersion {
444
441
#[ expect( deprecated) ]
445
442
let mut init_version = HummockVersion {
@@ -476,10 +473,41 @@ impl HummockVersion {
476
473
state_table_info_delta : Default :: default ( ) ,
477
474
}
478
475
}
476
+
477
+ pub fn split_change_log ( mut self ) -> ( LocalHummockVersion , HashMap < TableId , TableChangeLog > ) {
478
+ let table_change_log = {
479
+ let mut table_change_log = HashMap :: new ( ) ;
480
+ for ( table_id, log) in & mut self . table_change_log {
481
+ let change_log_iter =
482
+ log. change_log_iter_mut ( )
483
+ . map ( |item| EpochNewChangeLogCommon {
484
+ new_value : std:: mem:: take ( & mut item. new_value ) ,
485
+ old_value : std:: mem:: take ( & mut item. old_value ) ,
486
+ epochs : item. epochs . clone ( ) ,
487
+ } ) ;
488
+ table_change_log. insert ( * table_id, TableChangeLogCommon :: new ( change_log_iter) ) ;
489
+ }
490
+
491
+ table_change_log
492
+ } ;
493
+
494
+ let local_version = LocalHummockVersion :: from ( self ) ;
495
+
496
+ ( local_version, table_change_log)
497
+ }
498
+ }
499
+
500
+ impl < T , L > HummockVersionCommon < T , L > {
501
+ pub fn table_committed_epoch ( & self , table_id : TableId ) -> Option < u64 > {
502
+ self . state_table_info
503
+ . info ( )
504
+ . get ( & table_id)
505
+ . map ( |info| info. committed_epoch )
506
+ }
479
507
}
480
508
481
509
#[ derive( Debug , PartialEq , Clone ) ]
482
- pub struct HummockVersionDeltaCommon < T > {
510
+ pub struct HummockVersionDeltaCommon < T , L = T > {
483
511
pub id : HummockVersionId ,
484
512
pub prev_id : HummockVersionId ,
485
513
pub group_deltas : HashMap < CompactionGroupId , GroupDeltasCommon < T > > ,
@@ -488,12 +516,14 @@ pub struct HummockVersionDeltaCommon<T> {
488
516
pub trivial_move : bool ,
489
517
pub new_table_watermarks : HashMap < TableId , TableWatermarks > ,
490
518
pub removed_table_ids : HashSet < TableId > ,
491
- pub change_log_delta : HashMap < TableId , ChangeLogDeltaCommon < T > > ,
519
+ pub change_log_delta : HashMap < TableId , ChangeLogDeltaCommon < L > > ,
492
520
pub state_table_info_delta : HashMap < TableId , StateTableInfoDelta > ,
493
521
}
494
522
495
523
pub type HummockVersionDelta = HummockVersionDeltaCommon < SstableInfo > ;
496
524
525
+ pub type LocalHummockVersionDelta = HummockVersionDeltaCommon < SstableInfo , ( ) > ;
526
+
497
527
impl Default for HummockVersionDelta {
498
528
fn default ( ) -> Self {
499
529
HummockVersionDelta :: from ( & PbHummockVersionDelta :: default ( ) )
@@ -1095,3 +1125,64 @@ where
1095
1125
self . into ( )
1096
1126
}
1097
1127
}
1128
+
1129
+ impl From < HummockVersionDelta > for LocalHummockVersionDelta {
1130
+ #[ expect( deprecated) ]
1131
+ fn from ( delta : HummockVersionDelta ) -> Self {
1132
+ Self {
1133
+ id : delta. id ,
1134
+ prev_id : delta. prev_id ,
1135
+ group_deltas : delta. group_deltas ,
1136
+ max_committed_epoch : delta. max_committed_epoch ,
1137
+ trivial_move : delta. trivial_move ,
1138
+ new_table_watermarks : delta. new_table_watermarks ,
1139
+ removed_table_ids : delta. removed_table_ids ,
1140
+ change_log_delta : delta
1141
+ . change_log_delta
1142
+ . into_iter ( )
1143
+ . map ( |( k, v) | {
1144
+ (
1145
+ k,
1146
+ ChangeLogDeltaCommon {
1147
+ truncate_epoch : v. truncate_epoch ,
1148
+ new_log : EpochNewChangeLogCommon {
1149
+ epochs : v. new_log . epochs ,
1150
+ new_value : Vec :: new ( ) ,
1151
+ old_value : Vec :: new ( ) ,
1152
+ } ,
1153
+ } ,
1154
+ )
1155
+ } )
1156
+ . collect ( ) ,
1157
+ state_table_info_delta : delta. state_table_info_delta ,
1158
+ }
1159
+ }
1160
+ }
1161
+
1162
+ impl From < HummockVersion > for LocalHummockVersion {
1163
+ #[ expect( deprecated) ]
1164
+ fn from ( version : HummockVersion ) -> Self {
1165
+ Self {
1166
+ id : version. id ,
1167
+ levels : version. levels ,
1168
+ max_committed_epoch : version. max_committed_epoch ,
1169
+ table_watermarks : version. table_watermarks ,
1170
+ table_change_log : version
1171
+ . table_change_log
1172
+ . into_iter ( )
1173
+ . map ( |( k, v) | {
1174
+ let epoch_new_change_logs: Vec < EpochNewChangeLogCommon < ( ) > > = v
1175
+ . change_log_into_iter ( )
1176
+ . map ( |epoch_new_change_log| EpochNewChangeLogCommon {
1177
+ epochs : epoch_new_change_log. epochs ,
1178
+ new_value : Vec :: new ( ) ,
1179
+ old_value : Vec :: new ( ) ,
1180
+ } )
1181
+ . collect ( ) ;
1182
+ ( k, TableChangeLogCommon :: new ( epoch_new_change_logs) )
1183
+ } )
1184
+ . collect ( ) ,
1185
+ state_table_info : version. state_table_info ,
1186
+ }
1187
+ }
1188
+ }
0 commit comments