@@ -144,7 +144,7 @@ impl ExtentMeta {
144
144
}
145
145
}
146
146
147
- #[ derive( Debug , Clone ) ]
147
+ #[ derive( Debug , Copy , Clone ) ]
148
148
#[ allow( clippy:: enum_variant_names) ]
149
149
pub enum ExtentType {
150
150
Data ,
@@ -169,7 +169,7 @@ impl fmt::Display for ExtentType {
169
169
* FileType from the repair client.
170
170
*/
171
171
impl ExtentType {
172
- pub fn to_file_type ( & self ) -> FileType {
172
+ pub fn to_file_type ( self ) -> FileType {
173
173
match self {
174
174
ExtentType :: Data => FileType :: Data ,
175
175
ExtentType :: Db => FileType :: Db ,
@@ -654,15 +654,27 @@ pub(crate) fn move_replacement_extent<P: AsRef<Path>>(
654
654
sync_path ( & original_file, log) ?;
655
655
656
656
// We distinguish between SQLite-backend and raw-file extents based on the
657
- // presence of the `.db` file. Under normal conditions, we should never
658
- // do extent repair across different extent formats; in fact, we should
659
- // never extent repair SQLite-backed extents at all, but must still
660
- // handle the case of unfinished migrations.
661
- // If we are replacing a downstairs, and have created the region empty
662
- // with the plan to replace it, then we can have a mismatch between
663
- // what files we have and what files we want to replace them with. When
664
- // repairing a downstairs, we don't know in advance if the source of our
665
- // repair will be SQLite-backend or not.
657
+ // presence of the `.db` file. We should never do extent repair across
658
+ // different extent formats; it must be SQLite-to-SQLite or raw-to-raw.
659
+ //
660
+ // It is uncommon to perform extent repair on SQLite-backed extents at all,
661
+ // because they are automatically migrated into raw file extents or
662
+ // read-only. However, it must be supported for two cases:
663
+ //
664
+ // - If there was an unfinished replacement, we must finish that replacement
665
+ // before migrating from SQLite -> raw file backend, which happens
666
+ // automatically later in startup.
667
+ // - We use this same code path to perform clones of read-only regions,
668
+ // which may be SQLite-backed (and will never migrate to raw files,
669
+ // because they are read only). This is only the case when the `clone`
670
+ // argument is `true`.
671
+ //
672
+ // In the first case, we know that we are repairing an SQLite-based extent
673
+ // because the target (original) extent includes a `.db` file.
674
+ //
675
+ // In the second case, the target (original) extent is not present, so we
676
+ // check whether the new files include a `.db` file.
677
+
666
678
new_file. set_extension ( "db" ) ;
667
679
original_file. set_extension ( "db" ) ;
668
680
@@ -676,12 +688,6 @@ pub(crate) fn move_replacement_extent<P: AsRef<Path>>(
676
688
e
677
689
) ;
678
690
}
679
- info ! (
680
- log,
681
- "Moved file {:?} to {:?}" ,
682
- new_file. clone( ) ,
683
- original_file. clone( )
684
- ) ;
685
691
sync_path ( & original_file, log) ?;
686
692
687
693
// The .db-shm and .db-wal files may or may not exist. If they don't
@@ -701,14 +707,11 @@ pub(crate) fn move_replacement_extent<P: AsRef<Path>>(
701
707
e
702
708
) ;
703
709
}
704
- info ! (
705
- log,
706
- "Moved db-shm file {:?} to {:?}" ,
707
- new_file. clone( ) ,
708
- original_file. clone( )
709
- ) ;
710
710
sync_path ( & original_file, log) ?;
711
711
} else if original_file. exists ( ) {
712
+ // If we are cloning, then our new region will have been
713
+ // created with Backend::RawFile, and we should have no SQLite
714
+ // files.
712
715
assert ! ( !clone) ;
713
716
info ! (
714
717
log,
@@ -732,14 +735,11 @@ pub(crate) fn move_replacement_extent<P: AsRef<Path>>(
732
735
e
733
736
) ;
734
737
}
735
- info ! (
736
- log,
737
- "Moved db-wal file {:?} to {:?}" ,
738
- new_file. clone( ) ,
739
- original_file. clone( )
740
- ) ;
741
738
sync_path ( & original_file, log) ?;
742
739
} else if original_file. exists ( ) {
740
+ // If we are cloning, then our new region will have been
741
+ // created with Backend::RawFile, and we should have no SQLite
742
+ // files.
743
743
assert ! ( !clone) ;
744
744
info ! (
745
745
log,
0 commit comments