From 4fb87e062bd0229785a78cdb7e34b6d65a91f799 Mon Sep 17 00:00:00 2001 From: Sydonian <794346190@qq.com> Date: Mon, 14 Aug 2023 09:37:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E5=A2=9E=E5=8A=A0TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/config/config.go | 2 +- internal/services/cmd/storage.go | 28 ++++++------- internal/task/ec_read.go | 70 ++++++++++++-------------------- main.go | 2 - 4 files changed, 41 insertions(+), 61 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 1c59be2..47a9a1e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -12,7 +12,7 @@ type Config struct { ID int64 `json:"id"` GRPCListenAddress string `json:"grpcListenAddress"` GRPCPort int `json:"grpcPort"` - GRPCPacketSize int64 `json:"grpcPacketSize"` + ECPacketSize int64 `json:"ecPacketSize"` LocalIP string `json:"localIP"` ExternalIP string `json:"externalIP"` StorageBaseDir string `json:"storageBaseDir"` diff --git a/internal/services/cmd/storage.go b/internal/services/cmd/storage.go index fab4c6b..608b692 100644 --- a/internal/services/cmd/storage.go +++ b/internal/services/cmd/storage.go @@ -37,19 +37,17 @@ func (service *Service) StartStorageMoveObject(msg *agtmsg.StartStorageMoveObjec return ramsg.ReplyOK(agtmsg.NewStartStorageMoveObjectResp(taskID)) - } else { - // TODO 处理其他备份类型 - if repRed, ok := msg.Redundancy.(models.ECRedundancyData); ok { - taskID, err := service.moveEcObject(msg.FileSize, repRed, outFilePath) - if err != nil { - logger.Warnf("move ec object as %s failed, err: %s", outFilePath, err.Error()) - return ramsg.ReplyFailed[agtmsg.StartStorageMoveObjectResp](errorcode.OperationFailed, "move ec object failed") - } - - return ramsg.ReplyOK(agtmsg.NewStartStorageMoveObjectResp(taskID)) + } else if repRed, ok := msg.Redundancy.(models.ECRedundancyData); ok { + taskID, err := service.moveEcObject(msg.ObjectID, msg.FileSize, repRed, outFilePath) + if err != nil { + logger.Warnf("move ec object as %s failed, err: %s", outFilePath, err.Error()) + return ramsg.ReplyFailed[agtmsg.StartStorageMoveObjectResp](errorcode.OperationFailed, "move ec object failed") } - return ramsg.ReplyFailed[agtmsg.StartStorageMoveObjectResp](errorcode.OperationFailed, "not rep or ec object???") + + return ramsg.ReplyOK(agtmsg.NewStartStorageMoveObjectResp(taskID)) } + + return ramsg.ReplyFailed[agtmsg.StartStorageMoveObjectResp](errorcode.OperationFailed, "not rep or ec object???") } func (svc *Service) moveRepObject(repData models.RepRedundancyData, outFilePath string) (string, error) { @@ -57,15 +55,15 @@ func (svc *Service) moveRepObject(repData models.RepRedundancyData, outFilePath return tsk.ID(), nil } -func (svc *Service) moveEcObject(fileSize int64, ecData models.ECRedundancyData, outFilePath string) (string, error) { +func (svc *Service) moveEcObject(objID int64, fileSize int64, ecData models.ECRedundancyData, outFilePath string) (string, error) { ecK := ecData.Ec.EcK blockIDs := make([]int, ecK) hashs := make([]string, ecK) - for i:=0 ; i