Skip to content

Commit 19f7965

Browse files
committed
fix(plugin): update plugin deps
1 parent 68b14f0 commit 19f7965

File tree

11 files changed

+440
-160
lines changed

11 files changed

+440
-160
lines changed

docs/dev/damocles-manager插件框架.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ damocles-manager 插件机制基于 [Go plugin](https://pkg.go.dev/plugin#sectio
2222
name = "memdb"
2323
# 插件描述
2424
description = "kvstore in memory"
25-
# 插件类型,当前支持: ObjStore | KVStore | SyncSectorState
25+
# 插件类型,当前支持: FileStore | KVStore | SyncSectorState
2626
kind = "KVStore"
2727
# 指定插件的初始化函数
2828
onInit = "OnInit"
@@ -41,35 +41,35 @@ damocles-manager 插件机制基于 [Go plugin](https://pkg.go.dev/plugin#sectio
4141
启动 damocles-manager 后会以日志的形式输出所有成功加载的插件。
4242
```
4343
2023-01-13T11:33:09.658+0800 INFO dep dep/sealer_constructor.go:132 loaded plugin 'KVStore/memdb', build time: '2023.01.13 11:32:43'.
44-
2023-01-13T11:33:09.658+0800 INFO dep dep/sealer_constructor.go:132 loaded plugin 'ObjStore/fsstore', build time: '2023.01.13 11:32:43'.
44+
2023-01-13T11:33:09.658+0800 INFO dep dep/sealer_constructor.go:132 loaded plugin 'FileStore/examplefstore', build time: '2023.01.13 11:32:43'.
4545
...
4646
```
4747
---
4848
4949
### 当前支持的插件类型
50-
#### ObjStore 插件
50+
#### FileStore 插件
5151
52-
`ObjStore` 允许用户创建自定的存储类型,例如 s3, fs 等
52+
`FileStore` 允许用户创建自定的存储类型,受 filecoin 封装算法限制,目前只支持文件系统,但是 FileStore 插件支持用户自定义扇区文件的存储路径
5353
5454
##### Manifest:
5555
5656
struct 定义:
5757
```go
58-
type ObjStoreManifest struct {
58+
type FileStoreManifest struct {
5959
Manifest
6060
61-
Constructor func(cfg objstore.Config) (objstore.Store, error)
61+
Constructor func(cfg filestore.Config) (filestore.Store, error)
6262
}
6363
```
6464

6565
manifest.toml 示例:
6666
```toml
6767
# manifest.toml
6868

69-
name = "s3store"
70-
description = "s3 plugin"
71-
# 插件类型设置为: ObjStore
72-
kind = "ObjStore"
69+
name = "mystore"
70+
description = "my filestore plugin"
71+
# 插件类型设置为: FileStore
72+
kind = "FileStore"
7373
onInit = "OnInit"
7474
onShutdown = "OnShutdown"
7575

@@ -79,9 +79,9 @@ export = [
7979
]
8080
```
8181

82-
`ObjStore` 插件只需要额外提供一个 `Constructor` 函数返回实现了 [objstore.Store](https://github.com/ipfs-force-community/venus-objstore/blob/00ad77fcbfed1df5c1613176521bce3ba3041fc7/objstore.go#L50-L61) 接口的对象即可。
82+
`FileStore` 插件只需要额外提供一个 `Constructor` 函数返回实现了 [filestore.Store](https://github.com/ipfs-force-community/damocles/blob/68b14f09025eab2ed7adb5b86ebb0b098fb3063f/manager-plugin/filestore/filestore.go#L75-L103) 接口的对象即可。
8383

84-
`ObjStore` 目前用于 Piece 文件存储 (PieceStore) 与封装后的扇区数据存储 (PersistStores), 当正确配置 ObjStore 插件后, damocles-manager 会调用插件返回的 `objstore.Store` 进行文件读写。
84+
`FileStore` 目前用于 Piece 文件存储 (PieceStore) 与封装后的扇区数据存储 (PersistStores), 当正确配置 FileStore 插件后, damocles-manager 会调用插件返回的 `filesotre.Store` 进行文件读写。
8585

8686
##### PieceStore 插件配置样例
8787

@@ -94,17 +94,17 @@ Dir = "path/to/damocles-manager-plugins-dir"
9494

9595
# damocles-manager 可以配置多个 PieceStore, 每个 PieceStore 都可以使用不同的插件。
9696
[[Common.PieceStores]]
97-
Name = "my-s3-store"
97+
Name = "my-file-store"
9898
Path = "/path"
9999

100100
# 指定插件名称
101101
# 注意: PluginName 不是插件程序的文件名,而是在 manifest.toml 中配置的名称
102-
PluginName = "s3store"
102+
PluginName = "mystore"
103103

104104
[[Common.PieceStores.Meta]]
105105
# Your plugin config here
106-
Bucket = "mybucket"
107-
# ConfigPath = "path/to/my-s3-store-config.toml"
106+
SubDirPattern = "sub-%d-%d"
107+
# ConfigPath = "path/to/my-store-config.toml"
108108
```
109109

110110
PersistStores 的插件配置与 PieceStore 类似,详细请参考 damocles-manager 配置文件说明。
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
9+
"github.com/filecoin-project/go-state-types/abi"
10+
plugin "github.com/ipfs-force-community/damocles/manager-plugin"
11+
pluginfilestore "github.com/ipfs-force-community/damocles/manager-plugin/filestore"
12+
"github.com/shirou/gopsutil/disk"
13+
)
14+
15+
var _ pluginfilestore.Store = (*Store)(nil)
16+
17+
func OnInit(ctx context.Context, pluginsDir string, manifest *plugin.Manifest) error {
18+
return nil
19+
}
20+
21+
func Open(cfg pluginfilestore.Config) (pluginfilestore.Store, error) { // nolint: deadcode
22+
dirPath, err := filepath.Abs(cfg.Path)
23+
if err != nil {
24+
return nil, fmt.Errorf("abs path for %s: %w", cfg.Path, err)
25+
}
26+
27+
stat, err := os.Stat(dirPath)
28+
if err != nil {
29+
return nil, fmt.Errorf("stat for %s: %w", dirPath, err)
30+
}
31+
32+
if !stat.IsDir() {
33+
return nil, fmt.Errorf("%s is not a dir", dirPath)
34+
}
35+
36+
cfg.Path = dirPath
37+
if cfg.Name == "" {
38+
cfg.Name = dirPath
39+
}
40+
41+
return &Store{
42+
cfg: cfg,
43+
}, nil
44+
}
45+
46+
type Store struct {
47+
cfg pluginfilestore.Config
48+
}
49+
50+
func (s *Store) Type() string {
51+
return "builtin-filesotre"
52+
}
53+
54+
func (*Store) Version() string {
55+
return "example"
56+
}
57+
58+
func (s *Store) Instance(context.Context) string { return s.cfg.Name }
59+
60+
func (s *Store) InstanceConfig(_ context.Context) pluginfilestore.Config {
61+
return s.cfg
62+
}
63+
64+
func (s *Store) InstanceInfo(ctx context.Context) (pluginfilestore.InstanceInfo, error) {
65+
usage, err := disk.UsageWithContext(ctx, s.cfg.Path)
66+
if err != nil {
67+
return pluginfilestore.InstanceInfo{}, fmt.Errorf("get disk usage: %w", err)
68+
}
69+
70+
return pluginfilestore.InstanceInfo{
71+
Config: s.cfg,
72+
Type: usage.Fstype,
73+
Total: usage.Total,
74+
Free: usage.Free,
75+
Used: usage.Used,
76+
UsedPercent: usage.UsedPercent,
77+
}, nil
78+
}
79+
80+
func (s *Store) SubPath(ctx context.Context, pathType pluginfilestore.PathType, sectorID *pluginfilestore.SectorID, custom *string) (subPath string, err error) {
81+
if pathType == pluginfilestore.PathTypeCustom {
82+
if custom == nil {
83+
return "", fmt.Errorf("sectorID cannot be nil")
84+
}
85+
return *custom, nil
86+
}
87+
88+
if sectorID == nil {
89+
return "", fmt.Errorf("sectorID cannot be nil")
90+
}
91+
92+
sid := abi.SectorID{
93+
Miner: abi.ActorID(sectorID.Miner),
94+
Number: abi.SectorNumber(sectorID.Number),
95+
}
96+
97+
return filepath.Join(string(pathType), FormatSectorID(sid)), nil
98+
}
99+
100+
const sectorIDFormat = "s-t0%d-%d"
101+
102+
func FormatSectorID(sid abi.SectorID) string {
103+
return fmt.Sprintf(sectorIDFormat, sid.Miner, sid.Number)
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module github.com/ipfs-force-community/damocles/manager-plugin/examples/examplefstore
2+
3+
go 1.20
4+
5+
require (
6+
github.com/filecoin-project/go-state-types v0.11.1
7+
github.com/ipfs-force-community/damocles/manager-plugin v0.0.0-20230913074304-520ac6d716fa
8+
github.com/shirou/gopsutil v2.18.12+incompatible
9+
)
10+
11+
require (
12+
github.com/StackExchange/wmi v1.2.1 // indirect
13+
github.com/filecoin-project/go-address v1.1.0 // indirect
14+
github.com/go-ole/go-ole v1.2.6 // indirect
15+
github.com/ipfs/go-block-format v0.1.2 // indirect
16+
github.com/ipfs/go-cid v0.4.1 // indirect
17+
github.com/ipfs/go-ipfs-util v0.0.3 // indirect
18+
github.com/ipfs/go-ipld-cbor v0.0.6 // indirect
19+
github.com/ipfs/go-ipld-format v0.5.0 // indirect
20+
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
21+
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
22+
github.com/minio/sha256-simd v1.0.1 // indirect
23+
github.com/mr-tron/base58 v1.2.0 // indirect
24+
github.com/multiformats/go-base32 v0.1.0 // indirect
25+
github.com/multiformats/go-base36 v0.2.0 // indirect
26+
github.com/multiformats/go-multibase v0.2.0 // indirect
27+
github.com/multiformats/go-multihash v0.2.3 // indirect
28+
github.com/multiformats/go-varint v0.0.7 // indirect
29+
github.com/polydawn/refmt v0.89.0 // indirect
30+
github.com/spaolacci/murmur3 v1.1.0 // indirect
31+
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect
32+
golang.org/x/crypto v0.10.0 // indirect
33+
golang.org/x/sys v0.9.0 // indirect
34+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
35+
lukechampine.com/blake3 v1.2.1 // indirect
36+
)

0 commit comments

Comments
 (0)