package main import ( //"context" //"io" "fmt" //"path/filepath" //"sync" "encoding/json" "rabbitmq" "strconv" "utils" //agentcaller "proto" //"github.com/pborman/uuid" //"github.com/streadway/amqp" //"google.golang.org/grpc" ) func rabbitSend(c []byte, userId int) { //TO DO xh: queueName调整:coorClientQueue+"_"+"本机Ip"+"_"+"进程号" queueName := "coorClientQueue" + strconv.Itoa(userId) rabbit := rabbitmq.NewRabbitMQSimple(queueName) fmt.Println(string(c)) rabbit.PublishSimple(c) rabbit.Destroy() } func TempCacheReport(command rabbitmq.TempCacheReport) { fmt.Println("TempCacheReport") fmt.Println(command.Hashs) fmt.Println(command.Ip) //返回消息 for i := 0; i < len(command.Hashs); i++ { cache := Update_Cache(command.Hashs[i], command.Ip) //若要插入缓存不存在,将hashs中的hash,IP插入缓存表中,TempOrPin字段为true,Time为插入时的时间戳 if cache == (Cache{}) { a := []string{} b := []string{} a = append(a, command.Hashs[i]) b = append(b, command.Ip) Insert_Cache(a, b, true) } } //jh:将hashs中的hash,IP插入缓存表中,TempOrPin字段为true,Time为插入时的时间戳 //-如果要插入的hash、IP在表中已存在且所对应的TempOrPin字段为false,则不做任何操作 //-如果要插入的hash、IP在表中已存在且所对应的TempOrPin字段为true,则更新Time } func CoorMove(command rabbitmq.MoveCommand) { fmt.Println("CoorMove") fmt.Println(command.BucketName) //查询数据库,获取冗余类型,冗余参数 //jh:使用command中的bucketname和objectname查询对象表,获得redundancy,EcName,fileSizeInBytes //-若redundancy是rep,查询对象副本表, 获得repHash //--ids :={0} //--hashs := {repHash} //-若redundancy是ec,查询对象编码块表,获得blockHashs, ids(innerID), //--查询缓存表,获得每个hash的nodeIps、TempOrPins、Times //--查询节点延迟表,得到command.destination与各个nodeIps的的延迟,存到一个map类型中(Delay) //--kx:根据查出来的hash/hashs、nodeIps、TempOrPins、Times(移动/读取策略)、Delay确定hashs、ids BucketID := Query_BucketID(command.BucketName) //jh:使用command中的bucketid和objectname查询对象表,获得objectid,redundancy,EcName,fileSizeInBytes ObjectID, fileSizeInBytes, redundancyy, ecName := Query_Object(command.ObjectName, BucketID) //-若redundancy是rep,查询对象副本表, 获得repHash var hashs []string ids := []int{0} redundancy := "rep" if redundancyy { //rep repHash := Query_ObjectRep(ObjectID) hashs = append(hashs, repHash) } else { //ec redundancy = "ec" blockHashs := Query_ObjectBlock(ObjectID) ecPolicies := *utils.GetEcPolicy() ecPolicy := ecPolicies[ecName] ecN := ecPolicy.GetN() ecK := ecPolicy.GetK() ids = make([]int, ecK) for i := 0; i < ecN; i++ { hashs = append(hashs, "-1") } for i := 0; i < ecK; i++ { ids[i] = i } hashs = make([]string, ecN) for _, tt := range blockHashs { id := tt.InnerID hash := tt.BlockHash hashs[id] = hash } //--查询缓存表,获得每个hash的nodeIps、TempOrPins、Times /*for id,hash := range blockHashs{ //type Cache struct {NodeIP string,TempOrPin bool,Cachetime string} Cache := Query_Cache(hash) //利用Time_trans()函数可将Cache[i].Cachetime转化为时间戳格式 //--查询节点延迟表,得到command.Destination与各个nodeIps的延迟,存到一个map类型中(Delay) Delay := make(map[string]int) // 延迟集合 for i:=0; i