Browse Source

增加接口返回信息

gitlink
songjc 2 years ago
parent
commit
5565a15f67
4 changed files with 32 additions and 21 deletions
  1. +10
    -6
      models/models.go
  2. +6
    -6
      pkgs/db/object_block.go
  3. +3
    -4
      pkgs/db/object_rep.go
  4. +13
    -5
      pkgs/mq/coordinator/package.go

+ 10
- 6
models/models.go View File

@@ -1,5 +1,7 @@
package models

import "gitlink.org.cn/cloudream/storage-common/pkgs/db/model"

/// TODO 将分散在各处的公共结构体定义集中到这里来

type RedundancyData interface{}
@@ -59,25 +61,27 @@ func NewEc(id int, name string, ecK int, ecN int) EC {
}

type ObjectRepData struct {
ObjectID int64 `json:"objectID"`
FileHash string `json:"fileHash"`
NodeIDs []int64 `json:"nodeIDs"`
Object model.Object `json:"object"`
FileHash string `json:"fileHash"`
NodeIDs []int64 `json:"nodeIDs"`
}

func NewObjectRepData(objectID int64, fileHash string, nodeIDs []int64) ObjectRepData {
func NewObjectRepData(object model.Object, fileHash string, nodeIDs []int64) ObjectRepData {
return ObjectRepData{
ObjectID: objectID,
Object: object,
FileHash: fileHash,
NodeIDs: nodeIDs,
}
}

type ObjectECData struct {
Object model.Object `json:"object"`
Blocks []ObjectBlockData `json:"blocks"`
}

func NewObjectECData(blocks []ObjectBlockData) ObjectECData {
func NewObjectECData(object model.Object, blocks []ObjectBlockData) ObjectECData {
return ObjectECData{
Object: object,
Blocks: blocks,
}
}


+ 6
- 6
pkgs/db/object_block.go View File

@@ -85,15 +85,15 @@ func (db *ObjectBlockDB) GetBatchBlocksNodes(ctx SQLContext, hashs [][]string) (
}

func (db *ObjectBlockDB) GetWithNodeIDInPackage(ctx SQLContext, packageID int64) ([]models.ObjectECData, error) {
var objectIDs []int64
err := sqlx.Select(ctx, &objectIDs, "select ObjectID from Object where PackageID = ? order by ObjectID asc", packageID)
var objs []model.Object
err := sqlx.Select(ctx, &objs, "select * from Object where PackageID = ? order by ObjectID asc", packageID)
if err != nil {
return nil, fmt.Errorf("query objectIDs: %w", err)
}

rets := make([]models.ObjectECData, 0, len(objectIDs))
rets := make([]models.ObjectECData, 0, len(objs))

for _, objID := range objectIDs {
for _, obj := range objs {
var tmpRets []struct {
Index int `db:"Index"`
FileHash string `db:"FileHash"`
@@ -105,7 +105,7 @@ func (db *ObjectBlockDB) GetWithNodeIDInPackage(ctx SQLContext, packageID int64)
"select ObjectBlock.Index, ObjectBlock.FileHash, group_concat(NodeID) as NodeIDs from ObjectBlock"+
" left join Cache on ObjectBlock.FileHash = Cache.FileHash"+
" where ObjectID = ? group by ObjectBlock.Index, ObjectBlock.FileHash",
objID,
obj.ObjectID,
)
if err != nil {
return nil, err
@@ -124,7 +124,7 @@ func (db *ObjectBlockDB) GetWithNodeIDInPackage(ctx SQLContext, packageID int64)
blocks = append(blocks, block)
}

rets = append(rets, models.NewObjectECData(blocks))
rets = append(rets, models.NewObjectECData(obj, blocks))
}

return rets, nil


+ 3
- 4
pkgs/db/object_rep.go View File

@@ -81,14 +81,14 @@ func (db *ObjectRepDB) GetFileMaxRepCount(ctx SQLContext, fileHash string) (int,

func (db *ObjectRepDB) GetWithNodeIDInPackage(ctx SQLContext, packageID int64) ([]models.ObjectRepData, error) {
var tmpRets []struct {
ObjectID int64 `db:"ObjectID"`
model.Object
FileHash *string `db:"FileHash"`
NodeIDs *string `db:"NodeIDs"`
}

err := sqlx.Select(ctx,
&tmpRets,
"select Object.ObjectID, ObjectRep.FileHash, group_concat(NodeID) as NodeIDs from Object"+
"select Object.*, ObjectRep.FileHash, group_concat(NodeID) as NodeIDs from Object"+
" left join ObjectRep on Object.ObjectID = ObjectRep.ObjectID"+
" left join Cache on ObjectRep.FileHash = Cache.FileHash"+
" where PackageID = ? group by Object.ObjectID order by Object.ObjectID asc",
@@ -97,11 +97,10 @@ func (db *ObjectRepDB) GetWithNodeIDInPackage(ctx SQLContext, packageID int64) (
if err != nil {
return nil, err
}

rets := make([]models.ObjectRepData, 0, len(tmpRets))
for _, tmp := range tmpRets {
var repData models.ObjectRepData
repData.ObjectID = tmp.ObjectID
repData.Object = tmp.Object

if tmp.FileHash != nil {
repData.FileHash = *tmp.FileHash


+ 13
- 5
pkgs/mq/coordinator/package.go View File

@@ -212,9 +212,14 @@ type GetPackageCachedNodes struct {
PackageID int64 `json:"packageID"`
}

type PackageCachedNodeInfo struct {
NodeID int64 `json:"nodeID"`
FileSize int64 `json:"fileSize"`
ObjectCount int64 `json:"objectCount"`
}

type GetPackageCachedNodesResp struct {
NodeIDs []int64 `json:"nodeIDs"`
RedundancyType string `json:"redundancyType"`
models.PackageCachingInfo
}

func NewGetPackageCachedNodes(userID int64, packageID int64) GetPackageCachedNodes {
@@ -224,10 +229,13 @@ func NewGetPackageCachedNodes(userID int64, packageID int64) GetPackageCachedNod
}
}

func NewGetPackageCachedNodesResp(nodeIDs []int64, redundancyType string) GetPackageCachedNodesResp {
func NewGetPackageCachedNodesResp(nodeInfos []models.NodePackageCachingInfo, packageSize int64, redunancyType string) GetPackageCachedNodesResp {
return GetPackageCachedNodesResp{
NodeIDs: nodeIDs,
RedundancyType: redundancyType,
PackageCachingInfo: models.PackageCachingInfo{
NodeInfos: nodeInfos,
PackageSize: packageSize,
RedunancyType: redunancyType,
},
}
}



Loading…
Cancel
Save