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 ( ...@@ -10,12 +10,17 @@ import (
"os" "os"
"path" "path"
"strings" "strings"
"time"
"github.com/jbenet/go-datastore" "github.com/jbenet/go-datastore"
"github.com/jbenet/go-datastore/Godeps/_workspace/src/github.com/jbenet/go-os-rename" "github.com/jbenet/go-datastore/Godeps/_workspace/src/github.com/jbenet/go-os-rename"
"github.com/jbenet/go-datastore/query" "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 ( const (
extension = ".data" extension = ".data"
maxPrefixLen = 16 maxPrefixLen = 16
...@@ -93,12 +98,32 @@ func (fs *Datastore) makePrefixDirNoSync(dir string) error { ...@@ -93,12 +98,32 @@ func (fs *Datastore) makePrefixDirNoSync(dir string) error {
return nil return nil
} }
var putMaxRetries = 3
func (fs *Datastore) Put(key datastore.Key, value interface{}) error { func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
val, ok := value.([]byte) val, ok := value.([]byte)
if !ok { if !ok {
return datastore.ErrInvalidType 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) dir, path := fs.encode(key)
if err := fs.makePrefixDir(dir); err != nil { if err := fs.makePrefixDir(dir); err != nil {
return err 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