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

*: use 'io.Seek*' for go1.7+ #7545

Merged
merged 1 commit into from
Mar 20, 2017
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ See [etcdctl][etcdctl] for a simple command line client.

The easiest way to get etcd is to use one of the pre-built release binaries which are available for OSX, Linux, Windows, [rkt][rkt], and Docker. Instructions for using these binaries are on the [GitHub releases page][github-release].

For those wanting to try the very latest version, [build the latest version of etcd][dl-build] from the `master` branch. This first needs [*Go*](https://golang.org/) installed (version 1.7+ is required). All development occurs on `master`, including new features and bug fixes. Bug fixes are first targeted at `master` and subsequently ported to release branches, as described in the [branch management][branch-management] guide.
For those wanting to try the very latest version, [build the latest version of etcd][dl-build] from the `master` branch. This first needs [*Go*](https://golang.org/) installed (version 1.8+ is required). All development occurs on `master`, including new features and bug fixes. Bug fixes are first targeted at `master` and subsequently ported to release branches, as described in the [branch management][branch-management] guide.

[rkt]: https://github.com/coreos/rkt/releases/
[github-release]: https://github.com/coreos/etcd/releases/
Expand Down Expand Up @@ -73,7 +73,7 @@ That's it! etcd is now running and serving client requests. For more

### etcd TCP ports

The [official etcd ports][iana-ports] are 2379 for client requests, and 2380 for peer communication.
The [official etcd ports][iana-ports] are 2379 for client requests, and 2380 for peer communication.

[iana-ports]: https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=etcd

Expand Down
8 changes: 4 additions & 4 deletions etcdctl/ctlv3/command/snapshot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,14 @@ func makeDB(snapdir, dbfile string, commit int) {
defer f.Close()

// get snapshot integrity hash
if _, err := f.Seek(-sha256.Size, os.SEEK_END); err != nil {
if _, err := f.Seek(-sha256.Size, io.SeekEnd); err != nil {
ExitWithError(ExitIO, err)
}
sha := make([]byte, sha256.Size)
if _, err := f.Read(sha); err != nil {
ExitWithError(ExitIO, err)
}
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
if _, err := f.Seek(0, io.SeekStart); err != nil {
ExitWithError(ExitIO, err)
}

Expand All @@ -335,7 +335,7 @@ func makeDB(snapdir, dbfile string, commit int) {
}

// truncate away integrity hash, if any.
off, serr := db.Seek(0, os.SEEK_END)
off, serr := db.Seek(0, io.SeekEnd)
if serr != nil {
ExitWithError(ExitIO, serr)
}
Expand All @@ -353,7 +353,7 @@ func makeDB(snapdir, dbfile string, commit int) {

if hasHash && !skipHashCheck {
// check for match
if _, err := db.Seek(0, os.SEEK_SET); err != nil {
if _, err := db.Seek(0, io.SeekStart); err != nil {
ExitWithError(ExitIO, err)
}
h := sha256.New()
Expand Down
7 changes: 4 additions & 3 deletions pkg/fileutil/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package fileutil

import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -101,11 +102,11 @@ func Exist(name string) bool {
// shorten the length of the file.
func ZeroToEnd(f *os.File) error {
// TODO: support FALLOC_FL_ZERO_RANGE
off, err := f.Seek(0, os.SEEK_CUR)
off, err := f.Seek(0, io.SeekCurrent)
if err != nil {
return err
}
lenf, lerr := f.Seek(0, os.SEEK_END)
lenf, lerr := f.Seek(0, io.SeekEnd)
if lerr != nil {
return lerr
}
Expand All @@ -116,6 +117,6 @@ func ZeroToEnd(f *os.File) error {
if err = Preallocate(f, lenf, true); err != nil {
return err
}
_, err = f.Seek(off, os.SEEK_SET)
_, err = f.Seek(off, io.SeekStart)
return err
}
5 changes: 3 additions & 2 deletions pkg/fileutil/fileutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package fileutil

import (
"io"
"io/ioutil"
"os"
"os/user"
Expand Down Expand Up @@ -133,13 +134,13 @@ func TestZeroToEnd(t *testing.T) {
if _, err = f.Write(b); err != nil {
t.Fatal(err)
}
if _, err = f.Seek(512, os.SEEK_SET); err != nil {
if _, err = f.Seek(512, io.SeekStart); err != nil {
t.Fatal(err)
}
if err = ZeroToEnd(f); err != nil {
t.Fatal(err)
}
off, serr := f.Seek(0, os.SEEK_CUR)
off, serr := f.Seek(0, io.SeekCurrent)
if serr != nil {
t.Fatal(serr)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/fileutil/lock_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package fileutil

import (
"io"
"os"
"syscall"
)
Expand All @@ -36,7 +37,7 @@ const (
var (
wrlck = syscall.Flock_t{
Type: syscall.F_WRLCK,
Whence: int16(os.SEEK_SET),
Whence: int16(io.SeekStart),
Start: 0,
Len: 0,
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/fileutil/preallocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

package fileutil

import "os"
import (
"io"
"os"
)

// Preallocate tries to allocate the space for given
// file. This operation is only supported on linux by a
Expand All @@ -29,15 +32,15 @@ func Preallocate(f *os.File, sizeInBytes int64, extendFile bool) error {
}

func preallocExtendTrunc(f *os.File, sizeInBytes int64) error {
curOff, err := f.Seek(0, os.SEEK_CUR)
curOff, err := f.Seek(0, io.SeekCurrent)
if err != nil {
return err
}
size, err := f.Seek(sizeInBytes, os.SEEK_END)
size, err := f.Seek(sizeInBytes, io.SeekEnd)
if err != nil {
return err
}
if _, err = f.Seek(curOff, os.SEEK_SET); err != nil {
if _, err = f.Seek(curOff, io.SeekStart); err != nil {
return err
}
if sizeInBytes > size {
Expand Down
2 changes: 1 addition & 1 deletion wal/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newEncoder(w io.Writer, prevCrc uint32, pageOffset int) *encoder {

// newFileEncoder creates a new encoder with current file offset for the page writer.
func newFileEncoder(f *os.File, prevCrc uint32) (*encoder, error) {
offset, err := f.Seek(0, os.SEEK_CUR)
offset, err := f.Seek(0, io.SeekCurrent)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion wal/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Repair(dirpath string) bool {
}
defer bf.Close()

if _, err = f.Seek(0, os.SEEK_SET); err != nil {
if _, err = f.Seek(0, io.SeekStart); err != nil {
plog.Errorf("could not repair %v, failed to read file", f.Name())
return false
}
Expand Down
2 changes: 1 addition & 1 deletion wal/repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func testRepair(t *testing.T, ents [][]raftpb.Entry, corrupt corruptFunc, expect
}
}

offset, err := w.tail().Seek(0, os.SEEK_CUR)
offset, err := w.tail().Seek(0, io.SeekCurrent)
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func Create(dirpath string, metadata []byte) (*WAL, error) {
if err != nil {
return nil, err
}
if _, err = f.Seek(0, os.SEEK_END); err != nil {
if _, err = f.Seek(0, io.SeekEnd); err != nil {
return nil, err
}
if err = fileutil.Preallocate(f.File, SegmentSizeBytes, true); err != nil {
Expand Down Expand Up @@ -322,7 +322,7 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
// not all, will cause CRC errors on WAL open. Since the records
// were never fully synced to disk in the first place, it's safe
// to zero them out to avoid any CRC errors from new writes.
if _, err = w.tail().Seek(w.decoder.lastOffset(), os.SEEK_SET); err != nil {
if _, err = w.tail().Seek(w.decoder.lastOffset(), io.SeekStart); err != nil {
return nil, state, nil, err
}
if err = fileutil.ZeroToEnd(w.tail().File); err != nil {
Expand Down Expand Up @@ -361,7 +361,7 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
// Then cut atomically rename temp wal file to a wal file.
func (w *WAL) cut() error {
// close old wal file; truncate to avoid wasting space if an early cut
off, serr := w.tail().Seek(0, os.SEEK_CUR)
off, serr := w.tail().Seek(0, io.SeekCurrent)
if serr != nil {
return serr
}
Expand Down Expand Up @@ -401,7 +401,7 @@ func (w *WAL) cut() error {
return err
}

off, err = w.tail().Seek(0, os.SEEK_CUR)
off, err = w.tail().Seek(0, io.SeekCurrent)
if err != nil {
return err
}
Expand All @@ -418,7 +418,7 @@ func (w *WAL) cut() error {
if newTail, err = fileutil.LockFile(fpath, os.O_WRONLY, fileutil.PrivateFileMode); err != nil {
return err
}
if _, err = newTail.Seek(off, os.SEEK_SET); err != nil {
if _, err = newTail.Seek(off, io.SeekStart); err != nil {
return err
}

Expand Down Expand Up @@ -564,7 +564,7 @@ func (w *WAL) Save(st raftpb.HardState, ents []raftpb.Entry) error {
return err
}

curOff, err := w.tail().Seek(0, os.SEEK_CUR)
curOff, err := w.tail().Seek(0, io.SeekCurrent)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestNew(t *testing.T) {
defer w.Close()

// file is preallocated to segment size; only read data written by wal
off, err := w.tail().Seek(0, os.SEEK_CUR)
off, err := w.tail().Seek(0, io.SeekCurrent)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -623,7 +623,7 @@ func TestTailWriteNoSlackSpace(t *testing.T) {
}
}
// get rid of slack space by truncating file
off, serr := w.tail().Seek(0, os.SEEK_CUR)
off, serr := w.tail().Seek(0, io.SeekCurrent)
if serr != nil {
t.Fatal(serr)
}
Expand Down Expand Up @@ -732,7 +732,7 @@ func TestOpenOnTornWrite(t *testing.T) {
if err = w.Save(raftpb.HardState{}, es); err != nil {
t.Fatal(err)
}
if offsets[i], err = w.tail().Seek(0, os.SEEK_CUR); err != nil {
if offsets[i], err = w.tail().Seek(0, io.SeekCurrent); err != nil {
t.Fatal(err)
}
}
Expand All @@ -746,7 +746,7 @@ func TestOpenOnTornWrite(t *testing.T) {
t.Fatal(ferr)
}
defer f.Close()
_, err = f.Seek(offsets[clobberIdx], os.SEEK_SET)
_, err = f.Seek(offsets[clobberIdx], io.SeekStart)
if err != nil {
t.Fatal(err)
}
Expand Down