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

feat: read harder #78

Merged
merged 1 commit into from
Apr 10, 2020
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
18 changes: 0 additions & 18 deletions flatfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,24 +652,6 @@ func (fs *Datastore) putMany(data map[datastore.Key][]byte) error {
}

func (fs *Datastore) Get(key datastore.Key) (value []byte, err error) {
value, err = fs.get(key)

// Fallback retry for temporary error.
if err != nil && isTooManyFDError(err) {
for i := 0; i < 6; i++ {
time.Sleep(time.Duration(i+1) * RetryDelay)

value, err = fs.get(key)
if err == nil || !isTooManyFDError(err) {
break
}
}
}

return
}

func (fs *Datastore) get(key datastore.Key) (value []byte, err error) {
// Can't exist in datastore.
if !keyIsValid(key) {
return nil, datastore.ErrNotFound
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/ipfs/go-ds-flatfs

require (
github.com/alexbrainman/goissue34681 v0.0.0-20191006012335-3fc7a47baff5 // indirect
github.com/alexbrainman/goissue34681 v0.0.0-20191006012335-3fc7a47baff5
github.com/ipfs/go-datastore v0.4.4
github.com/ipfs/go-log v1.0.3
github.com/jbenet/goprocess v0.1.4
Expand Down
13 changes: 13 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flatfs
import (
"io"
"os"
"time"
)

// From: http://stackoverflow.com/questions/30697324/how-to-check-if-directory-on-path-is-empty
Expand All @@ -19,3 +20,15 @@ func DirIsEmpty(name string) (bool, error) {
}
return false, err // Either not empty or error, suits both cases
}

func readFile(filename string) (data []byte, err error) {
// Fallback retry for temporary error.
for i := 0; i < 6; i++ {
data, err = readFileOnce(filename)
if err == nil || !isTooManyFDError(err) {
break
}
time.Sleep(time.Duration(i+1) * RetryDelay)
}
return data, err
}
2 changes: 1 addition & 1 deletion util_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ func tempFile(dir, pattern string) (*os.File, error) {
return ioutil.TempFile(dir, pattern)
}

func readFile(filename string) ([]byte, error) {
func readFileOnce(filename string) ([]byte, error) {
return ioutil.ReadFile(filename)
}
2 changes: 1 addition & 1 deletion util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func tempFile(dir, pattern string) (f *os.File, err error) {
return
}

func readFile(filename string) ([]byte, error) {
func readFileOnce(filename string) ([]byte, error) {
f, err := goissue34681.Open(filename)
if err != nil {
return nil, err
Expand Down