@@ -1128,7 +1128,8 @@ type Options struct {
11281128 // the current database state.
11291129 //
11301130 // If a previous WAL configuration may have stored WALs elsewhere but there
1131- // is not a corresponding entry in WALRecoveryDirs, Open will error.
1131+ // is not a corresponding entry in WALRecoveryDirs, Open will error (unless
1132+ // Unsafe.AllowMissingWALDirs is true).
11321133 WALRecoveryDirs []wal.Dir
11331134
11341135 // WALMinSyncInterval is the minimum duration between syncs of the WAL. If
@@ -1159,6 +1160,19 @@ type Options struct {
11591160 // preemptively reduce internal fragmentation when loaded into the block cache.
11601161 AllocatorSizeClasses []int
11611162
1163+ // Unsafe contains options that must be used very carefully and in exceptional
1164+ // circumstances.
1165+ Unsafe struct {
1166+ // AllowMissingWALDirs, if set to true, allows opening a DB when the WAL or
1167+ // WAL secondary directory was changed and the previous directory is not in
1168+ // WALRecoveryDirs. This can be used to move WALs without having to keep the
1169+ // previous directory in the options forever.
1170+ //
1171+ // CAUTION: Enabling this option will lead to data loss if the missing
1172+ // directory contained any WAL files that were not flushed to sstables.
1173+ AllowMissingWALDirs bool
1174+ }
1175+
11621176 // private options are only used by internal tests or are used internally
11631177 // for facilitating upgrade paths of unconfigurable functionality.
11641178 private struct {
@@ -2482,6 +2496,11 @@ func (o *Options) checkWALDir(storeDir, walDir, errContext string) error {
24822496 }
24832497 }
24842498
2499+ if o .Unsafe .AllowMissingWALDirs {
2500+ o .Logger .Infof ("directory %q may contain relevant WALs but is not in WALRecoveryDirs (AllowMissingWALDirs enabled)" , walDir )
2501+ return nil
2502+ }
2503+
24852504 var buf bytes.Buffer
24862505 fmt .Fprintf (& buf , "\n %s\n " , errContext )
24872506 fmt .Fprintf (& buf , " o.WALDir: %q\n " , o .WALDir )
@@ -2492,6 +2511,7 @@ func (o *Options) checkWALDir(storeDir, walDir, errContext string) error {
24922511 for _ , d := range o .WALRecoveryDirs {
24932512 fmt .Fprintf (& buf , "\n %q" , d .Dirname )
24942513 }
2514+
24952515 return ErrMissingWALRecoveryDir {Dir : walPath , ExtraInfo : buf .String ()}
24962516}
24972517
0 commit comments