Browse Source

修复一些问题,增加TODO

gitlink
Sydonian 2 years ago
parent
commit
8de9d69e46
3 changed files with 12 additions and 108 deletions
  1. +0
    -52
      internal/services/command_service_ec.go
  2. +5
    -5
      internal/services/object.go
  3. +7
    -51
      internal/services/storage.go

+ 0
- 52
internal/services/command_service_ec.go View File

@@ -97,55 +97,3 @@ func (svc *Service) CreateEcObject(msg *coormsg.CreateEcObject) (*coormsg.Create


return ramsg.ReplyOK(coormsg.NewCreateObjectResp(objID)) return ramsg.ReplyOK(coormsg.NewCreateObjectResp(objID))
} }

//func (service *Service) ECWrite(msg *coormsg.ECWriteCommand) *coormsg.PreUploadResp {
// panic("not implement yet!")

/*
//jh:根据command中的UserId查询用户节点权限表,返回用户可用的NodeIp
//kx:根据command中的ecName,得到ecN,然后从jh查到的NodeIp中选择ecN个,赋值给Ips
//jh:完成对象表、对象编码块表的插入(对象编码块表的Hash字段先不插入)
//返回消息
//查询用户可用的节点IP
nodes, err := service.db.GetUserNodes(msg.Body.UserID)
if err != nil {
log.Warnf("query user nodes failed, err: %s", err.Error())
return ramsg.NewCoorWriteRespFailed(errorcode.OPERATION_FAILED, "query user nodes failed")
}

ecid := msg.Body.ECName
ecPolicies := *utils.GetEcPolicy()
ecPolicy := ecPolicies[ecid]
ecN := ecPolicy.GetN()

if len(nodes) < ecN {
log.Warnf("user nodes are not enough, err: %s", err.Error())
return ramsg.NewCoorWriteRespFailed(errorcode.OPERATION_FAILED, "user nodes are not enough")
}

ids := make([]int, ecN)
ips := make([]string, ecN)
//随机选取numRep个nodeIp
start := utils.GetRandInt(len(nodes))
for i := 0; i < ecN; i++ {
index := (start + i) % len(nodes)
ids[i] = nodes[index].NodeID
ips[i] = nodes[index].IP
}

// TODO 参考RepWrite,将创建EC对象的逻辑移动到WriteECHash中,并合成成一个事务
//根据BucketName查询BucketID
BucketID := Query_BucketID(msg.Body.BucketName)
if BucketID == -1 {
// TODO 日志
return ramsg.NewCoorWriteRespFailed(errorcode.OPERATION_FAILED, fmt.Sprintf("bucket id not found for %s", msg.Body.BucketName))
}
//对象表插入Insert_Cache
ObjectID := Insert_EcObject(msg.Body.ObjectName, BucketID, msg.Body.FileSize, msg.Body.ECName)
//对象编码块表插入,hash暂时为空
for i := 0; i < ecN; i++ {
Insert_EcObjectBlock(ObjectID, i)
}
return ramsg.NewCoorWriteRespOK(ids, ips)
*/
//}

+ 5
- 5
internal/services/object.go View File

@@ -82,7 +82,7 @@ func (svc *Service) PreDownloadObject(msg *coormsg.PreDownloadObject) (*coormsg.
ramsg.NewRespRepRedundancyData(objectRep.FileHash, respNodes), ramsg.NewRespRepRedundancyData(objectRep.FileHash, respNodes),
)) ))


}else{
} else {
// TODO 参考上面进行重写 // TODO 参考上面进行重写
ecName := object.Redundancy ecName := object.Redundancy
blocks, err := svc.db.QueryObjectBlock(object.ObjectID) blocks, err := svc.db.QueryObjectBlock(object.ObjectID)
@@ -95,9 +95,9 @@ func (svc *Service) PreDownloadObject(msg *coormsg.PreDownloadObject) (*coormsg.
//查询纠删码参数 //查询纠删码参数
ec, err := svc.db.Ec().GetEc(svc.db.SQLCtx(), ecName) ec, err := svc.db.Ec().GetEc(svc.db.SQLCtx(), ecName)
ecc := ramsg.NewEc(ec.EcID, ec.Name, ec.EcK, ec.EcN) ecc := ramsg.NewEc(ec.EcID, ec.Name, ec.EcK, ec.EcN)
//查询每个编码块存放的所有节点
//查询每个编码块存放的所有节点
respNodes := make([][]ramsg.RespNode, len(blocks)) respNodes := make([][]ramsg.RespNode, len(blocks))
for i:=0; i<len(blocks); i++{
for i := 0; i < len(blocks); i++ {
nodes, err := svc.db.Cache().FindCachingFileUserNodes(svc.db.SQLCtx(), msg.UserID, blocks[i].BlockHash) nodes, err := svc.db.Cache().FindCachingFileUserNodes(svc.db.SQLCtx(), msg.UserID, blocks[i].BlockHash)
if err != nil { if err != nil {
logger.WithField("FileHash", blocks[i].BlockHash). logger.WithField("FileHash", blocks[i].BlockHash).
@@ -117,9 +117,9 @@ func (svc *Service) PreDownloadObject(msg *coormsg.PreDownloadObject) (*coormsg.
respNodes[i] = nd respNodes[i] = nd
logger.Debugf("##%d\n", i) logger.Debugf("##%d\n", i)
} }
var blockss []ramsg.RespObjectBlock var blockss []ramsg.RespObjectBlock
for i:=0; i<len(blocks); i++{
for i := 0; i < len(blocks); i++ {
blockss = append(blockss, ramsg.NewRespObjectBlock( blockss = append(blockss, ramsg.NewRespObjectBlock(
blocks[i].InnerID, blocks[i].InnerID,
blocks[i].BlockHash, blocks[i].BlockHash,


+ 7
- 51
internal/services/storage.go View File

@@ -2,11 +2,12 @@ package services


import ( import (
"database/sql" "database/sql"
"fmt"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"gitlink.org.cn/cloudream/common/consts/errorcode" "gitlink.org.cn/cloudream/common/consts/errorcode"
"gitlink.org.cn/cloudream/common/models" "gitlink.org.cn/cloudream/common/models"
"gitlink.org.cn/cloudream/common/pkg/logger" "gitlink.org.cn/cloudream/common/pkg/logger"

//"gitlink.org.cn/cloudream/common/utils" //"gitlink.org.cn/cloudream/common/utils"
ramsg "gitlink.org.cn/cloudream/rabbitmq/message" ramsg "gitlink.org.cn/cloudream/rabbitmq/message"
coormsg "gitlink.org.cn/cloudream/rabbitmq/message/coordinator" coormsg "gitlink.org.cn/cloudream/rabbitmq/message/coordinator"
@@ -23,16 +24,6 @@ func (svc *Service) GetStorageInfo(msg *coormsg.GetStorageInfo) (*coormsg.GetSto
} }


func (svc *Service) PreMoveObjectToStorage(msg *coormsg.PreMoveObjectToStorage) (*coormsg.PreMoveObjectToStorageResp, *ramsg.CodeMessage) { func (svc *Service) PreMoveObjectToStorage(msg *coormsg.PreMoveObjectToStorage) (*coormsg.PreMoveObjectToStorageResp, *ramsg.CodeMessage) {
//查询数据库,获取冗余类型,冗余参数
//jh:使用command中的bucketname和objectname查询对象表,获得redundancy,EcName,fileSize
//-若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

// 查询用户关联的存储服务 // 查询用户关联的存储服务
stg, err := svc.db.Storage().GetUserStorage(svc.db.SQLCtx(), msg.UserID, msg.StorageID) stg, err := svc.db.Storage().GetUserStorage(svc.db.SQLCtx(), msg.UserID, msg.StorageID)
if err != nil { if err != nil {
@@ -76,58 +67,23 @@ func (svc *Service) PreMoveObjectToStorage(msg *coormsg.PreMoveObjectToStorage)
} }
//查询纠删码参数 //查询纠删码参数
ec, err := svc.db.Ec().GetEc(svc.db.SQLCtx(), ecName) ec, err := svc.db.Ec().GetEc(svc.db.SQLCtx(), ecName)
// TODO zkx 异常处理
ecc := models.NewEc(ec.EcID, ec.Name, ec.EcK, ec.EcN) ecc := models.NewEc(ec.EcID, ec.Name, ec.EcK, ec.EcN)
/*//查询每个编码块存放的所有节点
respNodes := make([][]ramsg.RespNode, len(blocks))
for i:=0; i<len(blocks); i++{
nodes, err := svc.db.Cache().FindCachingFileUserNodes(svc.db.SQLCtx(), msg.UserID, blocks[i].BlockHash)
if err != nil {
logger.WithField("FileHash", blocks[i].BlockHash).
Warnf("query Cache failed, err: %s", err.Error())
return ramsg.ReplyFailed[coormsg.PreDownloadObjectResp](errorcode.OperationFailed, "query Cache failed")
}
var nd []ramsg.RespNode
for _, node := range nodes {
nd = append(nd, ramsg.NewRespNode(
node.NodeID,
node.ExternalIP,
node.LocalIP,
// LocationID 相同则认为是在同一个地域
foundBelongNode && belongNode.LocationID == node.LocationID,
))
}
respNodes[i] = nd
logger.Debugf("##%d\n", i)
}
*/

blockss := make([]models.ObjectBlock, len(blocks)) blockss := make([]models.ObjectBlock, len(blocks))
for i:=0; i<len(blocks); i++{
for i := 0; i < len(blocks); i++ {
blockss[i] = models.NewObjectBlock( blockss[i] = models.NewObjectBlock(
blocks[i].InnerID, blocks[i].InnerID,
blocks[i].BlockHash, blocks[i].BlockHash,
) )
} }
fmt.Println(blockss)

return ramsg.ReplyOK(coormsg.NewPreMoveObjectToStorageRespBody( return ramsg.ReplyOK(coormsg.NewPreMoveObjectToStorageRespBody(
stg.NodeID, stg.NodeID,
stg.Directory, stg.Directory,
object, object,
models.NewRedundancyEcData(ecc,blockss),
models.NewRedundancyEcData(ecc, blockss),
)) ))
//--查询缓存表,获得每个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<len(Cache); i++{
Delay[Cache[i].NodeIP] = Query_NodeDelay(Destination, Cache[i].NodeIP)
}
//--kx:根据查出来的hash/hashs、nodeIps、TempOrPins、Times(移动/读取策略)、Delay确定hashs、ids
}*/
} }
} }




Loading…
Cancel
Save