Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Add support for converting badger2 datastore #26

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,49 @@ func TestBasicCleanup(t *testing.T) {

testutil.FinishTest(t, dir, s1, s2, 200, 200)
}

func TestBasicConvertBadger2(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in #23 (comment) there aren't really any natural places to add Badger2 tests in the repo that are just copy-paste's of the Badger1 tests (aside from the short Validator tests). This is mostly because this library is mostly datastore agnostic and so it shouldn't be relevant.

The existing tests are:

  1. The CLI works (cli_test.go)
  2. The strategies work (strategy_test.go)
  3. Datastore configs look right (validate_test.go)

I think the right way to make this work is to just add a basic test that converts from all primitive datastores (flatfs, leveldb, memory, badger, badger2) to in memory leveldb and then back again.

You should be able to use t.Run to create the various subtests and utilize the testutils (e.g. testutil.PrepareTest and FinishTest) to generate the random keys and check their validity.

Copy link
Contributor Author

@gammazero gammazero Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, with the exception of memory datastore. While it makes sense to have a memory datastore for IPFS testing, does it makes sense to support conversion to/from a memory-only datastore? It would mean IPFS would need to be running during the conversion, which does not seem safe.

See TestCoverAll in convert/convert_test.go

dir, _close, s1, s2 := testutil.PrepareTest(t, 2000, 2000)
defer _close(t)

testutil.PatchConfig(t, path.Join(dir, "config"), "testfiles/badger2Spec")

os.Setenv(EnvDir, dir)
run([]string{".", "convert"})

testutil.FinishTest(t, dir, s1, s2, 2000, 2000)
}

func TestBasicRevertBadger2(t *testing.T) {
dir, _close, s1, s2 := testutil.PrepareTest(t, 200, 200)
defer _close(t)

testutil.PatchConfig(t, path.Join(dir, "config"), "testfiles/badger2Spec")

os.Setenv(EnvDir, dir)
run([]string{".", "convert", "--keep"})

testutil.FinishTest(t, dir, s1, s2, 200, 200)

os.Setenv(EnvDir, dir)
run([]string{".", "revert", "--force", "--fix-config"})

testutil.FinishTest(t, dir, s1, s2, 200, 200)
}

func TestBasicCleanupBadger2(t *testing.T) {
dir, _close, s1, s2 := testutil.PrepareTest(t, 200, 200)
defer _close(t)

testutil.PatchConfig(t, path.Join(dir, "config"), "testfiles/badger2Spec")

os.Setenv(EnvDir, dir)
run([]string{".", "convert", "--keep"})

testutil.FinishTest(t, dir, s1, s2, 200, 200)

os.Setenv(EnvDir, dir)
run([]string{".", "cleanup"})

testutil.FinishTest(t, dir, s1, s2, 200, 200)
}
10 changes: 10 additions & 0 deletions config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var validators = map[string]func(*validatorContext, map[string]interface{}) erro

func init() {
validators["badgerds"] = badgerdsValidator
validators["badger2ds"] = badger2dsValidator
validators["flatfs"] = flatfsValidator
validators["levelds"] = leveldsValidator
validators["log"] = logValidator
Expand Down Expand Up @@ -130,6 +131,15 @@ func badgerdsValidator(ctx *validatorContext, dsConfiguration map[string]interfa
return nil
}

func badger2dsValidator(ctx *validatorContext, dsConfiguration map[string]interface{}) error {
err := checkPath(ctx, dsConfiguration["path"])
if err != nil {
return err
}

return nil
}

func mountValidator(ctx *validatorContext, dsConfiguration map[string]interface{}) error {
mounts, ok := dsConfiguration["mounts"].([]interface{})
if !ok {
Expand Down
42 changes: 36 additions & 6 deletions config/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ var (
"compression": "none",
},
},
map[string]interface{}{
"mountpoint": "/other2",
"type": "measure",
"prefix": "badger2.datastore",
"child": map[string]interface{}{
"type": "badger2ds",
"path": "badger2Datastore",
"compression": "none",
},
},
},
}

Expand All @@ -61,6 +71,11 @@ var (
"compression": "none",
}

InvalidBadger2dsPathSpec = map[string]interface{}{
"type": "badger2ds",
"compression": "none",
}

LeveldbNoCompression = map[string]interface{}{
"type": "levelds",
"path": "levelDatastore",
Expand Down Expand Up @@ -167,14 +182,17 @@ func TestValidate(t *testing.T) {

sort.Strings(dirs)

if dirs[0] != "badgerDatastore" {
t.Errorf(`dirs[0] != "badgerDatastore" got %s `, dirs[0])
if dirs[0] != "badger2Datastore" {
t.Errorf(`dirs[0] != "badger2Datastore" got %s `, dirs[0])
}
if dirs[1] != "badgerDatastore" {
t.Errorf(`dirs[0] != "badgerDatastore" got %s `, dirs[1])
}
if dirs[1] != "blocks" {
t.Errorf(`dirs[0] != "blocks" got %s `, dirs[1])
if dirs[2] != "blocks" {
t.Errorf(`dirs[0] != "blocks" got %s `, dirs[2])
}
if dirs[2] != "levelDatastore" {
t.Errorf(`dirs[0] != "levelDatastore" got %s `, dirs[2])
if dirs[3] != "levelDatastore" {
t.Errorf(`dirs[0] != "levelDatastore" got %s `, dirs[3])
}
}

Expand Down Expand Up @@ -226,6 +244,18 @@ func TestInvalidBadgerdsPathSpec(t *testing.T) {
t.Errorf("expected error")
}

func TestInvalidBadger2dsPathSpec(t *testing.T) {
_, err := Validate(InvalidBadger2dsPathSpec, false)
if err != nil {
if strings.Contains(err.Error(), "invalid 'path' type in datastore") {
return
}
t.Errorf("unexpected error: %s", err)
}

t.Errorf("expected error")
}

func TestLeveldbSpec(t *testing.T) {
_, err := Validate(LeveldbNoCompression, false)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ go 1.14
require (
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-ds-badger v0.2.5
github.com/ipfs/go-ds-badger2 v0.1.1-0.20200930015122-da4821a7ffe4
github.com/ipfs/go-ds-flatfs v0.4.5
github.com/ipfs/go-ds-leveldb v0.4.2
github.com/ipfs/go-ds-measure v0.1.0
github.com/ipfs/go-fs-lock v0.0.6
github.com/ipfs/go-ipfs v0.7.0
github.com/ipfs/go-ipfs-config v0.9.0
github.com/ipfs/go-ipfs v0.7.1-0.20200930073312-b956e64be61b
github.com/ipfs/go-ipfs-config v0.9.1-0.20200924122122-49c7675a694d
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/syndtr/goleveldb v1.0.0
Expand Down
25 changes: 21 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOv
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Kubuxu/go-os-helper v0.0.1 h1:EJiD2VUQyh5A9hWJLmc6iWg6yIcJ7jpBcwC8GMGXfDk=
github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
Expand Down Expand Up @@ -119,8 +121,12 @@ github.com/dgraph-io/badger v1.6.1 h1:w9pSFNSdq/JPM1N12Fz/F/bzo993Is1W+Q7HjPzi7y
github.com/dgraph-io/badger v1.6.1/go.mod h1:FRmFw3uxvcpa8zG3Rxs0th+hCLIuaQg8HlNV5bjgnuU=
github.com/dgraph-io/badger v1.6.2 h1:mNw0qs90GVgGGWylh0umH5iag1j6n/PeJtNvL6KY/x8=
github.com/dgraph-io/badger v1.6.2/go.mod h1:JW2yswe3V058sS0kZ2h/AXeDSqFjxnZcRrVH//y2UQE=
github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20200928190309-8e06ab6e719e h1:aHGNSe6469hEl4ojh2UBc25kCDAA3FY+tGjtadMLRSw=
github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20200928190309-8e06ab6e719e/go.mod h1:2uGEvGm+JSDLd5UAaKIFSbXDcYyeH0fWJP4N2HMMYMI=
github.com/dgraph-io/ristretto v0.0.2 h1:a5WaUrDa0qm0YrAAS1tUykT5El3kt62KNZZeMxQn3po=
github.com/dgraph-io/ristretto v0.0.2/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E=
github.com/dgraph-io/ristretto v0.0.4-0.20200906165740-41ebdbffecfd h1:KoJOtZf+6wpQaDTuOWGuo61GxcPBIfhwRxRTaTWGCTc=
github.com/dgraph-io/ristretto v0.0.4-0.20200906165740-41ebdbffecfd/go.mod h1:YylP9MpCYGVZQrly/j/diqcdUetCRRePeBB0c2VGXsA=
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f h1:dDxpBYafY/GYpcl+LS4Bn3ziLPuEdGRkRjYAbSlWxSA=
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
Expand Down Expand Up @@ -195,6 +201,8 @@ github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -316,6 +324,8 @@ github.com/ipfs/go-ds-badger v0.2.4 h1:UPGB0y7luFHk+mY/tUZrif/272M8o+hFsW+avLUeW
github.com/ipfs/go-ds-badger v0.2.4/go.mod h1:pEYw0rgg3FIrywKKnL+Snr+w/LjJZVMTBRn4FS6UHUk=
github.com/ipfs/go-ds-badger v0.2.5 h1:oKRP6xVdgunjioOvaW4Ue2N7rBI7h/sWNERHTguUmpE=
github.com/ipfs/go-ds-badger v0.2.5/go.mod h1:02rnztVKA4aZwDuaRPTf8mpqcKmXP7mLl6JPxd14JHA=
github.com/ipfs/go-ds-badger2 v0.1.1-0.20200930015122-da4821a7ffe4 h1:DyXjWhKJaGzN6nri3X93lIjgCH+LR+G3dmPJp2nZIVQ=
github.com/ipfs/go-ds-badger2 v0.1.1-0.20200930015122-da4821a7ffe4/go.mod h1:2Y9+V1wfn39CcFmPg8aselrj0Ifd5ek4O7gvQhpeCz4=
github.com/ipfs/go-ds-flatfs v0.4.5 h1:4QceuKEbH+HVZ2ZommstJMi3o3II+dWS3IhLaD7IGHs=
github.com/ipfs/go-ds-flatfs v0.4.5/go.mod h1:e4TesLyZoA8k1gV/yCuBTnt2PJtypn4XUlB5n8KQMZY=
github.com/ipfs/go-ds-leveldb v0.0.1 h1:Z0lsTFciec9qYsyngAw1f/czhRU35qBLR2vhavPFgqA=
Expand All @@ -332,8 +342,8 @@ github.com/ipfs/go-fs-lock v0.0.6 h1:sn3TWwNVQqSeNjlWy6zQ1uUGAZrV3hPOyEA6y1/N2a0
github.com/ipfs/go-fs-lock v0.0.6/go.mod h1:OTR+Rj9sHiRubJh3dRhD15Juhd/+w6VPOY28L7zESmM=
github.com/ipfs/go-graphsync v0.1.1 h1:bFDAYS0Z48yd8ROPI6f/zIVmJxaDLA6m8cVuJPKC5fE=
github.com/ipfs/go-graphsync v0.1.1/go.mod h1:jMXfqIEDFukLPZHqDPp8tJMbHO9Rmeb9CEGevngQbmE=
github.com/ipfs/go-ipfs v0.7.0 h1:8qJkP8PounMHhbWJ+sOij5FV3mlJhP+mhCg2JeDV1mg=
github.com/ipfs/go-ipfs v0.7.0/go.mod h1:4UNBZMgbAZ6/+xUZDlMkGxMFPiu1RB67+TaNVvKV7ZQ=
github.com/ipfs/go-ipfs v0.7.1-0.20200930073312-b956e64be61b h1:FddLZ9lF/4kwgJ33qmlhGcS0kt4HrVL4zF4YItXvRWk=
github.com/ipfs/go-ipfs v0.7.1-0.20200930073312-b956e64be61b/go.mod h1:bFYE8U73hYWGmrBjColpU5ovSz3PWft4fDwQCfWb10g=
github.com/ipfs/go-ipfs-blockstore v0.0.1 h1:O9n3PbmTYZoNhkgkEyrXTznbmktIXif62xLX+8dPHzc=
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
github.com/ipfs/go-ipfs-blockstore v0.1.0/go.mod h1:5aD0AvHPi7mZc6Ci1WCAhiBQu2IsfTduLl+422H6Rqw=
Expand All @@ -346,8 +356,8 @@ github.com/ipfs/go-ipfs-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7Na
github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8=
github.com/ipfs/go-ipfs-cmds v0.4.0 h1:xUavIxA9Ts8U6PAHmQBvDGMlGfUrQ13Rymd+5t8LIF4=
github.com/ipfs/go-ipfs-cmds v0.4.0/go.mod h1:ZgYiWVnCk43ChwoH8hAmI1IRbuVtq3GSTHwtRB/Kqhk=
github.com/ipfs/go-ipfs-config v0.9.0 h1:qTXJ9CyOyQv1LFJUMysxz8fi6RxxnP9QqcmiobuANvw=
github.com/ipfs/go-ipfs-config v0.9.0/go.mod h1:GQUxqb0NfkZmEU92PxqqqLVVFTLpoGGUlBaTyDaAqrE=
github.com/ipfs/go-ipfs-config v0.9.1-0.20200924122122-49c7675a694d h1:vrPLIqBYr8WR0h2VGPJbi/OydxEJgU3ZGGK302Sg4u4=
github.com/ipfs/go-ipfs-config v0.9.1-0.20200924122122-49c7675a694d/go.mod h1:GQUxqb0NfkZmEU92PxqqqLVVFTLpoGGUlBaTyDaAqrE=
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1IeRQ=
github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
Expand Down Expand Up @@ -412,6 +422,7 @@ github.com/ipfs/go-log/v2 v2.0.2/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBW
github.com/ipfs/go-log/v2 v2.0.3 h1:Q2gXcBoCALyLN/pUQlz1qgu0x3uFV6FzP9oXhpfyJpc=
github.com/ipfs/go-log/v2 v2.0.3/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBWFaa9+0=
github.com/ipfs/go-log/v2 v2.0.5/go.mod h1:eZs4Xt4ZUJQFM3DlanGhy7TkwwawCZcSByscwkWG+dw=
github.com/ipfs/go-log/v2 v2.0.8/go.mod h1:eZs4Xt4ZUJQFM3DlanGhy7TkwwawCZcSByscwkWG+dw=
github.com/ipfs/go-log/v2 v2.1.1 h1:G4TtqN+V9y9HY9TA6BwbCVyyBZ2B9MbCjR2MtGx8FR0=
github.com/ipfs/go-log/v2 v2.1.1/go.mod h1:2v2nsGfZsvvAJz13SyFzf9ObaqwHiHxsPLEHntrv9KM=
github.com/ipfs/go-merkledag v0.0.3 h1:A5DlOMzqTRDVmdgkf3dzCKCFmVWH4Zqwb0cbYXUs+Ro=
Expand Down Expand Up @@ -1186,6 +1197,8 @@ go.uber.org/zap v1.14.1 h1:nYDKopTbvAPq/NrUVZwT15y2lpROBiLLyoRTbXOYWOo=
go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
go4.org v0.0.0-20200411211856-f5505b9728dd h1:BNJlw5kRTzdmyfh5U8F93HA2OwkP7ZGwA51eJ/0wKOU=
go4.org v0.0.0-20200411211856-f5505b9728dd/go.mod h1:CIiUVy99QCPfoE13bO4EZaz5GZMZXMSBGhxRdsvzbkg=
Expand Down Expand Up @@ -1216,6 +1229,8 @@ golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1344,6 +1359,8 @@ golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c h1:/h0vtH0PyU0xAoZJVcRw1k0Ng+U0JAy3QDiFmppIlIE=
golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
63 changes: 63 additions & 0 deletions repo/badger2ds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package repo

import (
"fmt"
"os"
"path/filepath"

badger2ds "github.com/ipfs/go-ds-badger2"
)

type badger2dsDatastoreConfig struct {
path string
syncWrites bool
}

// Badger2dsDatastoreConfig returns a configuration stub for a badger2
// datastore from the given parameters
func Badger2dsDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
var c badger2dsDatastoreConfig
var ok bool

c.path, ok = params["path"].(string)
if !ok {
return nil, fmt.Errorf("'path' field is missing or not string")
}

sw, ok := params["syncWrites"]
if !ok {
c.syncWrites = true
} else {
if swb, ok := sw.(bool); ok {
c.syncWrites = swb
} else {
return nil, fmt.Errorf("'syncWrites' field was not a boolean")
}
}

return &c, nil
}

func (c *badger2dsDatastoreConfig) DiskSpec() DiskSpec {
return map[string]interface{}{
"type": "badger2ds",
"path": c.path,
}
}

func (c *badger2dsDatastoreConfig) Create(path string) (Datastore, error) {
p := c.path
if !filepath.IsAbs(p) {
p = filepath.Join(path, p)
}

err := os.MkdirAll(p, 0755)
if err != nil {
return nil, err
}

defopts := badger2ds.DefaultOptions
defopts.SyncWrites = c.syncWrites

return badger2ds.NewDatastore(p, &defopts)
}
2 changes: 1 addition & 1 deletion repo/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ const (
SpecsFile = "datastore_spec"

SupportedRepoVersion = 10
ToolVersion = "0.5.0"
ToolVersion = "0.6.0"
)
15 changes: 8 additions & 7 deletions repo/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ var datastores map[string]ConfigFromMap

func init() {
datastores = map[string]ConfigFromMap{
"mount": MountDatastoreConfig,
"flatfs": FlatfsDatastoreConfig,
"levelds": LeveldsDatastoreConfig,
"badgerds": BadgerdsDatastoreConfig,
"mem": MemDatastoreConfig,
"log": LogDatastoreConfig,
"measure": MeasureDatastoreConfig,
"mount": MountDatastoreConfig,
"flatfs": FlatfsDatastoreConfig,
"levelds": LeveldsDatastoreConfig,
"badgerds": BadgerdsDatastoreConfig,
"badger2ds": Badger2dsDatastoreConfig,
"mem": MemDatastoreConfig,
"log": LogDatastoreConfig,
"measure": MeasureDatastoreConfig,
}
}

Expand Down
14 changes: 8 additions & 6 deletions strategy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ var skipTypes = map[string]string{
}

var dsTypes = map[string]bool{
"flatfs": true,
"levelds": true,
"badgerds": true,
"flatfs": true,
"levelds": true,
"badgerds": true,
"badger2ds": true,
}

//datastors that have one directory inside IPFS repo
var simpleTypes = map[string]bool{
"flatfs": true,
"levelds": true,
"badgerds": true,
"flatfs": true,
"levelds": true,
"badgerds": true,
"badger2ds": true,
}

func NewStrategy(fromSpecIn, toSpecIn map[string]interface{}) (Strategy, error) {
Expand Down
Loading