@@ -91,6 +91,8 @@ pub(crate) struct SnapshotProduceAction<'a> {
9191 manifest_counter : RangeFrom < u64 > ,
9292
9393 new_data_file_sequence_number : Option < i64 > ,
94+
95+ target_branch : String ,
9496}
9597
9698impl < ' a > SnapshotProduceAction < ' a > {
@@ -115,6 +117,7 @@ impl<'a> SnapshotProduceAction<'a> {
115117 manifest_counter : ( 0 ..) ,
116118 key_metadata,
117119 new_data_file_sequence_number : None ,
120+ target_branch : MAIN_BRANCH . to_string ( ) ,
118121 } )
119122 }
120123
@@ -426,28 +429,39 @@ impl<'a> SnapshotProduceAction<'a> {
426429 let new_manifests = self
427430 . manifest_file ( & snapshot_produce_operation, & process)
428431 . await ?;
432+
429433 let next_seq_num = self . tx . current_table . metadata ( ) . next_sequence_number ( ) ;
430434
431435 let summary = self . summary ( & snapshot_produce_operation) ;
432436
433437 let manifest_list_path = self . generate_manifest_list_file_path ( 0 ) ;
434438
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+
435449 let mut manifest_list_writer = match self . tx . current_table . metadata ( ) . format_version ( ) {
436450 FormatVersion :: V1 => ManifestListWriter :: v1 (
437451 self . tx
438452 . current_table
439453 . file_io ( )
440454 . new_output ( manifest_list_path. clone ( ) ) ?,
441455 self . snapshot_id ,
442- self . tx . current_table . metadata ( ) . current_snapshot_id ( ) ,
456+ parent_snapshot_id ,
443457 ) ,
444458 FormatVersion :: V2 => ManifestListWriter :: v2 (
445459 self . tx
446460 . current_table
447461 . file_io ( )
448462 . new_output ( manifest_list_path. clone ( ) ) ?,
449463 self . snapshot_id ,
450- self . tx . current_table . metadata ( ) . current_snapshot_id ( ) ,
464+ parent_snapshot_id ,
451465 next_seq_num,
452466 ) ,
453467 } ;
@@ -458,7 +472,7 @@ impl<'a> SnapshotProduceAction<'a> {
458472 let new_snapshot = Snapshot :: builder ( )
459473 . with_manifest_list ( manifest_list_path)
460474 . 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 )
462476 . with_sequence_number ( next_seq_num)
463477 . with_summary ( summary)
464478 . with_schema_id ( self . tx . current_table . metadata ( ) . current_schema_id ( ) )
@@ -471,7 +485,7 @@ impl<'a> SnapshotProduceAction<'a> {
471485 snapshot: new_snapshot,
472486 } ,
473487 TableUpdate :: SetSnapshotRef {
474- ref_name: MAIN_BRANCH . to_string ( ) ,
488+ ref_name: self . target_branch . clone ( ) ,
475489 reference: SnapshotReference :: new(
476490 self . snapshot_id,
477491 SnapshotRetention :: branch( None , None , None ) ,
@@ -483,8 +497,8 @@ impl<'a> SnapshotProduceAction<'a> {
483497 uuid: self . tx. current_table. metadata( ) . uuid( ) ,
484498 } ,
485499 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 ,
488502 } ,
489503 ] ,
490504 ) ?;
@@ -494,6 +508,10 @@ impl<'a> SnapshotProduceAction<'a> {
494508 pub fn set_new_data_file_sequence_number ( & mut self , new_data_file_sequence_number : i64 ) {
495509 self . new_data_file_sequence_number = Some ( new_data_file_sequence_number) ;
496510 }
511+
512+ pub fn set_target_branch ( & mut self , target_branch : String ) {
513+ self . target_branch = target_branch;
514+ }
497515}
498516
499517pub ( crate ) struct MergeManifestProcess {
@@ -519,6 +537,7 @@ impl ManifestProcess for MergeManifestProcess {
519537 let ( unmerge_data_manifest, unmerge_delete_manifest) : ( Vec < _ > , Vec < _ > ) = manifests
520538 . into_iter ( )
521539 . partition ( |manifest| matches ! ( manifest. content, ManifestContentType :: Data ) ) ;
540+
522541 let mut data_manifest = {
523542 let manifest_merge_manager = MergeManifestManager :: new (
524543 self . target_size_bytes ,
@@ -529,6 +548,7 @@ impl ManifestProcess for MergeManifestProcess {
529548 . merge_manifest ( snapshot_produce, unmerge_data_manifest)
530549 . await ?
531550 } ;
551+
532552 data_manifest. extend ( unmerge_delete_manifest) ;
533553 Ok ( data_manifest)
534554 }
0 commit comments