Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop ensurewriter wrapper #42062

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libbeat/statestore/backend/memlog/diskstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (s *diskstore) tryOpenLog() error {
ok = true
s.logNeedsTruncate = false
s.logFile = f
s.logBuf = bufio.NewWriterSize(&ensureWriter{s.logFile}, s.bufferSize)
s.logBuf = bufio.NewWriterSize(s.logFile, s.bufferSize)
return nil
}

Expand Down Expand Up @@ -346,7 +346,7 @@ func (s *diskstore) checkpointTmpFile(tempfile string, states map[string]entry)
f.Close()
})

writer := bufio.NewWriterSize(&ensureWriter{f}, s.bufferSize)
writer := bufio.NewWriterSize(f, s.bufferSize)
enc := newJSONEncoder(writer)
if _, err = writer.Write([]byte{'['}); err != nil {
return "", err
Expand Down Expand Up @@ -650,7 +650,7 @@ func writeMetaFile(home string, mode os.FileMode) error {
f.Close()
})

enc := newJSONEncoder(&ensureWriter{f})
enc := newJSONEncoder(f)
err = enc.Encode(storeMeta{
Version: storeVersion,
})
Expand Down
26 changes: 0 additions & 26 deletions libbeat/statestore/backend/memlog/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@
"syscall"
)

// ensureWriter writes the buffer to the underlying writer
// for as long as w returns a retryable error (e.g. EAGAIN)
// or the input buffer has been exhausted.
//
// XXX: this code was written and tested with go1.13 and go1.14, which does not
// handled EINTR. Some users report EINTR getting triggered more often in
// go1.14 due to changes in the signal handling for implementing
// preemption.
// In future versions EINTR will be handled by go for us.
// See: https://github.com/golang/go/issues/38033
type ensureWriter struct {
w io.Writer
}

// countWriter keeps track of the amount of bytes written over time.
type countWriter struct {
n uint64
Expand All @@ -50,20 +36,8 @@
return n, err
}

func (e *ensureWriter) Write(p []byte) (int, error) {
var N int
for len(p) > 0 {
n, err := e.w.Write(p)
N, p = N+n, p[n:]
if err != nil && !isRetryErr(err) {
return N, err
}
}
return N, nil
}

func isRetryErr(err error) bool {
return err == syscall.EINTR || err == syscall.EAGAIN

Check failure on line 40 in libbeat/statestore/backend/memlog/util.go

View workflow job for this annotation

GitHub Actions / lint (linux)

comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
}

// trySyncPath provides a best-effort fsync on path (directory). The fsync is required by some
Expand All @@ -75,7 +49,7 @@
return // ignore error, sync on dir must not be necessarily supported by the FS
}
defer f.Close()
syncFile(f)

Check failure on line 52 in libbeat/statestore/backend/memlog/util.go

View workflow job for this annotation

GitHub Actions / lint (linux)

Error return value is not checked (errcheck)
}

// pathEnsurePermissions checks if the file permissions for the given file match wantPerm.
Expand Down
81 changes: 0 additions & 81 deletions libbeat/statestore/backend/memlog/util_test.go

This file was deleted.

Loading