Skip to content

Commit

Permalink
Merge pull request #1021 from ipfs-force-community/cherry-pick-pr-101…
Browse files Browse the repository at this point in the history
…9-to-release-v0.9

Cherry pick #1019 to release v0.9
  • Loading branch information
0x5459 authored Nov 10, 2023
2 parents 7695d46 + e7c2a5a commit 38b54b1
Show file tree
Hide file tree
Showing 26 changed files with 595 additions and 358 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.zh.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## 0.10.0-dev
## v0.9.0-rc6
- damocles-manager
- 简化扇区存储配置 [#1010](https://github.com/ipfs-force-community/damocles/pull/1010)

## v0.9.0-rc5
- damocles-manager
Expand Down
71 changes: 70 additions & 1 deletion damocles-manager/cmd/damocles-manager/internal/util_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"os"
Expand All @@ -17,27 +18,95 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/venus/venus-shared/types"
"github.com/google/uuid"
"github.com/ipfs-force-community/damocles/damocles-manager/core"
"github.com/ipfs-force-community/damocles/damocles-manager/dep"
"github.com/ipfs-force-community/damocles/damocles-manager/modules"
"github.com/ipfs-force-community/damocles/damocles-manager/modules/util"
"github.com/ipfs-force-community/damocles/damocles-manager/pkg/chain"
"github.com/ipfs-force-community/damocles/damocles-manager/pkg/logging"
"github.com/ipfs-force-community/damocles/damocles-manager/pkg/objstore"
"github.com/ipfs-force-community/damocles/damocles-manager/pkg/objstore/filestore"
"github.com/ipfs-force-community/damocles/damocles-manager/pkg/slices"
"github.com/urfave/cli/v2"
)

var utilStorageCmd = &cli.Command{
Name: "storage",
Usage: "Manage persistent storage for sealed sectors",
Subcommands: []*cli.Command{
utilStorageGenSectorStoreJSONCmd,
utilStorageAttachCmd,
utilStorageFindCmd,
utilStorageListCmd,
utilStorageReleaseReservedCmd,
},
}

var utilStorageGenSectorStoreJSONCmd = &cli.Command{
Name: "gen-sectorstore-json",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "strict",
Value: true,
},
&cli.BoolFlag{
Name: "readonly",
Aliases: []string{"read-only"},
Value: false,
},
&cli.UintFlag{
Name: "weight",
Value: 1,
},
&cli.StringFlag{
Name: "plugin-name",
Aliases: []string{"plugin"},
},
&cli.Uint64SliceFlag{
Name: "allow-miners",
},
&cli.Uint64SliceFlag{
Name: "deny-miners",
},
},
Usage: "generate the `sectorstore.json` file",
ArgsUsage: "[sectorstore.json path]",
Action: func(cctx *cli.Context) error {
cfg := modules.SectorStoreJSON{
ID: uuid.New().String(),
PersistStoreConfig: modules.PersistStoreConfig{
Config: objstore.Config{
Strict: cctx.Bool("strict"),
ReadOnly: cctx.Bool("readonly"),
Weight: cctx.Uint("weight"),
},
StoreSelectPolicy: objstore.StoreSelectPolicy{
AllowMiners: slices.Map(cctx.Uint64Slice("allow-miners"), func(x uint64) abi.ActorID { return abi.ActorID(x) }),
DenyMiners: slices.Map(cctx.Uint64Slice("deny-miners"), func(x uint64) abi.ActorID { return abi.ActorID(x) }),
},
PluginName: cctx.String("plugin-name"),
},
}

b, err := json.MarshalIndent(cfg, "", "\t")
if err != nil {
return fmt.Errorf("failed to marshal config: %w", err)
}

targetPath := cctx.Args().First()
if targetPath == "" {
fmt.Println(string(b))
return nil
}

if filepath.Base(targetPath) != modules.FilenameSectorStoreJSON {
targetPath = filepath.Join(targetPath, modules.FilenameSectorStoreJSON)
}
return os.WriteFile(targetPath, b, 0644)
},
}

var utilStorageAttachCmd = &cli.Command{
Name: "attach",
Usage: "Attach local storage path and import sectors in this path",
Expand Down Expand Up @@ -88,7 +157,7 @@ var utilStorageAttachCmd = &cli.Command{

scfg := objstore.DefaultConfig(abs, readOnly)
scfg.Name = name
scfg.Strict = &strict
scfg.Strict = strict

store, err := filestore.Open(scfg, false)
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions damocles-manager/dep/sealer_constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,20 @@ func openObjStore(cfg objstore.Config, pluginName string, loadedPlugins *manager
}

func BuildPersistedFileStoreMgr(scfg *modules.SafeConfig, globalStore CommonMetaStore, loadedPlugins *managerplugin.LoadedPlugins) (PersistedObjectStoreManager, error) {
persistCfg := scfg.MustCommonConfig().GetPersistStores()
persistCfg, err := scfg.MustCommonConfig().GetPersistStores()
if err != nil {
return nil, fmt.Errorf("get persist store config: %w", err)
}

stores := make([]objstore.Store, 0, len(persistCfg))
policy := map[string]objstore.StoreSelectPolicy{}
checkName := make(map[string]struct{})
for pi := range persistCfg {
if _, ok := checkName[persistCfg[pi].Name]; ok {
return nil, fmt.Errorf("duplicate persist store name %s", persistCfg[pi].Name)
}
checkName[persistCfg[pi].Name] = struct{}{}

// For compatibility with v0.5
if persistCfg[pi].PluginName == "" && persistCfg[pi].Plugin != "" {
persistCfg[pi].PluginName = persistCfg[pi].Plugin
Expand Down Expand Up @@ -575,7 +584,7 @@ func BuildMarketAPIRelated(gctx GlobalContext, lc fx.Lifecycle, scfg *modules.Sa
Name: pcfg.Name,
Path: pcfg.Path,
Meta: pcfg.Meta,
ReadOnly: &pcfg.ReadOnly,
ReadOnly: pcfg.ReadOnly,
}
// For compatibility with v0.5
if pcfg.PluginName == "" && pcfg.Plugin != "" {
Expand Down
4 changes: 2 additions & 2 deletions damocles-manager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ require (
github.com/filecoin-project/specs-storage v0.4.1
github.com/filecoin-project/venus v1.14.0-rc4
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026
github.com/hashicorp/go-multierror v1.1.1
github.com/ipfs-force-community/damocles/manager-plugin v0.0.0-20230830062024-608c68ada10e
github.com/ipfs-force-community/damocles/manager-plugin v0.0.0-20231108073455-ac8eebc7d237
github.com/ipfs-force-community/venus-cluster-assets v0.1.0
github.com/ipfs/boxo v0.10.1
github.com/ipfs/go-cid v0.4.1
Expand Down Expand Up @@ -114,7 +115,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hannahhoward/cbor-gen-for v0.0.0-20230214144701-5d17c9d5243c // indirect
Expand Down
4 changes: 2 additions & 2 deletions damocles-manager/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lTo
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/ipfs-force-community/damocles/manager-plugin v0.0.0-20230830062024-608c68ada10e h1:SEmUD7xCpHWlnTrZdyj++RExTy0T6bqX4yS/iXBHVAg=
github.com/ipfs-force-community/damocles/manager-plugin v0.0.0-20230830062024-608c68ada10e/go.mod h1:me1u2cl7qdxBCZiVL0laDop8uBHDdUwlUNnQ7KkHF64=
github.com/ipfs-force-community/damocles/manager-plugin v0.0.0-20231108073455-ac8eebc7d237 h1:yNvF1C/Qgt9p38wQfhJQ7PRnbwEBs8vSpNFxnWDlhu8=
github.com/ipfs-force-community/damocles/manager-plugin v0.0.0-20231108073455-ac8eebc7d237/go.mod h1:EpGeK7b251iv7L5TnHl1PJGFH4KbliE03ctYt5thy6c=
github.com/ipfs-force-community/go-jsonrpc v0.1.8 h1:w7CWlLveL+aXD3gLg8Z7I1RcktCiMY0sp8dgJG37uWE=
github.com/ipfs-force-community/go-jsonrpc v0.1.8/go.mod h1:jBSvPTl8V1N7gSTuCR4bis8wnQnIjHbRPpROol6iQKM=
github.com/ipfs-force-community/venus-cluster-assets v0.1.0 h1:K/0+OV9Jm7HjSa7O9MAtgfLDIudQYZUTymhJsp8rGXg=
Expand Down
Loading

0 comments on commit 38b54b1

Please sign in to comment.