@@ -2682,8 +2682,11 @@ mod tests {
26822682 stdb. release_tx ( read_tx) ;
26832683 }
26842684
2685- // Verify that we can compress snapshots and hardlink them.
2686- // then, verify that we can read the compressed snapshot.
2685+ // Verify that we can compress snapshots and hardlink them,
2686+ // except for the last one, which should be uncompressed.
2687+ // Then, verify that we can read the compressed snapshot.
2688+ //
2689+ // NOTE: `snapshot_watching_compressor` is what filter out the last snapshot
26872690 #[ test]
26882691 fn compress_snapshot_test ( ) -> ResultTest < ( ) > {
26892692 let stdb = TestDB :: in_memory ( ) ?;
@@ -2701,14 +2704,15 @@ mod tests {
27012704 stdb. take_snapshot ( & repo) ?;
27022705
27032706 let total_objects = repo. size_on_disk ( ) ?. object_count ;
2704- // Another snapshot that will hardlink part of the first one
2705- let mut tx = stdb. begin_mut_tx ( IsolationLevel :: Serializable , Workload :: ForTests ) ;
2706- for v in 0 ..10 {
2707- insert ( & stdb, & mut tx, table_id, & product ! [ v] ) ?;
2707+ // Another snapshots that will hardlink part of the first one
2708+ for i in 0 ..2 {
2709+ let mut tx = stdb. begin_mut_tx ( IsolationLevel :: Serializable , Workload :: ForTests ) ;
2710+ for v in 0 ..( 10 + i) {
2711+ insert ( & stdb, & mut tx, table_id, & product ! [ v] ) ?;
2712+ }
2713+ stdb. commit_tx ( tx) ?;
2714+ stdb. take_snapshot ( & repo) ?;
27082715 }
2709- stdb. commit_tx ( tx) ?;
2710-
2711- stdb. take_snapshot ( & repo) ?;
27122716
27132717 let size_compress_off = repo. size_on_disk ( ) ?;
27142718 assert ! (
@@ -2717,23 +2721,25 @@ mod tests {
27172721 ) ;
27182722 let mut offsets = repo. all_snapshots ( ) ?. collect :: < Vec < _ > > ( ) ;
27192723 offsets. sort ( ) ;
2720- assert_eq ! ( & offsets, & [ 1 , 2 ] ) ;
2724+ assert_eq ! ( & offsets, & [ 1 , 2 , 3 ] ) ;
2725+ // Simulate we take except the last snapshot
27212726 assert_eq ! (
2722- SnapshotRepository :: compress_snapshots( & dir, & offsets) ?,
2727+ SnapshotRepository :: compress_snapshots( & dir, & offsets[ .. 2 ] ) ?,
27232728 CompressCount { none: 0 , zstd: 2 }
27242729 ) ;
27252730 let size_compress_on = repo. size_on_disk ( ) ?;
27262731
27272732 assert ! ( size_compress_on. total_size < size_compress_off. total_size) ;
2728-
2733+ let last_compress = offsets [ 1 ] ;
27292734 // Verify we hard-linked the second snapshot
27302735 #[ cfg( unix) ]
27312736 {
2732- let snapshot_dir = dir. snapshot_dir ( offsets [ 1 ] ) ;
2737+ let snapshot_dir = dir. snapshot_dir ( last_compress ) ;
27332738 let mut hard_linked_on = 0 ;
27342739 let mut hard_linked_off = 0 ;
27352740
2736- let ( snapshot, _) = Snapshot :: read_from_file ( & snapshot_dir. snapshot_file ( offsets[ 1 ] ) ) ?;
2741+ let ( snapshot, compress) = Snapshot :: read_from_file ( & snapshot_dir. snapshot_file ( last_compress) ) ?;
2742+ assert_eq ! ( compress, CompressType :: Zstd ) ;
27372743 let repo = SnapshotRepository :: object_repo ( & snapshot_dir) ?;
27382744 for ( _, path) in snapshot. files ( & repo) {
27392745 match path. metadata ( ) ?. nlink ( ) {
@@ -2747,8 +2753,7 @@ mod tests {
27472753
27482754 // Sanity check that we can read the snapshot after compression
27492755 let repo = open_snapshot_repo ( dir, Identity :: ZERO , 0 ) ?;
2750- let last = repo. latest_snapshot ( ) ?;
2751- RelationalDB :: restore_from_snapshot_or_bootstrap ( Identity :: ZERO , Some ( & repo) , last) ?;
2756+ RelationalDB :: restore_from_snapshot_or_bootstrap ( Identity :: ZERO , Some ( & repo) , Some ( last_compress) ) ?;
27522757
27532758 Ok ( ( ) )
27542759 }
0 commit comments