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 all commits
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
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
55 changes: 55 additions & 0 deletions convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,61 @@ import (
testutil "github.com/ipfs/ipfs-ds-convert/testutil"
)

func TestConvertAll(t *testing.T) {
const (
levelSpec = "../testfiles/defaultSpec"
keys = 300
blocks = 300
)

// Each test case specifies a datastore spec to intiialize. That datastore
// is then converted to a leveldb datastore, and then converted back.
//
// TODO: enable testing on mem datastore.
testCases := []struct {
name string
specPath string
}{
{name: "badger", specPath: "../testfiles/badgerSpec"},
{name: "badger2", specPath: "../testfiles/badger2Spec"},
{name: "flatfs", specPath: "../testfiles/flatfsSpec"},
{name: "leveldb", specPath: levelSpec},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
spec := make(map[string]interface{})
err := config.Load(tc.specPath, &spec)
if err != nil {
t.Fatal(err)
}

// Create datastore for spec in testcase
dir, _close, s1, s2 := testutil.PrepareTestSpec(t, keys, blocks, spec)
defer _close(t)

// Patch config to leveldb datastore and convert
testutil.PatchConfig(t, path.Join(dir, "config"), levelSpec)
t.Log("Converting datastore from", tc.name, "to leveldb")
err = convert.Convert(dir, false)
if err != nil {
t.Fatal(err)
}

// Patch config back to original datastore and convert
testutil.PatchConfig(t, path.Join(dir, "config"), tc.specPath)
t.Log("Converting datastore from leveldb to", tc.name)
err = convert.Convert(dir, false)
if err != nil {
t.Fatal(err)
}

// Verify keys in final resulting datastore.
testutil.FinishTest(t, dir, s1, s2, keys, blocks)
})
}
}

func TestBasicConvert(t *testing.T) {
//Prepare repo
dir, _close, s1, s2 := testutil.PrepareTest(t, 3000, 3000)
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ 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-badger v0.2.6
github.com/ipfs/go-ds-badger2 v0.1.1-0.20201009224942-a4499bb2f243
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.10.0
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/syndtr/goleveldb v1.0.0
Expand Down
35 changes: 29 additions & 6 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,14 @@ 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/badger/v2 v2.0.1-rc1.0.20201002071632-68fb85d55d4b h1:VgR+yRZIkekGY7XsxomIlp4S/24hOWtMjPFHkYBOYWU=
github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20201002071632-68fb85d55d4b/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 +203,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 @@ -314,8 +324,12 @@ github.com/ipfs/go-ds-badger v0.2.1/go.mod h1:Tx7l3aTph3FMFrRS838dcSJh+jjA7cX9Dr
github.com/ipfs/go-ds-badger v0.2.3/go.mod h1:pEYw0rgg3FIrywKKnL+Snr+w/LjJZVMTBRn4FS6UHUk=
github.com/ipfs/go-ds-badger v0.2.4 h1:UPGB0y7luFHk+mY/tUZrif/272M8o+hFsW+avLUeWrM=
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-badger v0.2.6 h1:Hy8jw4rifxtRDrqpvC1yh36oIyE37KDzsUzlHUPOFiU=
github.com/ipfs/go-ds-badger v0.2.6/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-badger2 v0.1.1-0.20201009224942-a4499bb2f243 h1:DWi5c08OnEQgWCwIeM7z3+NYdbgHrHBeFfJMf+fV2wo=
github.com/ipfs/go-ds-badger2 v0.1.1-0.20201009224942-a4499bb2f243/go.mod h1:geztm0cnqsINb53cgj/Iw3HuFVefrIApmltHODtgiO8=
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 +346,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 +360,10 @@ 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-config v0.10.0 h1:QdTFdqCg3Zpvpz6wHc6B7UGwSnierqq0h8BwyUntjGA=
github.com/ipfs/go-ipfs-config v0.10.0/go.mod h1:Ei/FLgHGTdPyqCPK0oPCwGTe8VSnsjJjx7HZqUb6Ry0=
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 +428,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 +1203,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 +1235,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 +1365,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"
)
5 changes: 5 additions & 0 deletions repo/measureds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
measure "github.com/ipfs/go-ds-measure"
)

type measureDatastoreConfig struct {
child DatastoreConfig
prefix string
}

// MeasureDatastoreConfig returns a measure DatastoreConfig from a spec
func MeasureDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
childField, ok := params["child"].(map[string]interface{})
Expand Down
5 changes: 0 additions & 5 deletions repo/memds.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,3 @@ func (c *memDatastoreConfig) DiskSpec() DiskSpec {
func (c *memDatastoreConfig) Create(string) (Datastore, error) {
return ds.NewMapDatastore(), nil
}

type measureDatastoreConfig struct {
child DatastoreConfig
prefix string
}
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
Loading