2022-05-16 16:43:29 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
"errors"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
|
|
|
controlSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2022-05-16 16:43:29 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
synchronizeTreeIDFlag = "tree-id"
|
|
|
|
synchronizeTreeHeightFlag = "height"
|
|
|
|
)
|
|
|
|
|
|
|
|
var synchronizeTreeCmd = &cobra.Command{
|
|
|
|
Use: "synchronize-tree",
|
|
|
|
Short: "Synchronize log for the tree",
|
|
|
|
Long: "Synchronize log for the tree in an object tree service.",
|
|
|
|
Run: synchronizeTree,
|
|
|
|
}
|
|
|
|
|
|
|
|
func initControlSynchronizeTreeCmd() {
|
2022-10-17 15:37:15 +00:00
|
|
|
initControlFlags(synchronizeTreeCmd)
|
2022-05-16 16:43:29 +00:00
|
|
|
|
|
|
|
flags := synchronizeTreeCmd.Flags()
|
2022-10-18 11:43:04 +00:00
|
|
|
flags.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
2022-05-16 16:43:29 +00:00
|
|
|
flags.String(synchronizeTreeIDFlag, "", "Tree ID")
|
|
|
|
flags.Uint64(synchronizeTreeHeightFlag, 0, "Starting height")
|
|
|
|
}
|
|
|
|
|
|
|
|
func synchronizeTree(cmd *cobra.Command, _ []string) {
|
|
|
|
pk := key.Get(cmd)
|
|
|
|
|
|
|
|
var cnr cid.ID
|
2022-10-18 11:43:04 +00:00
|
|
|
cidStr, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't decode container ID: %w", cnr.DecodeString(cidStr))
|
2022-05-16 16:43:29 +00:00
|
|
|
|
|
|
|
treeID, _ := cmd.Flags().GetString("tree-id")
|
|
|
|
if treeID == "" {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", errors.New("tree ID must not be empty"))
|
2022-05-16 16:43:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
height, _ := cmd.Flags().GetUint64("height")
|
|
|
|
|
|
|
|
rawCID := make([]byte, sha256.Size)
|
|
|
|
cnr.Encode(rawCID)
|
|
|
|
|
|
|
|
req := &control.SynchronizeTreeRequest{
|
|
|
|
Body: &control.SynchronizeTreeRequest_Body{
|
|
|
|
ContainerId: rawCID,
|
|
|
|
TreeId: treeID,
|
|
|
|
Height: height,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := controlSvc.SignMessage(pk, req)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "could not sign request: %w", err)
|
2022-05-16 16:43:29 +00:00
|
|
|
|
|
|
|
cli := getClient(cmd, pk)
|
|
|
|
|
|
|
|
var resp *control.SynchronizeTreeResponse
|
|
|
|
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
resp, err = control.SynchronizeTree(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-05-16 16:43:29 +00:00
|
|
|
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
|
|
|
|
|
|
|
cmd.Println("Tree has been synchronized successfully.")
|
|
|
|
}
|