Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Badger datastore #4007

Merged
merged 11 commits into from
Sep 8, 2017
Merged
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,10 @@
"version": "1.1.11"
},
{
"author": "whyrusleeping",
"hash": "QmWRCn8vruNAzHx8i6SAXinuheRitKEGu8c7m26stKvsYx",
"name": "go-testutil",
"version": "1.1.11"
"author": "magik6k",
"hash": "QmNWbaGdPCA3anCcvh4jm3VAahAbmmAsU58sp8Ti4KTJkL",
"name": "go-ds-badger",
"version": "0.2.0"
}
],
"gxVersion": "0.10.0",
Expand Down
7 changes: 7 additions & 0 deletions repo/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ var ConfigProfiles = map[string]func(*Config) error{
c.Discovery.MDNS.Enabled = false
return nil
},
"badgerds": func(c *Config) error {
c.Datastore.Spec = map[string]interface{}{
"type": "badgerds",
"path": "badgerds",
}
return nil
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be missing something, but won't this config bypass the measure datastore? If so will this create a problem?

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC there is global measure in fsrepo

58 changes: 51 additions & 7 deletions repo/fsrepo/datastores.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import (
"bytes"
"encoding/json"
"fmt"
"os"
"path/filepath"
"sort"

repo "github.com/ipfs/go-ipfs/repo"

levelds "gx/ipfs/QmPdvXuXWAR6gtxxqZw42RtSADMwz4ijVmYHGS542b6cMz/go-ds-leveldb"
measure "gx/ipfs/QmSb95iHExSSb47zpmyn5CyY5PZidVWSjyKyDqgYQrnKor/go-ds-measure"
flatfs "gx/ipfs/QmUTshC2PP4ZDqkrFfDU4JGJFMWjYnunxPgkQ6ZCA2hGqh/go-ds-flatfs"

ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore"
mount "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/syncmount"

badgerds "gx/ipfs/QmNWbaGdPCA3anCcvh4jm3VAahAbmmAsU58sp8Ti4KTJkL/go-ds-badger"
levelds "gx/ipfs/QmPdvXuXWAR6gtxxqZw42RtSADMwz4ijVmYHGS542b6cMz/go-ds-leveldb"
ldbopts "gx/ipfs/QmbBhyDKsY4mbY6xsKt3qu9Y7FPvMJ6qbD8AMjYYvPRw1g/goleveldb/leveldb/opt"
)

Expand Down Expand Up @@ -55,12 +59,13 @@ var datastores map[string]ConfigFromMap

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

Expand Down Expand Up @@ -333,3 +338,42 @@ func (c measureDatastoreConfig) Create(path string) (repo.Datastore, error) {
}
return measure.New(c.prefix, child), nil
}

type badgerdsDatastoreConfig struct {
path string
}

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

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

return &c, nil
}

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

func (c *badgerdsDatastoreConfig) Create(path string) (repo.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
}

return badgerds.NewDatastore(p, nil)
}