From 26f5c9199b0d4cf49b316919f6bab726b917229f Mon Sep 17 00:00:00 2001 From: Shaoxiong Li Date: Tue, 6 Nov 2018 15:15:36 +0900 Subject: [PATCH 1/5] plugin/plugins: add rados implementation for datastore backend License: MIT Signed-off-by: Shaoxiong Li --- plugin/plugins/Rules.mk | 2 +- plugin/plugins/rados/rados.go | 78 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 plugin/plugins/rados/rados.go diff --git a/plugin/plugins/Rules.mk b/plugin/plugins/Rules.mk index 80924bad202..e7840008f2e 100644 --- a/plugin/plugins/Rules.mk +++ b/plugin/plugins/Rules.mk @@ -1,6 +1,6 @@ include mk/header.mk -$(d)_plugins:=$(d)/git $(d)/badgerds $(d)/flatfs $(d)/levelds +$(d)_plugins:=$(d)/git $(d)/badgerds $(d)/flatfs $(d)/levelds $(d)/rados $(d)_plugins_so:=$(addsuffix .so,$($(d)_plugins)) $(d)_plugins_main:=$(addsuffix /main/main.go,$($(d)_plugins)) diff --git a/plugin/plugins/rados/rados.go b/plugin/plugins/rados/rados.go new file mode 100644 index 00000000000..c71c00a11ad --- /dev/null +++ b/plugin/plugins/rados/rados.go @@ -0,0 +1,78 @@ +package radosds + +import ( + "fmt" + "os" + + "github.com/ipfs/go-ipfs/plugin" + "github.com/ipfs/go-ipfs/repo" + "github.com/ipfs/go-ipfs/repo/fsrepo" + + rados "github.com/ipfs/go-ds-rados" +) + +// Plugins is exported list of plugins that will be loaded +var Plugins = []plugin.Plugin{ + &radosPlugin{}, +} + +type radosPlugin struct{} + +var _ plugin.PluginDatastore = (*radosPlugin)(nil) + +func (*radosPlugin) Name() string { + return "ds-rados" +} + +func (*radosPlugin) Version() string { + return "0.1.0" +} + +func (*radosPlugin) Init() error { + return nil +} + +func (*radosPlugin) DatastoreTypeName() string { + return "rados" +} + +type radosDatastoreConfig struct { + confPath string + pool string +} + +func (*radosPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap { + return func(params map[string]interface{}) (fsrepo.DatastoreConfig, error) { + var c radosDatastoreConfig + var ok bool + c.confPath, ok = params["confpath"].(string) + if !ok { + return nil, fmt.Errorf("confpath filed is missing or not string") + } + c.pool, ok = params["pool"].(string) + if !ok { + return nil, fmt.Errorf("'pool' filed is missing or not string") + } + return &c, nil + } +} + +func (c *radosDatastoreConfig) DiskSpec() fsrepo.DiskSpec { + return map[string]interface{}{ + "type": "rados", + "confpath": c.confPath, + "pool": c.pool, + } +} + +func (c *radosDatastoreConfig) Create(string) (repo.Datastore, error) { + _, err := os.Open(c.confPath) + if os.IsNotExist(err) { + return nil, fmt.Errorf("Config file for rados doesn't exist:%s", c.confPath) + } + if os.IsPermission(err) { + return nil, fmt.Errorf("Permission deny for file:%s", c.confPath) + } + + return rados.NewDatastore(c.confPath, c.pool) +} From 22dc8a63e06d4b95af4c807dcfc066c9be2fdfd5 Mon Sep 17 00:00:00 2001 From: Bamvor Zhang Date: Tue, 6 Nov 2018 10:55:57 +0800 Subject: [PATCH 2/5] Update go-ds-rados So we can get go-ds-rados v0.0.3 License: MIT Signed-off-by: Bamvor Zhang --- package.json | 6 ++++++ plugin/plugins/rados/rados.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 19462633b2a..f41ed665a21 100644 --- a/package.json +++ b/package.json @@ -592,6 +592,12 @@ "hash": "QmTzWwfHZr9N6Tnk4iDTtKMWY57D3wik73qNCVo21Bu1UP", "name": "iptb-plugins", "version": "1.0.3" + }, + { + "author": "bjzhang", + "hash": "QmdZuk8xgy7o832HfhMEYFpVfWjGFm9FdgRW4ZatK1nwwQ", + "name": "go-ds-rados", + "version": "0.0.3" } ], "gxVersion": "0.10.0", diff --git a/plugin/plugins/rados/rados.go b/plugin/plugins/rados/rados.go index c71c00a11ad..270ab100ae6 100644 --- a/plugin/plugins/rados/rados.go +++ b/plugin/plugins/rados/rados.go @@ -8,7 +8,7 @@ import ( "github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo/fsrepo" - rados "github.com/ipfs/go-ds-rados" + rados "gx/ipfs/QmdZuk8xgy7o832HfhMEYFpVfWjGFm9FdgRW4ZatK1nwwQ/go-ds-rados" ) // Plugins is exported list of plugins that will be loaded From 290c27f8a0f5750a525f9c8892addfa45b8439ce Mon Sep 17 00:00:00 2001 From: Bamvor Zhang Date: Wed, 7 Nov 2018 14:59:41 +0800 Subject: [PATCH 3/5] travis: add librados-dev License: MIT Signed-off-by: Bamvor Zhang --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index d6d4b360626..e8f71f26484 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,9 @@ env: - TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_go_expensive - TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_sharness_expensive +before_install: + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y librados-dev; fi + install: - make install From 4cac906dabaae828281d6e0d3c4e1c26629d8974 Mon Sep 17 00:00:00 2001 From: Bamvor Zhang Date: Thu, 8 Nov 2018 19:58:31 +0800 Subject: [PATCH 4/5] Update go-ds-rados So we can get go-ds-rados v0.0.4 License: MIT Signed-off-by: Bamvor Zhang --- package.json | 4 ++-- plugin/plugins/rados/rados.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f41ed665a21..f2a0d56dcec 100644 --- a/package.json +++ b/package.json @@ -595,9 +595,9 @@ }, { "author": "bjzhang", - "hash": "QmdZuk8xgy7o832HfhMEYFpVfWjGFm9FdgRW4ZatK1nwwQ", + "hash": "QmYyMML9pPAFqQAtHW56YHzUXK7CBnubB1g7kK123eo98G", "name": "go-ds-rados", - "version": "0.0.3" + "version": "0.0.4" } ], "gxVersion": "0.10.0", diff --git a/plugin/plugins/rados/rados.go b/plugin/plugins/rados/rados.go index 270ab100ae6..cac274cd89e 100644 --- a/plugin/plugins/rados/rados.go +++ b/plugin/plugins/rados/rados.go @@ -8,7 +8,7 @@ import ( "github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo/fsrepo" - rados "gx/ipfs/QmdZuk8xgy7o832HfhMEYFpVfWjGFm9FdgRW4ZatK1nwwQ/go-ds-rados" + rados "gx/ipfs/QmYyMML9pPAFqQAtHW56YHzUXK7CBnubB1g7kK123eo98G/go-ds-rados" ) // Plugins is exported list of plugins that will be loaded From 1ab91e27c17ebfe329d8a1c9f1d6bfea36f8779d Mon Sep 17 00:00:00 2001 From: Bamvor Zhang Date: Thu, 8 Nov 2018 20:14:47 +0800 Subject: [PATCH 5/5] Only build radosds on Linux License: MIT Signed-off-by: Bamvor Zhang --- plugin/plugins/rados/rados.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin/plugins/rados/rados.go b/plugin/plugins/rados/rados.go index cac274cd89e..fd0000daa21 100644 --- a/plugin/plugins/rados/rados.go +++ b/plugin/plugins/rados/rados.go @@ -1,3 +1,5 @@ +// +build linux + package radosds import (