Skip to content

Commit

Permalink
Merge pull request #5187 from ipfs/feat/datastore-plugins
Browse files Browse the repository at this point in the history
Add support for datastore plugins
  • Loading branch information
Stebalien committed Oct 5, 2018
2 parents 70ebea5 + 7b9cfda commit ab9e211
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
14 changes: 14 additions & 0 deletions plugin/datastore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package plugin

import (
"github.com/ipfs/go-ipfs/repo/fsrepo"
)

// PluginDatastore is an interface that can be implemented to add handlers for
// for different datastores
type PluginDatastore interface {
Plugin

DatastoreTypeName() string
DatastoreConfigParser() fsrepo.ConfigFromMap
}
8 changes: 7 additions & 1 deletion plugin/loader/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package loader
import (
"github.com/ipfs/go-ipfs/core/coredag"
"github.com/ipfs/go-ipfs/plugin"
"gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"
"github.com/ipfs/go-ipfs/repo/fsrepo"

"gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
)

Expand Down Expand Up @@ -32,6 +33,11 @@ func run(plugins []plugin.Plugin) error {
if err != nil {
return err
}
case plugin.PluginDatastore:
err := fsrepo.AddDatastoreConfigHandler(pl.DatastoreTypeName(), pl.DatastoreConfigParser())
if err != nil {
return err
}
default:
panic(pl)
}
Expand Down
17 changes: 16 additions & 1 deletion repo/fsrepo/datastores.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ type DatastoreConfig interface {
Create(path string) (repo.Datastore, error)
}

// DiskSpec is the type returned by the DatastoreConfig's DiskSpec method
// DiskSpec is a minimal representation of the characteristic values of the
// datastore. If two diskspecs are the same, the loader assumes that they refer
// to exactly the same datastore. If they differ at all, it is assumed they are
// completely different datastores and a migration will be performed. Runtime
// values such as cache options or concurrency options should not be added
// here.
type DiskSpec map[string]interface{}

// Bytes returns a minimal JSON encoding of the DiskSpec
Expand Down Expand Up @@ -68,6 +73,16 @@ func init() {
}
}

func AddDatastoreConfigHandler(name string, dsc ConfigFromMap) error {
_, ok := datastores[name]
if ok {
return fmt.Errorf("already have a datastore named %q", name)
}

datastores[name] = dsc
return nil
}

// AnyDatastoreConfig returns a DatastoreConfig from a spec based on
// the "type" parameter
func AnyDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
Expand Down

0 comments on commit ab9e211

Please sign in to comment.