@@ -280,6 +280,16 @@ impl CompressedArchiveSnapshotter {
280
280
. with_context ( || format ! ( "Can not create folder: `{}`" , target_folder. display( ) ) ) ?;
281
281
282
282
for file in & files_to_snapshot {
283
+ // Some files to snapshot are in subfolders (i.e.: in-memory ledger snapshots files)
284
+ if let Some ( parent_dir) = file. parent ( ) {
285
+ let target_parent_dir = target_folder. join ( parent_dir) ;
286
+ if !target_parent_dir. exists ( ) {
287
+ fs:: create_dir_all ( & target_parent_dir) . with_context ( || {
288
+ format ! ( "Can not create folder: `{}`" , target_parent_dir. display( ) )
289
+ } ) ?;
290
+ }
291
+ }
292
+
283
293
let source = self . db_directory . join ( file) ;
284
294
let target = target_folder. join ( file) ;
285
295
tokio:: fs:: copy ( & source, & target) . await . with_context ( || {
@@ -527,7 +537,7 @@ mod tests {
527
537
use super :: * ;
528
538
529
539
#[ tokio:: test]
530
- async fn getting_files_to_include_copy_them_to_a_target_directory_while_keeping_source_dir_structure (
540
+ async fn getting_files_to_include_for_legacy_ledger_snapshot_copy_them_to_a_target_directory_while_keeping_source_dir_structure (
531
541
) {
532
542
let test_dir = temp_dir_create ! ( ) ;
533
543
let cardano_db = DummyCardanoDbBuilder :: new ( current_function ! ( ) )
@@ -557,6 +567,45 @@ mod tests {
557
567
) ;
558
568
}
559
569
570
+ #[ tokio:: test]
571
+ async fn getting_files_to_include_for_in_memory_ledger_snapshot_copy_them_to_a_target_directory_while_keeping_source_dir_structure (
572
+ ) {
573
+ let test_dir = temp_dir_create ! ( ) ;
574
+ let cardano_db = DummyCardanoDbBuilder :: new ( current_function ! ( ) )
575
+ . with_immutables ( & [ 1 , 2 ] )
576
+ . with_in_memory_ledger_snapshots ( & [ 737 ] )
577
+ . build ( ) ;
578
+ let snapshotter =
579
+ snapshotter_for_test ( & test_dir, cardano_db. get_dir ( ) , CompressionAlgorithm :: Gzip ) ;
580
+ let ancillary_snapshot_dir = test_dir. join ( "ancillary_snapshot" ) ;
581
+ fs:: create_dir ( & ancillary_snapshot_dir) . unwrap ( ) ;
582
+
583
+ snapshotter
584
+ . get_files_and_directories_for_ancillary_snapshot ( 1 , & ancillary_snapshot_dir)
585
+ . await
586
+ . unwrap ( ) ;
587
+
588
+ assert_dir_eq ! (
589
+ & ancillary_snapshot_dir,
590
+ format!(
591
+ "* {IMMUTABLE_DIR}/
592
+ ** 00002.chunk
593
+ ** 00002.primary
594
+ ** 00002.secondary
595
+ * {LEDGER_DIR}/
596
+ ** 737/
597
+ *** {}/
598
+ **** {}
599
+ *** {}
600
+ *** {}" ,
601
+ LedgerStateSnapshot :: IN_MEMORY_TABLES ,
602
+ LedgerStateSnapshot :: IN_MEMORY_TVAR ,
603
+ LedgerStateSnapshot :: IN_MEMORY_META ,
604
+ LedgerStateSnapshot :: IN_MEMORY_STATE ,
605
+ )
606
+ ) ;
607
+ }
608
+
560
609
#[ tokio:: test]
561
610
async fn getting_files_to_include_fails_when_no_ledger_file_found ( ) {
562
611
let test_dir = temp_dir_create ! ( ) ;
@@ -695,7 +744,8 @@ mod tests {
695
744
}
696
745
697
746
#[ tokio:: test]
698
- async fn create_archive_generate_sign_and_include_manifest_file ( ) {
747
+ async fn create_archive_of_legacy_ledger_snapshot_generate_sign_and_include_manifest_file ( )
748
+ {
699
749
let test_dir = temp_dir_create ! ( ) ;
700
750
let cardano_db = DummyCardanoDbBuilder :: new ( current_function ! ( ) )
701
751
. with_immutables ( & [ 1 , 2 , 3 ] )
@@ -744,6 +794,76 @@ mod tests {
744
794
manifest. signature
745
795
)
746
796
}
797
+
798
+ #[ tokio:: test]
799
+ async fn create_archive_of_in_memory_ledger_snapshot_generate_sign_and_include_manifest_file (
800
+ ) {
801
+ let test_dir = temp_dir_create ! ( ) ;
802
+ let cardano_db = DummyCardanoDbBuilder :: new ( current_function ! ( ) )
803
+ . with_immutables ( & [ 1 , 2 , 3 ] )
804
+ . with_in_memory_ledger_snapshots ( & [ 537 , 637 , 737 ] )
805
+ . with_non_immutables ( & [ "not_to_include.txt" ] )
806
+ . build ( ) ;
807
+ File :: create ( cardano_db. get_dir ( ) . join ( "not_to_include_as_well.txt" ) ) . unwrap ( ) ;
808
+
809
+ let snapshotter = CompressedArchiveSnapshotter {
810
+ ancillary_signer : Arc :: new ( MockAncillarySigner :: that_succeeds_with_signature (
811
+ fake_keys:: signable_manifest_signature ( ) [ 0 ] ,
812
+ ) ) ,
813
+ ..snapshotter_for_test ( & test_dir, cardano_db. get_dir ( ) , CompressionAlgorithm :: Gzip )
814
+ } ;
815
+
816
+ let archive = snapshotter
817
+ . snapshot_ancillary ( 2 , "ancillary" )
818
+ . await
819
+ . unwrap ( ) ;
820
+ let unpacked = archive. unpack_gzip ( test_dir) ;
821
+ let manifest_path = unpacked. join ( AncillaryFilesManifest :: ANCILLARY_MANIFEST_FILE_NAME ) ;
822
+
823
+ assert ! ( manifest_path. exists( ) ) ;
824
+
825
+ let manifest = serde_json:: from_reader :: < _ , AncillaryFilesManifest > (
826
+ File :: open ( & manifest_path) . unwrap ( ) ,
827
+ )
828
+ . unwrap ( ) ;
829
+
830
+ assert_eq ! (
831
+ vec![
832
+ & PathBuf :: from( IMMUTABLE_DIR ) . join( "00003.chunk" ) ,
833
+ & PathBuf :: from( IMMUTABLE_DIR ) . join( "00003.primary" ) ,
834
+ & PathBuf :: from( IMMUTABLE_DIR ) . join( "00003.secondary" ) ,
835
+ & PathBuf :: from( LEDGER_DIR )
836
+ . join( "637" )
837
+ . join( LedgerStateSnapshot :: IN_MEMORY_META ) ,
838
+ & PathBuf :: from( LEDGER_DIR )
839
+ . join( "637" )
840
+ . join( LedgerStateSnapshot :: IN_MEMORY_STATE ) ,
841
+ & PathBuf :: from( LEDGER_DIR )
842
+ . join( "637" )
843
+ . join( LedgerStateSnapshot :: IN_MEMORY_TABLES )
844
+ . join( LedgerStateSnapshot :: IN_MEMORY_TVAR ) ,
845
+ & PathBuf :: from( LEDGER_DIR )
846
+ . join( "737" )
847
+ . join( LedgerStateSnapshot :: IN_MEMORY_META ) ,
848
+ & PathBuf :: from( LEDGER_DIR )
849
+ . join( "737" )
850
+ . join( LedgerStateSnapshot :: IN_MEMORY_STATE ) ,
851
+ & PathBuf :: from( LEDGER_DIR )
852
+ . join( "737" )
853
+ . join( LedgerStateSnapshot :: IN_MEMORY_TABLES )
854
+ . join( LedgerStateSnapshot :: IN_MEMORY_TVAR ) ,
855
+ ] ,
856
+ manifest. data. keys( ) . collect:: <Vec <_>>( )
857
+ ) ;
858
+ assert_eq ! (
859
+ Some (
860
+ fake_keys:: signable_manifest_signature( ) [ 0 ]
861
+ . try_into( )
862
+ . unwrap( )
863
+ ) ,
864
+ manifest. signature
865
+ )
866
+ }
747
867
}
748
868
749
869
mod compute_immutable_total_and_average_uncompressed_size {
0 commit comments