-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[WIP] Badger datastore #4007
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fe42bf9
Initial badger ds support
magik6k bc27b9d
badgerds: update datastore hooks
magik6k c79bccf
badgerds: use go-ds-badger from gx
magik6k c310e3d
badgerds: implement DiskSpec
magik6k 0004008
add badger init profile
whyrusleeping 167f5c7
update badger dep
whyrusleeping f200445
fixup package.json
whyrusleeping 152a9fa
add godoc
whyrusleeping 526a0ac
add measure layer to badgerds profile defaults
whyrusleeping a9b8b90
add option to set syncWrites to badger
whyrusleeping 80757f3
update go-ds-badger
Stebalien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,21 @@ 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" | ||
badger "gx/ipfs/QmQL7yJ4iWQdeAH9WvgJ4XYHS6m5DqL853Cck5SaUb8MAw/badger" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't declared in package.json. However, if you update to go-ds-badger 0.2.1, you can use the re-exported |
||
ldbopts "gx/ipfs/QmbBhyDKsY4mbY6xsKt3qu9Y7FPvMJ6qbD8AMjYYvPRw1g/goleveldb/leveldb/opt" | ||
) | ||
|
||
|
@@ -55,12 +60,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, | ||
} | ||
} | ||
|
||
|
@@ -333,3 +339,57 @@ func (c measureDatastoreConfig) Create(path string) (repo.Datastore, error) { | |
} | ||
return measure.New(c.prefix, child), nil | ||
} | ||
|
||
type badgerdsDatastoreConfig struct { | ||
path string | ||
syncWrites bool | ||
} | ||
|
||
// 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") | ||
} | ||
|
||
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 *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 | ||
} | ||
|
||
defopts := badger.DefaultOptions | ||
defopts.SyncWrites = c.syncWrites | ||
|
||
return badgerds.NewDatastore(p, &defopts) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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