@@ -953,27 +953,50 @@ func setupInitialState(dataDir string, testOpts *TestOptions) error {
953
953
// If the test opts are not configured to use a WAL dir, we add the WAL dir
954
954
// as a 'WAL recovery dir' so that we'll read any WALs in the directory in
955
955
// Open.
956
- walRecoveryPath := testOpts .Opts .FS .PathJoin (dataDir , "wal" )
957
- if testOpts .Opts .WALDir != "" {
958
- // If the test opts are configured to use a WAL dir, we add the data
959
- // directory itself as a 'WAL recovery dir' so that we'll read any WALs if
960
- // the previous test was writing them to the data directory.
961
- walRecoveryPath = dataDir
962
- }
963
- testOpts .Opts .WALRecoveryDirs = append (testOpts .Opts .WALRecoveryDirs , wal.Dir {
964
- FS : testOpts .Opts .FS ,
965
- Dirname : walRecoveryPath ,
966
- })
967
-
968
- // If the failover dir exists and the test opts are not configured to use
969
- // WAL failover, add the failover directory as a 'WAL recovery dir' in case
970
- // the previous test was configured to use failover.
956
+ fs := testOpts .Opts .FS
957
+ walRecoveryPath := fs .PathJoin (dataDir , "wal" )
958
+ if _ , err := fs .Stat (walRecoveryPath ); err == nil {
959
+ // Previous test used a WAL dir.
960
+ if testOpts .Opts .WALDir == "" {
961
+ // This test is not using a WAL dir. Add the previous WAL dir as a
962
+ // recovery dir.
963
+ testOpts .Opts .WALRecoveryDirs = append (testOpts .Opts .WALRecoveryDirs , wal.Dir {
964
+ FS : fs ,
965
+ Dirname : pebble .MakeStoreRelativePath (fs , "wal" ),
966
+ })
967
+ } else {
968
+ // Both the previous test and the current test are using a WAL dir. We
969
+ // assume that they are the same.
970
+ if testOpts .Opts .WALDir != pebble .MakeStoreRelativePath (fs , "wal" ) {
971
+ return errors .Errorf ("unsupported wal dir value %q" , testOpts .Opts .WALDir )
972
+ }
973
+ }
974
+ } else {
975
+ // Previous test did not use a WAL dir.
976
+ if testOpts .Opts .WALDir != "" {
977
+ // The current test is using a WAL dir; we add the data directory itself
978
+ // as a 'WAL recovery dir' so that we'll read any WALs if the previous
979
+ // test was writing them to the data directory.
980
+ testOpts .Opts .WALRecoveryDirs = append (testOpts .Opts .WALRecoveryDirs , wal.Dir {
981
+ FS : fs ,
982
+ Dirname : pebble .MakeStoreRelativePath (fs , "" ),
983
+ })
984
+ }
985
+ }
986
+
987
+ // If the previous test used WAL failover and this test does not use failover,
988
+ // add the failover directory as a 'WAL recovery dir' in case the previous
989
+ // test was configured to use failover.
971
990
failoverDir := testOpts .Opts .FS .PathJoin (dataDir , "wal_secondary" )
972
- if _ , err := testOpts .Opts .FS .Stat (failoverDir ); err == nil && testOpts .Opts .WALFailover == nil {
973
- testOpts .Opts .WALRecoveryDirs = append (testOpts .Opts .WALRecoveryDirs , wal.Dir {
974
- FS : testOpts .Opts .FS ,
975
- Dirname : failoverDir ,
976
- })
991
+ if _ , err := testOpts .Opts .FS .Stat (failoverDir ); err == nil {
992
+ if testOpts .Opts .WALFailover == nil {
993
+ testOpts .Opts .WALRecoveryDirs = append (testOpts .Opts .WALRecoveryDirs , wal.Dir {
994
+ FS : testOpts .Opts .FS ,
995
+ Dirname : pebble .MakeStoreRelativePath (testOpts .Opts .FS , "wal_secondary" ),
996
+ })
997
+ } else if testOpts .Opts .WALFailover .Secondary .Dirname != pebble .MakeStoreRelativePath (testOpts .Opts .FS , "wal_secondary" ) {
998
+ return errors .Errorf ("unsupported wal failover dir value %q" , testOpts .Opts .WALFailover .Secondary .Dirname )
999
+ }
977
1000
}
978
1001
return nil
979
1002
}
0 commit comments