Commit 3488e4dd authored by Jeromy's avatar Jeromy

allow put to try again if it fails due to too many open files

add log statement for retry

vendor
parent 64a7b69a
......@@ -10,12 +10,17 @@ import (
"os"
"path"
"strings"
"time"
"github.com/jbenet/go-datastore"
"github.com/jbenet/go-datastore/Godeps/_workspace/src/github.com/jbenet/go-os-rename"
"github.com/jbenet/go-datastore/query"
logging "github.com/jbenet/go-datastore/Godeps/_workspace/src/github.com/ipfs/go-log"
)
var log = logging.Logger("flatfs")
const (
extension = ".data"
maxPrefixLen = 16
......@@ -93,12 +98,32 @@ func (fs *Datastore) makePrefixDirNoSync(dir string) error {
return nil
}
var putMaxRetries = 3
func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
val, ok := value.([]byte)
if !ok {
return datastore.ErrInvalidType
}
var err error
for i := 0; i < putMaxRetries; i++ {
err = fs.doPut(key, val)
if err == nil {
return nil
}
if !strings.Contains(err.Error(), "too many open files") {
return err
}
log.Error("too many open files, retrying in %dms", 100*i)
time.Sleep(time.Millisecond * 100 * time.Duration(i))
}
return err
}
func (fs *Datastore) doPut(key datastore.Key, val []byte) error {
dir, path := fs.encode(key)
if err := fs.makePrefixDir(dir); err != nil {
return 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