Skip to content

Commit

Permalink
neofs-cli/control: add object revive control command
Browse files Browse the repository at this point in the history
Support command that revive object by purging all removal marks from all
metabases.

```
$ neofs-cli control object status --endpoint s04.neofs.devenv:8081 -w
services/storage/wallet04.json --object 4yYJV2AyHaJ3fpVimEihAj6NTkwmanbwE7YatJUWBPyM/CYUeRyjfiNXhBMW9XZmdSBJNVLXYBH3gSNQASWTGZX8t
Enter password >
Shard ID: 2wEzFvWsao9yBiDWKjSBfF
	metabase: AVAILABLE
	peapod: path: "/storage/peapod1.db"
$ neofs-cli object delete -r s04.neofs.devenv:8080 -w services/storage/wallet04
.json --cid 4yYJV2AyHaJ3fpVimEihAj6NTkwmanbwE7YatJUWBPyM --oid CYUeRyjfiNXhBMW9XZmdSBJNVLXYBH3gSNQASWTGZX8t
Enter password >
Object CYUeRyjfiNXhBMW9XZmdSBJNVLXYBH3gSNQASWTGZX8t removed successfully.
  ID: C2LrMExCF3FTfQaFYYZfoDGLpsUVLUy156pUpWh72YeN
  CID: 4yYJV2AyHaJ3fpVimEihAj6NTkwmanbwE7YatJUWBPyM
$ neofs-cli control object status --endpoint s04.neofs.devenv:8081 -w
services/storage/wallet04.json --object 4yYJV2AyHaJ3fpVimEihAj6NTkwmanbwE7YatJUWBPyM/CYUeRyjfiNXhBMW9XZmdSBJNVLXYBH3gSNQASWTGZX8t
Enter password >
Shard ID: 2wEzFvWsao9yBiDWKjSBfF
	metabase: AVAILABLE,IN GRAVEYARD
	peapod: path: "/storage/peapod1.db"
$ neofs-cli control object revive --endpoint s04.neofs.devenv:8081 -w
services/storage/wallet04.json --object 4yYJV2AyHaJ3fpVimEihAj6NTkwmanbwE7YatJUWBPyM/CYUeRyjfiNXhBMW9XZmdSBJNVLXYBH3gSNQASWTGZX8t
Enter password >
Shard ID: Vuy2Q8QaPZSuUxDycPxSBC
Revival status: don't revive, err: logical error: object neither in the graveyard nor was marked with GC mark
Shard ID: 2wEzFvWsao9yBiDWKjSBfF
Revival status: successful revival from graveyard, tomb: 4yYJV2AyHaJ3fpVimEihAj6NTkwmanbwE7YatJUWBPyM/C2LrMExCF3FTfQaFYYZfoDGLpsUVLUy156pUpWh72YeN
$ neofs-cli control object status --endpoint s04.neofs.devenv:8081 -w
services/storage/wallet04.json --object 4yYJV2AyHaJ3fpVimEihAj6NTkwmanbwE7YatJUWBPyM/CYUeRyjfiNXhBMW9XZmdSBJNVLXYBH3gSNQASWTGZX8t
Enter password >
Shard ID: 2wEzFvWsao9yBiDWKjSBfF
	metabase: AVAILABLE
	peapod: path: "/storage/peapod1.db"
```

Closes #1450.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Oct 23, 2024
1 parent 1c78683 commit 4ded500
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ attribute, which is used for container domain name in NNS contracts (#2954)
- Save last epoch when metabase was resynchronized (#2966)
- `neofs-lens meta last-resync-epoch` command (#2966)
- `neofs-lens fstree cleanup-tmp` command (#2967)
- `neofs-cli control object revive` command (#2968)

### Fixed
- Do not search for tombstones when handling their expiration, use local indexes instead (#2929)
Expand Down
4 changes: 4 additions & 0 deletions cmd/neofs-cli/modules/control/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/spf13/cobra"
)

const objectFlag = "object"

var objectCmd = &cobra.Command{
Use: "object",
Short: "Direct object operations with storage engine",
Expand All @@ -12,7 +14,9 @@ var objectCmd = &cobra.Command{
func initControlObjectsCmd() {
objectCmd.AddCommand(listObjectsCmd)
objectCmd.AddCommand(objectStatusCmd)
objectCmd.AddCommand(reviveObjectCmd)

Check warning on line 17 in cmd/neofs-cli/modules/control/object.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object.go#L17

Added line #L17 was not covered by tests

initControlObjectReviveCmd()

Check warning on line 19 in cmd/neofs-cli/modules/control/object.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object.go#L19

Added line #L19 was not covered by tests
initControlObjectsListCmd()
initObjectStatusFlags()
}
89 changes: 89 additions & 0 deletions cmd/neofs-cli/modules/control/object_revive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package control

import (
"fmt"

rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/spf13/cobra"
)

var reviveObjectCmd = &cobra.Command{
Use: "revive",
Short: "Forcefully revive object",
Long: "Purge removal marks from metabases",
Args: cobra.NoArgs,
RunE: reviveObject,
}

func initControlObjectReviveCmd() {
initControlFlags(reviveObjectCmd)

flags := reviveObjectCmd.Flags()
flags.String(objectFlag, "", "Object address")

Check warning on line 26 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L22-L26

Added lines #L22 - L26 were not covered by tests
}

func reviveObject(cmd *cobra.Command, _ []string) error {
ctx, cancel := commonflags.GetCommandContext(cmd)
defer cancel()

pk, err := key.Get(cmd)
if err != nil {
return err
}
addressRaw, err := cmd.Flags().GetString(objectFlag)
if err != nil {
return fmt.Errorf("reading %s flag: %w", objectFlag, err)
}

Check warning on line 40 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L29-L40

Added lines #L29 - L40 were not covered by tests

var sdkAddr oid.Address
err = sdkAddr.DecodeString(addressRaw)
if err != nil {
return fmt.Errorf("validating address (%s): %w", addressRaw, err)
}

Check warning on line 46 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L42-L46

Added lines #L42 - L46 were not covered by tests

var resp *control.ReviveObjectResponse
req := &control.ReviveObjectRequest{
Body: &control.ReviveObjectRequest_Body{
ObjectAddress: addressRaw,
},
}
err = signRequest(pk, req)
if err != nil {
return err
}

Check warning on line 57 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L48-L57

Added lines #L48 - L57 were not covered by tests

cli, err := getClient(ctx)
if err != nil {
return err
}

Check warning on line 62 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L59-L62

Added lines #L59 - L62 were not covered by tests

err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.ReviveObject(client, req)
return err
})
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}

Check warning on line 70 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L64-L70

Added lines #L64 - L70 were not covered by tests

err = verifyResponse(resp.GetSignature(), resp.GetBody())
if err != nil {
return err
}

Check warning on line 75 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L72-L75

Added lines #L72 - L75 were not covered by tests

shards := resp.GetBody().GetShards()
if len(shards) == 0 {
cmd.Println("<empty response>")
return nil
}

Check warning on line 81 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L77-L81

Added lines #L77 - L81 were not covered by tests

for _, shard := range shards {
cmd.Printf("Shard ID: %s\n", shard.ShardId)
cmd.Printf("Revival status: %s\n", shard.Status)
}

Check warning on line 86 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L83-L86

Added lines #L83 - L86 were not covered by tests

return nil

Check warning on line 88 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L88

Added line #L88 was not covered by tests
}
2 changes: 0 additions & 2 deletions cmd/neofs-cli/modules/control/object_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/spf13/cobra"
)

const objectFlag = "object"

var objectStatusCmd = &cobra.Command{
Use: "status",
Short: "Check current object status",
Expand Down

0 comments on commit 4ded500

Please sign in to comment.