This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Add support for converting badger2 datastore #26
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ae4b1dc
Add support for converting badger2 datastore
gammazero 5a815a6
Add conversion tests for all datastore types
gammazero 913977e
Remove rudundant cli tests
gammazero 69f2254
Remove rudundant strategy tests
gammazero e388605
Update deps
gammazero 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
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 |
---|---|---|
@@ -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) | ||
} |
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 |
---|---|---|
|
@@ -6,5 +6,5 @@ const ( | |
SpecsFile = "datastore_spec" | ||
|
||
SupportedRepoVersion = 10 | ||
ToolVersion = "0.5.0" | ||
ToolVersion = "0.6.0" | ||
) |
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
Oops, something went wrong.
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.
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:
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.
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.
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
inconvert/convert_test.go