mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
* include pebble as built-in plugin Pebble provides a high-performance alternative to leveldb as the datastore, and will serve as a replacement for badger1. There are a number of tuning parameters available for tuning pebble's performance to your specific needs. Default values are used for any that are not configured or are set to the parameter's zero-value. Requires https://github.com/ipfs/go-ds-pebble/pull/39 Closes #10347 * docs: remove mention of ipfs-ds-convert. Rationale: https://github.com/ipfs/ipfs-ds-convert/issues/50 * docs: pebbleds profile * test: meaningful t0025-datastores.sh * Update config/init.go * Update docs/config.md * Do not hard-code zero values into pebble config
89 lines
1.9 KiB
Go
89 lines
1.9 KiB
Go
package levelds
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/ipfs/kubo/plugin"
|
|
"github.com/ipfs/kubo/repo"
|
|
"github.com/ipfs/kubo/repo/fsrepo"
|
|
|
|
levelds "github.com/ipfs/go-ds-leveldb"
|
|
ldbopts "github.com/syndtr/goleveldb/leveldb/opt"
|
|
)
|
|
|
|
// Plugins is exported list of plugins that will be loaded.
|
|
var Plugins = []plugin.Plugin{
|
|
&leveldsPlugin{},
|
|
}
|
|
|
|
type leveldsPlugin struct{}
|
|
|
|
var _ plugin.PluginDatastore = (*leveldsPlugin)(nil)
|
|
|
|
func (*leveldsPlugin) Name() string {
|
|
return "ds-level"
|
|
}
|
|
|
|
func (*leveldsPlugin) Version() string {
|
|
return "0.1.0"
|
|
}
|
|
|
|
func (*leveldsPlugin) Init(_ *plugin.Environment) error {
|
|
return nil
|
|
}
|
|
|
|
func (*leveldsPlugin) DatastoreTypeName() string {
|
|
return "levelds"
|
|
}
|
|
|
|
type datastoreConfig struct {
|
|
path string
|
|
compression ldbopts.Compression
|
|
}
|
|
|
|
// DatastoreConfigParser returns a configuration stub for a badger datastore
|
|
// from the given parameters.
|
|
func (*leveldsPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap {
|
|
return func(params map[string]interface{}) (fsrepo.DatastoreConfig, error) {
|
|
var c datastoreConfig
|
|
var ok bool
|
|
|
|
c.path, ok = params["path"].(string)
|
|
if !ok {
|
|
return nil, fmt.Errorf("'path' field is missing or not string")
|
|
}
|
|
|
|
switch cm := params["compression"]; cm {
|
|
case "none":
|
|
c.compression = ldbopts.NoCompression
|
|
case "snappy":
|
|
c.compression = ldbopts.SnappyCompression
|
|
case "", nil:
|
|
c.compression = ldbopts.DefaultCompression
|
|
default:
|
|
return nil, fmt.Errorf("unrecognized value for compression: %s", cm)
|
|
}
|
|
|
|
return &c, nil
|
|
}
|
|
}
|
|
|
|
func (c *datastoreConfig) DiskSpec() fsrepo.DiskSpec {
|
|
return map[string]interface{}{
|
|
"type": "levelds",
|
|
"path": c.path,
|
|
}
|
|
}
|
|
|
|
func (c *datastoreConfig) Create(path string) (repo.Datastore, error) {
|
|
p := c.path
|
|
if !filepath.IsAbs(p) {
|
|
p = filepath.Join(path, p)
|
|
}
|
|
|
|
return levelds.NewDatastore(p, &levelds.Options{
|
|
Compression: c.compression,
|
|
})
|
|
}
|