Merge pull request #3741 from filecoin-project/feat/chain-delete-obj
Delete a chain store object
This commit is contained in:
commit
7d39542522
@ -76,6 +76,9 @@ type FullNode interface {
|
|||||||
// blockstore and returns raw bytes.
|
// blockstore and returns raw bytes.
|
||||||
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
||||||
|
|
||||||
|
// ChainDeleteObj deletes node referenced by the given CID
|
||||||
|
ChainDeleteObj(context.Context, cid.Cid) error
|
||||||
|
|
||||||
// ChainHasObj checks if a given CID exists in the chain blockstore.
|
// ChainHasObj checks if a given CID exists in the chain blockstore.
|
||||||
ChainHasObj(context.Context, cid.Cid) (bool, error)
|
ChainHasObj(context.Context, cid.Cid) (bool, error)
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ type FullNodeStruct struct {
|
|||||||
ChainGetParentMessages func(context.Context, cid.Cid) ([]api.Message, error) `perm:"read"`
|
ChainGetParentMessages func(context.Context, cid.Cid) ([]api.Message, error) `perm:"read"`
|
||||||
ChainGetTipSetByHeight func(context.Context, abi.ChainEpoch, types.TipSetKey) (*types.TipSet, error) `perm:"read"`
|
ChainGetTipSetByHeight func(context.Context, abi.ChainEpoch, types.TipSetKey) (*types.TipSet, error) `perm:"read"`
|
||||||
ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"`
|
ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"`
|
||||||
|
ChainDeleteObj func(context.Context, cid.Cid) error `perm:"admin"`
|
||||||
ChainHasObj func(context.Context, cid.Cid) (bool, error) `perm:"read"`
|
ChainHasObj func(context.Context, cid.Cid) (bool, error) `perm:"read"`
|
||||||
ChainStatObj func(context.Context, cid.Cid, cid.Cid) (api.ObjStat, error) `perm:"read"`
|
ChainStatObj func(context.Context, cid.Cid, cid.Cid) (api.ObjStat, error) `perm:"read"`
|
||||||
ChainSetHead func(context.Context, types.TipSetKey) error `perm:"admin"`
|
ChainSetHead func(context.Context, types.TipSetKey) error `perm:"admin"`
|
||||||
@ -662,6 +663,10 @@ func (c *FullNodeStruct) ChainReadObj(ctx context.Context, obj cid.Cid) ([]byte,
|
|||||||
return c.Internal.ChainReadObj(ctx, obj)
|
return c.Internal.ChainReadObj(ctx, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) ChainDeleteObj(ctx context.Context, obj cid.Cid) error {
|
||||||
|
return c.Internal.ChainDeleteObj(ctx, obj)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) ChainHasObj(ctx context.Context, o cid.Cid) (bool, error) {
|
func (c *FullNodeStruct) ChainHasObj(ctx context.Context, o cid.Cid) (bool, error) {
|
||||||
return c.Internal.ChainHasObj(ctx, o)
|
return c.Internal.ChainHasObj(ctx, o)
|
||||||
}
|
}
|
||||||
|
38
cli/chain.go
38
cli/chain.go
@ -40,6 +40,7 @@ var chainCmd = &cli.Command{
|
|||||||
chainHeadCmd,
|
chainHeadCmd,
|
||||||
chainGetBlock,
|
chainGetBlock,
|
||||||
chainReadObjCmd,
|
chainReadObjCmd,
|
||||||
|
chainDeleteObjCmd,
|
||||||
chainStatObjCmd,
|
chainStatObjCmd,
|
||||||
chainGetMsgCmd,
|
chainGetMsgCmd,
|
||||||
chainSetHeadCmd,
|
chainSetHeadCmd,
|
||||||
@ -193,6 +194,43 @@ var chainReadObjCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var chainDeleteObjCmd = &cli.Command{
|
||||||
|
Name: "delete-obj",
|
||||||
|
Usage: "Delete an object from the chain blockstore",
|
||||||
|
Description: "WARNING: Removing wrong objects from the chain blockstore may lead to sync issues",
|
||||||
|
ArgsUsage: "[objectCid]",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "really-do-it",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
c, err := cid.Decode(cctx.Args().First())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse cid input: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !cctx.Bool("really-do-it") {
|
||||||
|
return xerrors.Errorf("pass the --really-do-it flag to proceed")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = api.ChainDeleteObj(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Obj %s deleted\n", c.String())
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var chainStatObjCmd = &cli.Command{
|
var chainStatObjCmd = &cli.Command{
|
||||||
Name: "stat-obj",
|
Name: "stat-obj",
|
||||||
Usage: "Collect size and ipld link counts for objs",
|
Usage: "Collect size and ipld link counts for objs",
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
* [Beacon](#Beacon)
|
* [Beacon](#Beacon)
|
||||||
* [BeaconGetEntry](#BeaconGetEntry)
|
* [BeaconGetEntry](#BeaconGetEntry)
|
||||||
* [Chain](#Chain)
|
* [Chain](#Chain)
|
||||||
|
* [ChainDeleteObj](#ChainDeleteObj)
|
||||||
* [ChainExport](#ChainExport)
|
* [ChainExport](#ChainExport)
|
||||||
* [ChainGetBlock](#ChainGetBlock)
|
* [ChainGetBlock](#ChainGetBlock)
|
||||||
* [ChainGetBlockMessages](#ChainGetBlockMessages)
|
* [ChainGetBlockMessages](#ChainGetBlockMessages)
|
||||||
@ -281,6 +282,23 @@ The Chain method group contains methods for interacting with the
|
|||||||
blockchain, but that do not require any form of state computation.
|
blockchain, but that do not require any form of state computation.
|
||||||
|
|
||||||
|
|
||||||
|
### ChainDeleteObj
|
||||||
|
ChainDeleteObj deletes node referenced by the given CID
|
||||||
|
|
||||||
|
|
||||||
|
Perms: admin
|
||||||
|
|
||||||
|
Inputs:
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Response: `{}`
|
||||||
|
|
||||||
### ChainExport
|
### ChainExport
|
||||||
ChainExport returns a stream of bytes with CAR dump of chain data.
|
ChainExport returns a stream of bytes with CAR dump of chain data.
|
||||||
The exported chain data includes the header chain from the given tipset
|
The exported chain data includes the header chain from the given tipset
|
||||||
|
@ -197,6 +197,10 @@ func (a *ChainAPI) ChainReadObj(ctx context.Context, obj cid.Cid) ([]byte, error
|
|||||||
return blk.RawData(), nil
|
return blk.RawData(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *ChainAPI) ChainDeleteObj(ctx context.Context, obj cid.Cid) error {
|
||||||
|
return a.Chain.Blockstore().DeleteBlock(obj)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *ChainAPI) ChainHasObj(ctx context.Context, obj cid.Cid) (bool, error) {
|
func (a *ChainAPI) ChainHasObj(ctx context.Context, obj cid.Cid) (bool, error) {
|
||||||
return a.Chain.Blockstore().Has(obj)
|
return a.Chain.Blockstore().Has(obj)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user