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
70540a69
Commit
70540a69
authored
Aug 21, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix lint errors
parent
6e6008d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
18 deletions
+40
-18
flatfs.go
flatfs.go
+7
-7
flatfs_test.go
flatfs_test.go
+33
-11
No files found.
flatfs.go
View file @
70540a69
...
@@ -490,7 +490,7 @@ func (fs *Datastore) putMany(data map[datastore.Key][]byte) error {
...
@@ -490,7 +490,7 @@ func (fs *Datastore) putMany(data map[datastore.Key][]byte) error {
defer
func
()
{
defer
func
()
{
for
fi
:=
range
files
{
for
fi
:=
range
files
{
val
,
_
:=
ops
[
fi
]
val
:=
ops
[
fi
]
switch
val
{
switch
val
{
case
0
:
case
0
:
_
=
fi
.
Close
()
_
=
fi
.
Close
()
...
@@ -667,7 +667,7 @@ func (fs *Datastore) Query(q query.Query) (query.Results, error) {
...
@@ -667,7 +667,7 @@ func (fs *Datastore) Query(q query.Query) (query.Results, error) {
case
<-
p
.
Closing
()
:
case
<-
p
.
Closing
()
:
}
}
})
})
go
b
.
Process
.
CloseAfterChildren
()
go
b
.
Process
.
CloseAfterChildren
()
//nolint
return
b
.
Results
(),
nil
return
b
.
Results
(),
nil
}
}
...
@@ -1045,20 +1045,20 @@ func (fs *Datastore) walk(path string, result *query.ResultBuilder) error {
...
@@ -1045,20 +1045,20 @@ func (fs *Datastore) walk(path string, result *query.ResultBuilder) error {
// Deactivate closes background maintenance threads, most write
// Deactivate closes background maintenance threads, most write
// operations will fail but readonly operations will continue to
// operations will fail but readonly operations will continue to
// function
// function
func
(
fs
*
Datastore
)
deactivate
()
error
{
func
(
fs
*
Datastore
)
deactivate
()
{
fs
.
shutdownLock
.
Lock
()
fs
.
shutdownLock
.
Lock
()
defer
fs
.
shutdownLock
.
Unlock
()
defer
fs
.
shutdownLock
.
Unlock
()
if
fs
.
shutdown
{
if
fs
.
shutdown
{
return
nil
return
}
}
fs
.
shutdown
=
true
fs
.
shutdown
=
true
close
(
fs
.
checkpointCh
)
close
(
fs
.
checkpointCh
)
<-
fs
.
done
<-
fs
.
done
return
nil
}
}
func
(
fs
*
Datastore
)
Close
()
error
{
func
(
fs
*
Datastore
)
Close
()
error
{
return
fs
.
deactivate
()
fs
.
deactivate
()
return
nil
}
}
type
flatfsBatch
struct
{
type
flatfsBatch
struct
{
...
@@ -1091,7 +1091,7 @@ func (bt *flatfsBatch) Commit() error {
...
@@ -1091,7 +1091,7 @@ func (bt *flatfsBatch) Commit() error {
return
err
return
err
}
}
for
k
,
_
:=
range
bt
.
deletes
{
for
k
:=
range
bt
.
deletes
{
if
err
:=
bt
.
ds
.
Delete
(
k
);
err
!=
nil
{
if
err
:=
bt
.
ds
.
Delete
(
k
);
err
!=
nil
{
return
err
return
err
}
}
...
...
flatfs_test.go
View file @
70540a69
...
@@ -561,7 +561,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
...
@@ -561,7 +561,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
v
:=
[]
byte
(
"10bytes---"
)
v
:=
[]
byte
(
"10bytes---"
)
err
:=
fs
.
Put
(
testKey
,
v
)
err
:=
fs
.
Put
(
testKey
,
v
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
f
(
"Put fail: %v
\n
"
,
err
)
t
.
Error
f
(
"Put fail: %v
\n
"
,
err
)
}
}
}
}
}
}
...
@@ -571,7 +571,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
...
@@ -571,7 +571,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
for
i
:=
0
;
i
<
count
;
i
++
{
for
i
:=
0
;
i
<
count
;
i
++
{
err
:=
fs
.
Delete
(
testKey
)
err
:=
fs
.
Delete
(
testKey
)
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
"key not found"
)
{
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
"key not found"
)
{
t
.
Fatal
f
(
"Delete fail: %v
\n
"
,
err
)
t
.
Error
f
(
"Delete fail: %v
\n
"
,
err
)
}
}
}
}
}
}
...
@@ -624,7 +624,10 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
...
@@ -624,7 +624,10 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
}
}
defer
fs
.
Close
()
defer
fs
.
Close
()
fsBatch
,
_
:=
fs
.
Batch
()
fsBatch
,
err
:=
fs
.
Batch
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
count
:=
200
count
:=
200
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
...
@@ -636,14 +639,17 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
...
@@ -636,14 +639,17 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
put
:=
func
()
{
put
:=
func
()
{
for
i
:=
0
;
i
<
count
;
i
++
{
for
i
:=
0
;
i
<
count
;
i
++
{
fsBatch
.
Put
(
testKeys
[
i
],
[]
byte
(
"10bytes---"
))
err
:=
fsBatch
.
Put
(
testKeys
[
i
],
[]
byte
(
"10bytes---"
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
}
}
}
commit
:=
func
()
{
commit
:=
func
()
{
defer
wg
.
Done
()
defer
wg
.
Done
()
err
:=
fsBatch
.
Commit
()
err
:=
fsBatch
.
Commit
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
f
(
"Batch Put fail: %v
\n
"
,
err
)
t
.
Error
f
(
"Batch Put fail: %v
\n
"
,
err
)
}
}
}
}
...
@@ -652,7 +658,7 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
...
@@ -652,7 +658,7 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
for
_
,
k
:=
range
testKeys
{
for
_
,
k
:=
range
testKeys
{
err
:=
fs
.
Delete
(
k
)
err
:=
fs
.
Delete
(
k
)
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
"key not found"
)
{
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
"key not found"
)
{
t
.
Fatal
f
(
"Delete fail: %v
\n
"
,
err
)
t
.
Error
f
(
"Delete fail: %v
\n
"
,
err
)
}
}
}
}
}
}
...
@@ -662,9 +668,15 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
...
@@ -662,9 +668,15 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
wg
.
Add
(
2
)
wg
.
Add
(
2
)
put
()
put
()
commit
()
commit
()
du
,
_
:=
fs
.
DiskUsage
()
du
,
err
:=
fs
.
DiskUsage
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
del
()
del
()
du2
,
_
:=
fs
.
DiskUsage
()
du2
,
err
:=
fs
.
DiskUsage
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
du
-
uint64
(
10
*
count
)
!=
du2
{
if
du
-
uint64
(
10
*
count
)
!=
du2
{
t
.
Errorf
(
"should have deleted exactly %d bytes: %d %d"
,
10
*
count
,
du
,
du2
)
t
.
Errorf
(
"should have deleted exactly %d bytes: %d %d"
,
10
*
count
,
du
,
du2
)
}
}
...
@@ -676,11 +688,17 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
...
@@ -676,11 +688,17 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
go
del
()
go
del
()
wg
.
Wait
()
wg
.
Wait
()
du3
,
_
:=
fs
.
DiskUsage
()
du3
,
err
:=
fs
.
DiskUsage
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Now query how many keys we have
// Now query how many keys we have
results
,
err
:=
fs
.
Query
(
query
.
Query
{
results
,
err
:=
fs
.
Query
(
query
.
Query
{
KeysOnly
:
true
,
KeysOnly
:
true
,
})
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
rest
,
err
:=
results
.
Rest
()
rest
,
err
:=
results
.
Rest
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -862,6 +880,7 @@ func TestSHARDINGFile(t *testing.T) {
...
@@ -862,6 +880,7 @@ func TestSHARDINGFile(t *testing.T) {
fs
,
err
=
flatfs
.
CreateOrOpen
(
tempdir
,
flatfs
.
Prefix
(
5
),
false
)
fs
,
err
=
flatfs
.
CreateOrOpen
(
tempdir
,
flatfs
.
Prefix
(
5
),
false
)
if
err
==
nil
{
if
err
==
nil
{
fs
.
Close
()
t
.
Fatalf
(
"Was able to open repo with incompatible sharding function"
)
t
.
Fatalf
(
"Was able to open repo with incompatible sharding function"
)
}
}
}
}
...
@@ -877,9 +896,12 @@ func TestNonDatastoreDir(t *testing.T) {
...
@@ -877,9 +896,12 @@ func TestNonDatastoreDir(t *testing.T) {
tempdir
,
cleanup
:=
tempdir
(
t
)
tempdir
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
defer
cleanup
()
ioutil
.
WriteFile
(
filepath
.
Join
(
tempdir
,
"afile"
),
[]
byte
(
"Some Content"
),
0644
)
err
:=
ioutil
.
WriteFile
(
filepath
.
Join
(
tempdir
,
"afile"
),
[]
byte
(
"Some Content"
),
0644
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
:
=
flatfs
.
Create
(
tempdir
,
flatfs
.
NextToLast
(
2
))
err
=
flatfs
.
Create
(
tempdir
,
flatfs
.
NextToLast
(
2
))
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"Expected an error when creating a datastore in a non-empty directory"
)
t
.
Fatalf
(
"Expected an error when creating a datastore in a non-empty directory"
)
}
}
...
...
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