Browse Source

合并了repRead和ecRead

gitlink
17BaoH 2 years ago
parent
commit
beadae0a77
4 changed files with 35 additions and 67 deletions
  1. +1
    -0
      assets/test3
  2. BIN
      client
  3. +33
    -64
      clientCommand.go
  4. +1
    -3
      main.go

+ 1
- 0
assets/test3 View File

@@ -0,0 +1 @@
122345678901234567890

BIN
client View File


+ 33
- 64
clientCommand.go View File

@@ -38,7 +38,7 @@ func Move(bucketName string, objectName string, destination string){
Destination: destination, Destination: destination,
} }
c1,_:=json.Marshal(command1) c1,_:=json.Marshal(command1)
b1:=append([]byte("06"),c1...)
b1:=append([]byte("05"),c1...)
fmt.Println(string(b1)) fmt.Println(string(b1))
rabbit1 := rabbitmq.NewRabbitMQSimple("coorQueue") rabbit1 := rabbitmq.NewRabbitMQSimple("coorQueue")
rabbit1.PublishSimple(b1) rabbit1.PublishSimple(b1)
@@ -124,30 +124,30 @@ func Move(bucketName string, objectName string, destination string){
rabbit4.Destroy() rabbit4.Destroy()
} }





func RepRead(localFilePath string, bucketName string, objectName string){
func Read(localFilePath string, bucketName string, objectName string){
fmt.Println("read "+bucketName+"/"+objectName+" to "+localFilePath) fmt.Println("read "+bucketName+"/"+objectName+" to "+localFilePath)
//获取块hash,ip,序号,编码参数等 //获取块hash,ip,序号,编码参数等
//发送写请求,分配写入节点Ip //发送写请求,分配写入节点Ip
userId:=0 userId:=0
command1:= rabbitmq.RepReadCommand{
command1:= rabbitmq.ReadCommand{
BucketName: bucketName, BucketName: bucketName,
ObjectName: objectName, ObjectName: objectName,
UserId: userId, UserId: userId,
} }
c1,_:=json.Marshal(command1) c1,_:=json.Marshal(command1)
b1:=append([]byte("05"),c1...)
b1:=append([]byte("02"),c1...)
fmt.Println(b1) fmt.Println(b1)
rabbit1 := rabbitmq.NewRabbitMQSimple("coorQueue") rabbit1 := rabbitmq.NewRabbitMQSimple("coorQueue")
rabbit1.PublishSimple(b1) rabbit1.PublishSimple(b1)


//接收消息,赋值给ip, repHash, fileSizeInBytes //接收消息,赋值给ip, repHash, fileSizeInBytes
var res1 rabbitmq.RepReadRes
var ip string
var repHash string
var res1 rabbitmq.ReadRes
var hashs []string
var ips []string
var fileSizeInBytes int64 var fileSizeInBytes int64
var ecName string
var ids []int
var redundancy string
queueName := "coorClientQueue"+strconv.Itoa(userId) queueName := "coorClientQueue"+strconv.Itoa(userId)
rabbit2 := rabbitmq.NewRabbitMQSimple(queueName) rabbit2 := rabbitmq.NewRabbitMQSimple(queueName)
msgs:=rabbit2.ConsumeSimple(time.Millisecond, true) msgs:=rabbit2.ConsumeSimple(time.Millisecond, true)
@@ -156,19 +156,35 @@ func RepRead(localFilePath string, bucketName string, objectName string){
go func() { go func() {
for d := range msgs { for d := range msgs {
_ = json.Unmarshal(d.Body, &res1) _ = json.Unmarshal(d.Body, &res1)
ip=res1.Ip
repHash=res1.Hash
fileSizeInBytes=res1.FileSizeInBytes
ips=res1.Ips
hashs=res1.Hashs
ids=res1.BlockIds
ecName=res1.EcName
fileSizeInBytes=res1.FileSizeInBytes
redundancy=res1.Redundancy
wg.Done() wg.Done()
} }
}() }()
wg.Wait() wg.Wait()
fmt.Println(ip)
fmt.Println(repHash)
fmt.Println(redundancy)
fmt.Println(ips)
fmt.Println(hashs)
fmt.Println(ids)
fmt.Println(ecName)
fmt.Println(fileSizeInBytes) fmt.Println(fileSizeInBytes)
rabbit1.Destroy() rabbit1.Destroy()
rabbit2.Destroy() rabbit2.Destroy()
switch redundancy {
case "rep":
repRead(fileSizeInBytes, ips[0], hashs[0], localFilePath)
case "ec":
ecRead(fileSizeInBytes, ips, hashs, ids, ecName, localFilePath)
}
}



func repRead(fileSizeInBytes int64, ip string, repHash string, localFilePath string){
numPacket := (fileSizeInBytes+packetSizeInBytes-1)/(packetSizeInBytes) numPacket := (fileSizeInBytes+packetSizeInBytes-1)/(packetSizeInBytes)
fmt.Println(numPacket) fmt.Println(numPacket)
//rpc相关 //rpc相关
@@ -208,7 +224,6 @@ func RepRead(localFilePath string, bucketName string, objectName string){
} }


func RepWrite(localFilePath string, bucketName string, objectName string, numRep int){ func RepWrite(localFilePath string, bucketName string, objectName string, numRep int){
fmt.Println("write "+localFilePath+" as "+bucketName+"/"+objectName)
userId:=0 userId:=0
//获取文件大小 //获取文件大小
fileInfo,_ := os.Stat(localFilePath) fileInfo,_ := os.Stat(localFilePath)
@@ -298,55 +313,9 @@ func RepWrite(localFilePath string, bucketName string, objectName string, numRep
// //
} }


func EcRead(localFilePath string, bucketName string, objectName string){
fmt.Println("read "+bucketName+"/"+objectName+" to "+localFilePath)
//获取块hash,ip,序号,编码参数等
userId:=0
command1:= rabbitmq.EcReadCommand{
BucketName: bucketName,
ObjectName: objectName,
UserId: userId,
}
c1,_:=json.Marshal(command1)
b1:=append([]byte("02"),c1...)
fmt.Println(b1)
rabbit1 := rabbitmq.NewRabbitMQSimple("coorQueue")
rabbit1.PublishSimple(b1)

//接收消息,赋值给ip, repHash, fileSizeInBytes
var res1 rabbitmq.EcReadRes
var blockHashs []string
var ips []string
var fileSizeInBytes int64
var ecName string
var blockIds []int
queueName := "coorClientQueue"+strconv.Itoa(userId)
rabbit2 := rabbitmq.NewRabbitMQSimple(queueName)
msgs:=rabbit2.ConsumeSimple(time.Millisecond, true)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
for d := range msgs {
_ = json.Unmarshal(d.Body, &res1)
ips=res1.Ips
blockHashs=res1.Hashs
blockIds=res1.BlockIds
ecName=res1.EcName
fileSizeInBytes=res1.FileSizeInBytes
wg.Done()
}
}()
wg.Wait()
fmt.Println(ips)
fmt.Println(blockHashs)
fmt.Println(blockIds)
fmt.Println(ecName)
fmt.Println(fileSizeInBytes)
rabbit1.Destroy()
rabbit2.Destroy()

func ecRead(fileSizeInBytes int64, ips []string, blockHashs []string, blockIds []int, ecName string, localFilePath string){
//根据ecName获得以下参数 //根据ecName获得以下参数
wg := sync.WaitGroup{}
const ecK int = 2 const ecK int = 2
const ecN int = 3 const ecN int = 3
var coefs = [][]int64 {{1,1,1},{1,2,3}}//2应替换为ecK,3应替换为ecN var coefs = [][]int64 {{1,1,1},{1,2,3}}//2应替换为ecK,3应替换为ecN


+ 1
- 3
main.go View File

@@ -28,13 +28,11 @@ func main() {
switch args[1] { switch args[1] {
case "ecWrite": case "ecWrite":
EcWrite(args[2], args[3], args[4], args[5]) EcWrite(args[2], args[3], args[4], args[5])
case "ecRead":
EcRead(args[2], args[3], args[4])
case "write": case "write":
numRep,_ :=strconv.Atoi(args[5]) numRep,_ :=strconv.Atoi(args[5])
RepWrite(args[2], args[3], args[4], numRep) RepWrite(args[2], args[3], args[4], numRep)
case "read": case "read":
RepRead(args[2], args[3], args[4])
Read(args[2], args[3], args[4])
case "move": case "move":
Move(args[2],args[3], args[4])//bucket object destination Move(args[2],args[3], args[4])//bucket object destination
} }


Loading…
Cancel
Save