Browse Source

Move命令使用ID进行操作;去掉各种命令中不需要的参数

gitlink
Sydonian 2 years ago
parent
commit
d6e7d33689
3 changed files with 24 additions and 20 deletions
  1. +6
    -6
      client_command.go
  2. +1
    -1
      client_command_ec.go
  3. +17
    -13
      main.go

+ 6
- 6
client_command.go View File

@@ -22,7 +22,7 @@ import (
"google.golang.org/grpc/credentials/insecure"
)

func Read(localFilePath string, bucketID int, objectID int) error {
func Read(localFilePath string, objectID int) error {
// TODO 此处是写死的常量
userId := 0

@@ -33,7 +33,7 @@ func Read(localFilePath string, bucketID int, objectID int) error {
}
defer coorClient.Close()

readResp, err := coorClient.Read(bucketID, objectID, userId)
readResp, err := coorClient.Read(objectID, userId)
if err != nil {
return fmt.Errorf("request to coordinator failed, err: %w", err)
}
@@ -340,7 +340,7 @@ func sendFinish(numRep int, senders []fileSender) {
}
}

func Move(bucketName string, objectName string, stgID int) error {
func Move(objectID int, stgID int) error {
// TODO 此处是写死的常量
userId := 0

@@ -351,7 +351,7 @@ func Move(bucketName string, objectName string, stgID int) error {
}
defer coorClient.Close()

moveResp, err := coorClient.Move(bucketName, objectName, userId, stgID)
moveResp, err := coorClient.Move(objectID, stgID, userId)
if err != nil {
return fmt.Errorf("request to coordinator failed, err: %w", err)
}
@@ -368,7 +368,7 @@ func Move(bucketName string, objectName string, stgID int) error {

switch moveResp.Redundancy {
case consts.REDUNDANCY_REP:
agentMoveResp, err := agentClient.RepMove(moveResp.Directory, moveResp.Hashes, bucketName, objectName, userId, moveResp.FileSizeInBytes)
agentMoveResp, err := agentClient.RepMove(moveResp.Directory, moveResp.Hashes, objectID, userId, moveResp.FileSizeInBytes)
if err != nil {
return fmt.Errorf("request to agent %d failed, err: %w", stgID, err)
}
@@ -377,7 +377,7 @@ func Move(bucketName string, objectName string, stgID int) error {
}

case consts.REDUNDANCY_EC:
agentMoveResp, err := agentClient.ECMove(moveResp.Directory, moveResp.Hashes, moveResp.IDs, *moveResp.ECName, bucketName, objectName, userId, moveResp.FileSizeInBytes)
agentMoveResp, err := agentClient.ECMove(moveResp.Directory, moveResp.Hashes, moveResp.IDs, *moveResp.ECName, objectID, userId, moveResp.FileSizeInBytes)
if err != nil {
return fmt.Errorf("request to agent %d failed, err: %w", stgID, err)
}


+ 1
- 1
client_command_ec.go View File

@@ -12,7 +12,7 @@ import (
"gitlink.org.cn/cloudream/utils"
)

func EcWrite(localFilePath string, bucketName string, objectName string, ecName string) error {
func EcWrite(localFilePath string, bucketID int, objectName string, ecName string) error {
panic("not implement yet!")
/*
fmt.Println("write " + localFilePath + " as " + bucketName + "/" + objectName)


+ 17
- 13
main.go View File

@@ -21,18 +21,13 @@ func main() {
args := os.Args
switch args[1] {
case "read":
bucketID, err := strconv.Atoi(args[3])
objectID, err := strconv.Atoi(args[3])
if err != nil {
fmt.Printf("invalid bucket id %s, err: %s", args[3], err.Error())
os.Exit(1)
}
objectID, err := strconv.Atoi(args[4])
if err != nil {
fmt.Printf("invalid object id %s, err: %s", args[4], err.Error())
fmt.Printf("invalid object id %s, err: %s", args[3], err.Error())
os.Exit(1)
}

if err := Read(args[2], bucketID, objectID); err != nil {
if err := Read(args[2], objectID); err != nil {
fmt.Printf("read failed, err: %s", err.Error())
os.Exit(1)
}
@@ -54,20 +49,29 @@ func main() {
os.Exit(1)
}
case "ecWrite":
//TODO: 写入对象时,Coor判断对象是否已存在,如果存在,则直接返回
if err := EcWrite(args[2], args[3], args[4], args[5]); err != nil {
bucketID, err := strconv.Atoi(args[3])
if err != nil {
fmt.Printf("invalid bucket id %s, err: %s", args[3], err.Error())
os.Exit(1)
}
if err := EcWrite(args[2], bucketID, args[4], args[5]); err != nil {
fmt.Printf("ec write failed, err: %s", err.Error())
os.Exit(1)
}

case "move":
stgID, err := strconv.Atoi(args[4])
objectID, err := strconv.Atoi(args[2])
if err != nil {
fmt.Printf("invalid object id %s, err: %s", args[2], err.Error())
os.Exit(1)
}
stgID, err := strconv.Atoi(args[3])
if err != nil {
fmt.Printf("invalid storage id %s, err: %s", args[4], err.Error())
fmt.Printf("invalid storage id %s, err: %s", args[3], err.Error())
os.Exit(1)
}

if err := Move(args[2], args[3], stgID); err != nil {
if err := Move(objectID, stgID); err != nil {
fmt.Printf("move failed, err: %s", err.Error())
os.Exit(1)
}


Loading…
Cancel
Save