@@ -91,6 +91,8 @@ pub(crate) struct SnapshotProduceAction<'a> {
91
91
manifest_counter : RangeFrom < u64 > ,
92
92
93
93
new_data_file_sequence_number : Option < i64 > ,
94
+
95
+ target_branch : String ,
94
96
}
95
97
96
98
impl < ' a > SnapshotProduceAction < ' a > {
@@ -115,6 +117,7 @@ impl<'a> SnapshotProduceAction<'a> {
115
117
manifest_counter : ( 0 ..) ,
116
118
key_metadata,
117
119
new_data_file_sequence_number : None ,
120
+ target_branch : MAIN_BRANCH . to_string ( ) ,
118
121
} )
119
122
}
120
123
@@ -426,28 +429,39 @@ impl<'a> SnapshotProduceAction<'a> {
426
429
let new_manifests = self
427
430
. manifest_file ( & snapshot_produce_operation, & process)
428
431
. await ?;
432
+
429
433
let next_seq_num = self . tx . current_table . metadata ( ) . next_sequence_number ( ) ;
430
434
431
435
let summary = self . summary ( & snapshot_produce_operation) ;
432
436
433
437
let manifest_list_path = self . generate_manifest_list_file_path ( 0 ) ;
434
438
439
+ let parent_snapshot = self
440
+ . tx
441
+ . current_table
442
+ . metadata ( )
443
+ . snapshot_for_ref ( & self . target_branch ) ;
444
+
445
+ let parent_snapshot_id = parent_snapshot
446
+ . map ( |s| Some ( s. snapshot_id ( ) ) )
447
+ . unwrap_or ( None ) ;
448
+
435
449
let mut manifest_list_writer = match self . tx . current_table . metadata ( ) . format_version ( ) {
436
450
FormatVersion :: V1 => ManifestListWriter :: v1 (
437
451
self . tx
438
452
. current_table
439
453
. file_io ( )
440
454
. new_output ( manifest_list_path. clone ( ) ) ?,
441
455
self . snapshot_id ,
442
- self . tx . current_table . metadata ( ) . current_snapshot_id ( ) ,
456
+ parent_snapshot_id ,
443
457
) ,
444
458
FormatVersion :: V2 => ManifestListWriter :: v2 (
445
459
self . tx
446
460
. current_table
447
461
. file_io ( )
448
462
. new_output ( manifest_list_path. clone ( ) ) ?,
449
463
self . snapshot_id ,
450
- self . tx . current_table . metadata ( ) . current_snapshot_id ( ) ,
464
+ parent_snapshot_id ,
451
465
next_seq_num,
452
466
) ,
453
467
} ;
@@ -458,7 +472,7 @@ impl<'a> SnapshotProduceAction<'a> {
458
472
let new_snapshot = Snapshot :: builder ( )
459
473
. with_manifest_list ( manifest_list_path)
460
474
. with_snapshot_id ( self . snapshot_id )
461
- . with_parent_snapshot_id ( self . tx . current_table . metadata ( ) . current_snapshot_id ( ) )
475
+ . with_parent_snapshot_id ( parent_snapshot_id )
462
476
. with_sequence_number ( next_seq_num)
463
477
. with_summary ( summary)
464
478
. with_schema_id ( self . tx . current_table . metadata ( ) . current_schema_id ( ) )
@@ -471,7 +485,7 @@ impl<'a> SnapshotProduceAction<'a> {
471
485
snapshot: new_snapshot,
472
486
} ,
473
487
TableUpdate :: SetSnapshotRef {
474
- ref_name: MAIN_BRANCH . to_string ( ) ,
488
+ ref_name: self . target_branch . clone ( ) ,
475
489
reference: SnapshotReference :: new(
476
490
self . snapshot_id,
477
491
SnapshotRetention :: branch( None , None , None ) ,
@@ -483,8 +497,8 @@ impl<'a> SnapshotProduceAction<'a> {
483
497
uuid: self . tx. current_table. metadata( ) . uuid( ) ,
484
498
} ,
485
499
TableRequirement :: RefSnapshotIdMatch {
486
- r#ref: MAIN_BRANCH . to_string ( ) ,
487
- snapshot_id: self . tx . current_table . metadata ( ) . current_snapshot_id ( ) ,
500
+ r#ref: self . target_branch . clone ( ) ,
501
+ snapshot_id: parent_snapshot_id ,
488
502
} ,
489
503
] ,
490
504
) ?;
@@ -494,6 +508,10 @@ impl<'a> SnapshotProduceAction<'a> {
494
508
pub fn set_new_data_file_sequence_number ( & mut self , new_data_file_sequence_number : i64 ) {
495
509
self . new_data_file_sequence_number = Some ( new_data_file_sequence_number) ;
496
510
}
511
+
512
+ pub fn set_target_branch ( & mut self , target_branch : String ) {
513
+ self . target_branch = target_branch;
514
+ }
497
515
}
498
516
499
517
pub ( crate ) struct MergeManifestProcess {
@@ -519,6 +537,7 @@ impl ManifestProcess for MergeManifestProcess {
519
537
let ( unmerge_data_manifest, unmerge_delete_manifest) : ( Vec < _ > , Vec < _ > ) = manifests
520
538
. into_iter ( )
521
539
. partition ( |manifest| matches ! ( manifest. content, ManifestContentType :: Data ) ) ;
540
+
522
541
let mut data_manifest = {
523
542
let manifest_merge_manager = MergeManifestManager :: new (
524
543
self . target_size_bytes ,
@@ -529,6 +548,7 @@ impl ManifestProcess for MergeManifestProcess {
529
548
. merge_manifest ( snapshot_produce, unmerge_data_manifest)
530
549
. await ?
531
550
} ;
551
+
532
552
data_manifest. extend ( unmerge_delete_manifest) ;
533
553
Ok ( data_manifest)
534
554
}
0 commit comments