Skip to content

Commit ba96148

Browse files
committed
pebble: fix wal recovery dir lock acquisition in Open
Do not attempt to reacquire lock on the wal recovery dir when it is the same as the dir being opened. Fixes: #5051
1 parent 6feecba commit ba96148

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

open.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,12 @@ func Open(dirname string, opts *Options) (db *DB, err error) {
395395
}()
396396
for i, dir := range opts.WALRecoveryDirs {
397397
dir.Dirname = resolveStorePath(dirname, dir.Dirname)
398-
// Acquire a lock on the WAL recovery directory.
399-
walRecoveryLocks[i], err = base.AcquireOrValidateDirectoryLock(dir.Lock, dir.Dirname, dir.FS)
400-
if err != nil {
401-
return nil, errors.Wrapf(err, "error acquiring lock on WAL recovery directory %q", dir.Dirname)
398+
if dir.Dirname != dirname {
399+
// Acquire a lock on the WAL recovery directory.
400+
walRecoveryLocks[i], err = base.AcquireOrValidateDirectoryLock(dir.Lock, dir.Dirname, dir.FS)
401+
if err != nil {
402+
return nil, errors.Wrapf(err, "error acquiring lock on WAL recovery directory %q", dir.Dirname)
403+
}
402404
}
403405
walDirs = append(walDirs, dir)
404406
}

open_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ func TestOpenAlreadyLocked(t *testing.T) {
427427
Secondary: wal.Dir{FS: fs, Dirname: opts.WALFailover.Secondary.Dirname},
428428
},
429429
FS: fs,
430+
// Setting the recovery dir to be the same as the dir being opened should not error.
431+
WALRecoveryDirs: []wal.Dir{{FS: fs, Dirname: dataDir2}},
430432
})
431433
_, err := Open(dataDir2, opts2)
432434
require.Error(t, err, "Expected error when opening another database with the same secondary WAL directory")

0 commit comments

Comments
 (0)