Unverified Commit c1f339f4 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #78 from ipfs/feat/read-file-harder

feat: read harder
parents 319998e6 303e0190
...@@ -652,24 +652,6 @@ func (fs *Datastore) putMany(data map[datastore.Key][]byte) error { ...@@ -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) { 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. // Can't exist in datastore.
if !keyIsValid(key) { if !keyIsValid(key) {
return nil, datastore.ErrNotFound return nil, datastore.ErrNotFound
......
...@@ -3,6 +3,7 @@ package flatfs ...@@ -3,6 +3,7 @@ package flatfs
import ( import (
"io" "io"
"os" "os"
"time"
) )
// From: http://stackoverflow.com/questions/30697324/how-to-check-if-directory-on-path-is-empty // From: http://stackoverflow.com/questions/30697324/how-to-check-if-directory-on-path-is-empty
...@@ -19,3 +20,15 @@ func DirIsEmpty(name string) (bool, error) { ...@@ -19,3 +20,15 @@ func DirIsEmpty(name string) (bool, error) {
} }
return false, err // Either not empty or error, suits both cases 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
}
...@@ -11,6 +11,6 @@ func tempFile(dir, pattern string) (*os.File, error) { ...@@ -11,6 +11,6 @@ func tempFile(dir, pattern string) (*os.File, error) {
return ioutil.TempFile(dir, pattern) return ioutil.TempFile(dir, pattern)
} }
func readFile(filename string) ([]byte, error) { func readFileOnce(filename string) ([]byte, error) {
return ioutil.ReadFile(filename) return ioutil.ReadFile(filename)
} }
...@@ -75,7 +75,7 @@ func tempFile(dir, pattern string) (f *os.File, err error) { ...@@ -75,7 +75,7 @@ func tempFile(dir, pattern string) (f *os.File, err error) {
return return
} }
func readFile(filename string) ([]byte, error) { func readFileOnce(filename string) ([]byte, error) {
f, err := goissue34681.Open(filename) f, err := goissue34681.Open(filename)
if err != nil { if err != nil {
return nil, err return nil, err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment