Commit 303e0190 authored by Steven Allen's avatar Steven Allen

feat: read harder

Instead of retrying in get only, retry everywhere we read a file.
parent 319998e6
......@@ -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
......
......@@ -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
......@@ -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
}
......@@ -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)
}
......@@ -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
......
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