Skip to content

Commit

Permalink
feat: DagstoreDestroyShard API and CLI (#681)
Browse files Browse the repository at this point in the history
* DagstoreDestroyShard

* update dagstore

* mod tidy

* dagstore v0.5.3
  • Loading branch information
LexLuthr authored Aug 10, 2022
1 parent c8f9868 commit 97643cb
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 5 deletions.
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Boost interface {
BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*smtypes.ProviderDealState, error) //perm:admin
BoostDummyDeal(context.Context, smtypes.DealParams) (*ProviderDealRejectionInfo, error) //perm:admin
BoostDagstoreRegisterShard(ctx context.Context, key string) error //perm:admin
BoostDagstoreDestroyShard(ctx context.Context, key string) error //perm:admin
BoostDagstoreInitializeShard(ctx context.Context, key string) error //perm:admin
BoostDagstoreInitializeAll(ctx context.Context, params DagstoreInitializeAllParams) (<-chan DagstoreInitializeAllEvent, error) //perm:admin
BoostDagstoreRecoverShard(ctx context.Context, key string) error //perm:admin
Expand Down
13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/boost.json.gz
Binary file not shown.
40 changes: 40 additions & 0 deletions cmd/boostd/dagstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var dagstoreCmd = &cli.Command{
dagstoreInitializeAllCmd,
dagstoreListShardsCmd,
dagstoreGcCmd,
dagstoreDestroyShardCmd,
},
}

Expand Down Expand Up @@ -269,3 +270,42 @@ var dagstoreRecoverShardCmd = &cli.Command{
return napi.BoostDagstoreRecoverShard(ctx, cctx.Args().First())
},
}

var dagstoreDestroyShardCmd = &cli.Command{
Name: "destroy-shard",
ArgsUsage: "[key]",
Usage: "Destroy a shard",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "color",
Usage: "use color in display output",
DefaultText: "depends on output being a TTY",
},
},
Action: func(cctx *cli.Context) error {
if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}

if cctx.NArg() != 1 {
return fmt.Errorf("must provide a single shard key")
}

napi, closer, err := bcli.GetBoostAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := lcli.ReqContext(cctx)

shardKey := cctx.Args().First()
err = napi.BoostDagstoreDestroyShard(ctx, shardKey)
if err != nil {
return err
}

fmt.Println("Destroyed shard " + shardKey)
return nil
},
}
15 changes: 15 additions & 0 deletions documentation/en/api-v1-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [AuthNew](#authnew)
* [AuthVerify](#authverify)
* [Boost](#boost)
* [BoostDagstoreDestroyShard](#boostdagstoredestroyshard)
* [BoostDagstoreGC](#boostdagstoregc)
* [BoostDagstoreInitializeAll](#boostdagstoreinitializeall)
* [BoostDagstoreInitializeShard](#boostdagstoreinitializeshard)
Expand Down Expand Up @@ -139,6 +140,20 @@ Response:
## Boost


### BoostDagstoreDestroyShard


Perms: admin

Inputs:
```json
[
"string value"
]
```

Response: `{}`

### BoostDagstoreGC


Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/etclabscore/go-openrpc-reflect v0.0.36
github.com/fatih/color v1.13.0
github.com/filecoin-project/dagstore v0.5.2
github.com/filecoin-project/dagstore v0.5.3
github.com/filecoin-project/go-address v1.0.0
github.com/filecoin-project/go-bitfield v0.2.4
github.com/filecoin-project/go-cbor-util v0.0.1
github.com/filecoin-project/go-commp-utils v0.1.3
github.com/filecoin-project/go-data-transfer v1.15.2
github.com/filecoin-project/go-fil-commcid v0.1.0
github.com/filecoin-project/go-fil-commp-hashhash v0.1.0
github.com/filecoin-project/go-fil-markets v1.23.1
github.com/filecoin-project/go-fil-markets v1.23.2
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/filecoin-project/dagstore v0.5.2 h1:Nd6oXdnolbbVhpMpkYT5PJHOjQp4OBSntHpMV5pxj3c=
github.com/filecoin-project/dagstore v0.5.2/go.mod h1:mdqKzYrRBHf1pRMthYfMv3n37oOw0Tkx7+TxPt240M0=
github.com/filecoin-project/dagstore v0.5.3 h1:++s4pEW/NvHph0N8sCdz7NokU0Y3r2yVB5SFaDTLLWM=
github.com/filecoin-project/dagstore v0.5.3/go.mod h1:mdqKzYrRBHf1pRMthYfMv3n37oOw0Tkx7+TxPt240M0=
github.com/filecoin-project/go-address v0.0.3/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+cGQ59wMIps/8YW/lDj8=
github.com/filecoin-project/go-address v0.0.5/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+cGQ59wMIps/8YW/lDj8=
github.com/filecoin-project/go-address v0.0.6/go.mod h1:7B0/5DA13n6nHkB8bbGx1gWzG/dbTsZ0fgOJVGsM3TE=
Expand Down Expand Up @@ -384,8 +385,9 @@ github.com/filecoin-project/go-fil-commcid v0.1.0 h1:3R4ds1A9r6cr8mvZBfMYxTS88Oq
github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commp-hashhash v0.1.0 h1:imrrpZWEHRnNqqv0tN7LXep5bFEVOVmQWHJvl2mgsGo=
github.com/filecoin-project/go-fil-commp-hashhash v0.1.0/go.mod h1:73S8WSEWh9vr0fDJVnKADhfIv/d6dCbAGaAGWbdJEI8=
github.com/filecoin-project/go-fil-markets v1.23.1 h1:F2jr4qldYrpbLgdtKe5LqUHXv2eRxeuWTMr+nX4gASc=
github.com/filecoin-project/go-fil-markets v1.23.1/go.mod h1:V+1vFO34RZmpdECdikKGiyWhSNJK81Q89Kn0egA9iAk=
github.com/filecoin-project/go-fil-markets v1.23.2 h1:9+5CCliLVoTbq3qffT2xZMuGjyl2HyR0RJ7x29ywRi8=
github.com/filecoin-project/go-fil-markets v1.23.2/go.mod h1:V+1vFO34RZmpdECdikKGiyWhSNJK81Q89Kn0egA9iAk=
github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM=
github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24=
github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 h1:b3UDemBYN2HNfk3KOXNuxgTTxlWi3xVvbQP0IT38fvM=
Expand Down
29 changes: 28 additions & 1 deletion node/impl/boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/multiformats/go-multihash"
"net/http"
"sort"

"github.com/multiformats/go-multihash"

"github.com/filecoin-project/go-fil-markets/stores"

"github.com/filecoin-project/boost/api"
Expand Down Expand Up @@ -446,3 +447,29 @@ func (sm *BoostAPI) BoostDagstoreRecoverShard(ctx context.Context, key string) e

return res.Error
}

func (sm *BoostAPI) BoostDagstoreDestroyShard(ctx context.Context, key string) error {
if sm.DAGStore == nil {
return fmt.Errorf("dagstore not available on this node")
}

// First check if the shard has already been registered
k := shard.KeyFromString(key)
_, err := sm.DAGStore.GetShardInfo(k)
if err != nil {
return fmt.Errorf("unable to query dagstore for shard info: %w", err)
}
// If the shard is not registered we would expect ErrShardUnknown
if !errors.Is(err, dagstore.ErrShardUnknown) {
return fmt.Errorf("shard not found in the dagstore: %w", err)
}

pieceCid, err := cid.Parse(key)
if err != nil {
return fmt.Errorf("parsing shard key as piece cid: %w", err)
}
if err = stores.DestroyShardSync(ctx, sm.DagStoreWrapper, pieceCid); err != nil {
return fmt.Errorf("failed to destroy shard: %w", err)
}
return nil
}

0 comments on commit 97643cb

Please sign in to comment.