Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-flatfs
Commits
3488e4dd
Commit
3488e4dd
authored
Sep 10, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow put to try again if it fails due to too many open files
add log statement for retry vendor
parent
64a7b69a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
flatfs.go
flatfs.go
+25
-0
No files found.
flatfs.go
View file @
3488e4dd
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment