Skip to content

Commit

Permalink
Merge pull request #18574 from lucasrod16/18571-ensure-consistent-per…
Browse files Browse the repository at this point in the history
…missions-for-broken-WAL-files

Ensure consistent file permissions on broken WAL files
  • Loading branch information
serathius authored Sep 17, 2024
2 parents 4b8655e + d12bb7e commit 2ed418c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/storage/wal/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Repair(lg *zap.Logger, dirpath string) bool {

case errors.Is(err, io.ErrUnexpectedEOF):
brokenName := f.Name() + ".broken"
bf, bferr := os.Create(brokenName)
bf, bferr := os.OpenFile(brokenName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fileutil.PrivateFileMode)
if bferr != nil {
lg.Warn("failed to create backup file", zap.String("path", brokenName), zap.Error(bferr))
return false
Expand Down
10 changes: 10 additions & 0 deletions server/storage/wal/repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"

"go.etcd.io/etcd/client/pkg/v3/fileutil"
"go.etcd.io/etcd/server/v3/storage/wal/walpb"
"go.etcd.io/raft/v3/raftpb"
)
Expand Down Expand Up @@ -77,6 +79,14 @@ func testRepair(t *testing.T, ents [][]raftpb.Entry, corrupt corruptFunc, expect
// repair the wal
require.True(t, Repair(lg, p), "'Repair' returned 'false', want 'true'")

// verify the broken wal has correct permissions
bf := filepath.Join(p, filepath.Base(w.tail().Name())+".broken")
fi, err := os.Stat(bf)
require.NoError(t, err)
expectedPerms := fmt.Sprintf("%o", os.FileMode(fileutil.PrivateFileMode))
actualPerms := fmt.Sprintf("%o", fi.Mode().Perm())
require.Equal(t, expectedPerms, actualPerms, "unexpected file permissions on .broken wal")

// read it back
w, err = Open(lg, p, walpb.Snapshot{})
require.NoError(t, err)
Expand Down

0 comments on commit 2ed418c

Please sign in to comment.