Skip to content

Commit 1b64b32

Browse files
committed
metamorphic: fix code around WAL recovery directories
1 parent 3ec1b8d commit 1b64b32

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

metamorphic/meta.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func RunAndCompare(t *testing.T, rootDir string, rOpts ...RunOption) {
241241
cmd := exec.Command(binary, args...)
242242
out, err := cmd.CombinedOutput()
243243
if err != nil {
244-
t.Fatalf(`
244+
t.Fatalf(`error running %v
245245
===== SEED =====
246246
%d
247247
===== ERR =====
@@ -255,6 +255,7 @@ func RunAndCompare(t *testing.T, rootDir string, rOpts ...RunOption) {
255255
===== HISTORY =====
256256
%s
257257
To reduce: go test ./internal/metamorphic -tags invariants -run '%s$' --run-dir %s --try-to-reduce -v`,
258+
cmd.String(),
258259
runOpts.seed,
259260
err,
260261
out,
@@ -523,13 +524,13 @@ func RunOnce(t TestingT, runDir string, seed uint64, historyPath string, rOpts .
523524
testOpts.Threads = runOpts.maxThreads
524525
}
525526

526-
dir := opts.FS.PathJoin(runDir, "data")
527+
dataDir := opts.FS.PathJoin(runDir, "data")
527528
// Set up the initial database state if configured to start from a non-empty
528529
// database. By default tests start from an empty database, but split
529530
// version testing may configure a previous metamorphic tests's database
530531
// state as the initial state.
531532
if testOpts.initialStatePath != "" {
532-
require.NoError(t, setupInitialState(dir, testOpts))
533+
require.NoError(t, setupInitialState(dataDir, testOpts))
533534
}
534535

535536
if testOpts.Opts.WALFailover != nil {
@@ -561,7 +562,7 @@ func RunOnce(t TestingT, runDir string, seed uint64, historyPath string, rOpts .
561562
defer h.Close()
562563

563564
m := newTest(ops)
564-
require.NoError(t, m.init(h, dir, testOpts, runOpts.numInstances, runOpts.opTimeout))
565+
require.NoError(t, m.init(h, dataDir, testOpts, runOpts.numInstances, runOpts.opTimeout))
565566

566567
if err := Execute(m); err != nil {
567568
fmt.Fprintf(os.Stderr, "Seed: %d\n", seed)

metamorphic/options.go

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -953,27 +953,50 @@ func setupInitialState(dataDir string, testOpts *TestOptions) error {
953953
// If the test opts are not configured to use a WAL dir, we add the WAL dir
954954
// as a 'WAL recovery dir' so that we'll read any WALs in the directory in
955955
// 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.
971990
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+
}
9771000
}
9781001
return nil
9791002
}

options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,8 @@ func (o *Options) CheckCompatibility(previousOptions string) error {
21912191
}
21922192
case "Options.wal_dir", "WAL Failover.secondary_dir":
21932193
switch {
2194+
case value == "":
2195+
return nil
21942196
case o.WALDir == value:
21952197
return nil
21962198
case o.WALFailover != nil && o.WALFailover.Secondary.Dirname == value:

0 commit comments

Comments
 (0)