@@ -1048,7 +1048,8 @@ type Options struct {
10481048 // the current database state.
10491049 //
10501050 // If a previous WAL configuration may have stored WALs elsewhere but there
1051- // is not a corresponding entry in WALRecoveryDirs, Open will error.
1051+ // is not a corresponding entry in WALRecoveryDirs, Open will error (unless
1052+ // Unsafe.AllowMissingWALDirs is true).
10521053 WALRecoveryDirs []wal.Dir
10531054
10541055 // WALMinSyncInterval is the minimum duration between syncs of the WAL. If
@@ -1109,6 +1110,19 @@ type Options struct {
11091110 // preemptively reduce internal fragmentation when loaded into the block cache.
11101111 AllocatorSizeClasses []int
11111112
1113+ // Unsafe contains options that must be used very carefully and in exceptional
1114+ // circumstances.
1115+ Unsafe struct {
1116+ // AllowMissingWALDirs, if set to true, allows opening a DB when the WAL or
1117+ // WAL secondary directory was changed and the previous directory is not in
1118+ // WALRecoveryDirs. This can be used to move WALs without having to keep the
1119+ // previous directory in the options forever.
1120+ //
1121+ // CAUTION: Enabling this option will lead to data loss if the missing
1122+ // directory contained any WAL files that were not flushed to sstables.
1123+ AllowMissingWALDirs bool
1124+ }
1125+
11121126 // private options are only used by internal tests or are used internally
11131127 // for facilitating upgrade paths of unconfigurable functionality.
11141128 private struct {
@@ -2334,6 +2348,11 @@ func (o *Options) checkWALDir(storeDir, walDir, errContext string) error {
23342348 }
23352349 }
23362350
2351+ if o .Unsafe .AllowMissingWALDirs {
2352+ o .Logger .Infof ("directory %q may contain relevant WALs but is not in WALRecoveryDirs (AllowMissingWALDirs enabled)" , walDir )
2353+ return nil
2354+ }
2355+
23372356 var buf bytes.Buffer
23382357 fmt .Fprintf (& buf , "\n %s\n " , errContext )
23392358 fmt .Fprintf (& buf , " o.WALDir: %q\n " , o .WALDir )
@@ -2344,6 +2363,7 @@ func (o *Options) checkWALDir(storeDir, walDir, errContext string) error {
23442363 for _ , d := range o .WALRecoveryDirs {
23452364 fmt .Fprintf (& buf , "\n %q" , d .Dirname )
23462365 }
2366+
23472367 return ErrMissingWALRecoveryDir {Dir : walPath , ExtraInfo : buf .String ()}
23482368}
23492369
0 commit comments