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
1807cc86
Commit
1807cc86
authored
Aug 13, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use bytes instead of interface{}
parent
906a90d3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
35 deletions
+10
-35
convert_test.go
convert_test.go
+1
-1
flatfs.go
flatfs.go
+4
-9
flatfs_test.go
flatfs_test.go
+3
-23
package.json
package.json
+2
-2
No files found.
convert_test.go
View file @
1807cc86
...
...
@@ -228,7 +228,7 @@ func checkKeys(t *testing.T, dir string, keys []datastore.Key, blocks [][]byte)
if
err
!=
nil
{
t
.
Fatalf
(
"Get fail: %v
\n
"
,
err
)
}
if
!
bytes
.
Equal
(
data
.
([]
byte
)
,
blocks
[
i
])
{
if
!
bytes
.
Equal
(
data
,
blocks
[
i
])
{
t
.
Fatalf
(
"block context differ for key %s
\n
"
,
key
.
String
())
}
}
...
...
flatfs.go
View file @
1807cc86
...
...
@@ -354,18 +354,13 @@ var putMaxRetries = 6
// one arrived slightly later than the other. In the case of a
// concurrent Put and a Delete operation, we cannot guarantee which one
// will win.
func
(
fs
*
Datastore
)
Put
(
key
datastore
.
Key
,
value
interface
{})
error
{
val
,
ok
:=
value
.
([]
byte
)
if
!
ok
{
return
datastore
.
ErrInvalidType
}
func
(
fs
*
Datastore
)
Put
(
key
datastore
.
Key
,
value
[]
byte
)
error
{
var
err
error
for
i
:=
1
;
i
<=
putMaxRetries
;
i
++
{
err
=
fs
.
doWriteOp
(
&
op
{
typ
:
opPut
,
key
:
key
,
v
:
val
,
v
:
val
ue
,
})
if
err
==
nil
{
break
...
...
@@ -557,7 +552,7 @@ func (fs *Datastore) putMany(data map[datastore.Key]interface{}) error {
return
nil
}
func
(
fs
*
Datastore
)
Get
(
key
datastore
.
Key
)
(
value
interface
{}
,
err
error
)
{
func
(
fs
*
Datastore
)
Get
(
key
datastore
.
Key
)
(
value
[]
byte
,
err
error
)
{
_
,
path
:=
fs
.
encode
(
key
)
data
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
...
...
@@ -1025,7 +1020,7 @@ func (fs *Datastore) Batch() (datastore.Batch, error) {
},
nil
}
func
(
bt
*
flatfsBatch
)
Put
(
key
datastore
.
Key
,
val
interface
{}
)
error
{
func
(
bt
*
flatfsBatch
)
Put
(
key
datastore
.
Key
,
val
[]
byte
)
error
{
bt
.
puts
[
key
]
=
val
return
nil
}
...
...
flatfs_test.go
View file @
1807cc86
...
...
@@ -42,22 +42,6 @@ func tryAllShardFuncs(t *testing.T, testFunc func(mkShardFunc, *testing.T)) {
t
.
Run
(
"next-to-last"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
flatfs
.
NextToLast
,
t
)
})
}
func
TestPutBadValueType
(
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
CreateOrOpen
(
temp
,
flatfs
.
Prefix
(
2
),
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
defer
fs
.
Close
()
err
=
fs
.
Put
(
datastore
.
NewKey
(
"quux"
),
22
)
if
g
,
e
:=
err
,
datastore
.
ErrInvalidType
;
g
!=
e
{
t
.
Fatalf
(
"expected ErrInvalidType, got: %v
\n
"
,
g
)
}
}
type
mkShardFunc
func
(
int
)
*
flatfs
.
ShardIdV1
func
testPut
(
dirFunc
mkShardFunc
,
t
*
testing
.
T
)
{
...
...
@@ -94,14 +78,10 @@ func testGet(dirFunc mkShardFunc, t *testing.T) {
t
.
Fatalf
(
"Put fail: %v
\n
"
,
err
)
}
data
,
err
:=
fs
.
Get
(
datastore
.
NewKey
(
"quux"
))
buf
,
err
:=
fs
.
Get
(
datastore
.
NewKey
(
"quux"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Get failed: %v"
,
err
)
}
buf
,
ok
:=
data
.
([]
byte
)
if
!
ok
{
t
.
Fatalf
(
"expected []byte from Get, got %T: %v"
,
data
,
data
)
}
if
g
,
e
:=
string
(
buf
),
input
;
g
!=
e
{
t
.
Fatalf
(
"Get gave wrong content: %q != %q"
,
g
,
e
)
}
...
...
@@ -137,7 +117,7 @@ func testPutOverwrite(dirFunc mkShardFunc, t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Get failed: %v"
,
err
)
}
if
g
,
e
:=
string
(
data
.
([]
byte
)
),
winner
;
g
!=
e
{
if
g
,
e
:=
string
(
data
),
winner
;
g
!=
e
{
t
.
Fatalf
(
"Get gave wrong content: %q != %q"
,
g
,
e
)
}
}
...
...
@@ -732,7 +712,7 @@ func testDiskUsageEstimation(dirFunc mkShardFunc, t *testing.T) {
maxDiff
:=
int
(
0.05
*
float64
(
duReopen
))
// %5 of actual
if
diff
>
maxDiff
{
t
.
Fatal
(
"expected a better estimation within 5%"
)
t
.
Fatal
f
(
"expected a better estimation within 5%
%
"
)
}
// Make sure the accuracy value is correct
...
...
package.json
View file @
1807cc86
...
...
@@ -14,9 +14,9 @@
},
{
"author"
:
"jbenet"
,
"hash"
:
"Qm
eiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i
"
,
"hash"
:
"Qm
VG5gxteQNEMhrS8prJSmU2C9rebtFuTd3SYZ5kE3YZ5k
"
,
"name"
:
"go-datastore"
,
"version"
:
"
2.4.1
"
"version"
:
"
3.0.0
"
}
],
"gxVersion"
:
"0.8.0"
,
...
...
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