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
05f0240c
Commit
05f0240c
authored
Jan 18, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make UpgradeV0toV1 and DowngradeV1toV0 more robust.
parent
f91286dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
8 deletions
+27
-8
convert.go
convert.go
+8
-1
convert_test.go
convert_test.go
+18
-6
shard.go
shard.go
+1
-1
No files found.
convert.go
View file @
05f0240c
...
@@ -28,7 +28,14 @@ func UpgradeV0toV1(path string, prefixLen int) error {
...
@@ -28,7 +28,14 @@ func UpgradeV0toV1(path string, prefixLen int) error {
}
}
func
DowngradeV1toV0
(
path
string
)
error
{
func
DowngradeV1toV0
(
path
string
)
error
{
err
:=
os
.
Remove
(
filepath
.
Join
(
path
,
SHARDING_FN
))
fun
,
err
:=
ReadShardFunc
(
path
)
if
err
!=
nil
{
return
err
}
else
if
fun
.
funName
!=
"prefix"
{
return
fmt
.
Errorf
(
"%s: can only downgrade datastore that use the 'prefix' sharding function"
,
path
)
}
err
=
os
.
Remove
(
filepath
.
Join
(
path
,
SHARDING_FN
))
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
convert_test.go
View file @
05f0240c
...
@@ -96,7 +96,7 @@ func TestMoveRestart(t *testing.T) {
...
@@ -96,7 +96,7 @@ func TestMoveRestart(t *testing.T) {
// there should be nothing left in the new datastore
// there should be nothing left in the new datastore
rmEmptyDatastore
(
t
,
v2dir
)
rmEmptyDatastore
(
t
,
v2dir
)
// try the move again, again should fail
// try the move again, again should fail
createDatastore
(
t
,
v2dir
,
flatfs
.
NextToLast
(
2
))
createDatastore
(
t
,
v2dir
,
flatfs
.
NextToLast
(
2
))
err
=
flatfs
.
Move
(
v1dir
,
v2dir
,
nil
)
err
=
flatfs
.
Move
(
v1dir
,
v2dir
,
nil
)
...
@@ -139,12 +139,12 @@ func TestUpgradeDownload(t *testing.T) {
...
@@ -139,12 +139,12 @@ func TestUpgradeDownload(t *testing.T) {
keys
,
blocks
:=
populateDatastore
(
t
,
tempdir
)
keys
,
blocks
:=
populateDatastore
(
t
,
tempdir
)
checkKeys
(
t
,
tempdir
,
keys
,
blocks
)
checkKeys
(
t
,
tempdir
,
keys
,
blocks
)
//
err := flatfs.UpgradeV0toV1(tempdir, 3)
err
:=
flatfs
.
UpgradeV0toV1
(
tempdir
,
3
)
//
if err == nil {
if
err
==
nil
{
//
t.Fatalf("UpgradeV0toV1 on already v1 should fail.")
t
.
Fatalf
(
"UpgradeV0toV1 on already v1 should fail."
)
//
}
}
err
:
=
flatfs
.
DowngradeV1toV0
(
tempdir
)
err
=
flatfs
.
DowngradeV1toV0
(
tempdir
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"DowngradeV1toV0 fail: %v
\n
"
,
err
)
t
.
Fatalf
(
"DowngradeV1toV0 fail: %v
\n
"
,
err
)
}
}
...
@@ -165,6 +165,18 @@ func TestUpgradeDownload(t *testing.T) {
...
@@ -165,6 +165,18 @@ func TestUpgradeDownload(t *testing.T) {
checkKeys
(
t
,
tempdir
,
keys
,
blocks
)
checkKeys
(
t
,
tempdir
,
keys
,
blocks
)
}
}
func
TestDownloadNonPrefix
(
t
*
testing
.
T
)
{
tempdir
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
createDatastore
(
t
,
tempdir
,
flatfs
.
NextToLast
(
2
))
err
:=
flatfs
.
DowngradeV1toV0
(
tempdir
)
if
err
==
nil
{
t
.
Fatalf
(
"DowngradeV1toV0 should have failed"
,
err
)
}
}
func
createDatastore
(
t
*
testing
.
T
,
dir
string
,
fun
*
flatfs
.
ShardIdV1
)
{
func
createDatastore
(
t
*
testing
.
T
,
dir
string
,
fun
*
flatfs
.
ShardIdV1
)
{
err
:=
flatfs
.
Create
(
dir
,
fun
)
err
:=
flatfs
.
Create
(
dir
,
fun
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
shard.go
View file @
05f0240c
...
@@ -121,7 +121,7 @@ func ReadShardFunc(dir string) (*ShardIdV1, error) {
...
@@ -121,7 +121,7 @@ func ReadShardFunc(dir string) (*ShardIdV1, error) {
}
}
func
WriteShardFunc
(
dir
string
,
id
*
ShardIdV1
)
error
{
func
WriteShardFunc
(
dir
string
,
id
*
ShardIdV1
)
error
{
file
,
err
:=
os
.
Creat
e
(
filepath
.
Join
(
dir
,
SHARDING_FN
))
file
,
err
:=
os
.
OpenFil
e
(
filepath
.
Join
(
dir
,
SHARDING_FN
)
,
os
.
O_WRONLY
|
os
.
O_CREATE
|
os
.
O_EXCL
,
0666
)
if
err
!=
nil
{
if
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