From be6d8085c7449a923bddfeafaaa48a19c69525ea Mon Sep 17 00:00:00 2001 From: dlut_xz <52518280+fcgxz2003@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:28:24 +0800 Subject: [PATCH] feat: add finished piece count element in types (#2557) Signed-off-by: XZ <834756128@qq.com> --- scheduler/service/service_v1.go | 34 ++++++++++++++------------- scheduler/storage/storage_test.go | 34 ++++++++++++++------------- scheduler/storage/types.go | 6 +++++ trainer/storage/testdata/download.csv | 2 +- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/scheduler/service/service_v1.go b/scheduler/service/service_v1.go index 4ef22c4cc..7c7c359f8 100644 --- a/scheduler/service/service_v1.go +++ b/scheduler/service/service_v1.go @@ -1346,14 +1346,15 @@ func (v *V1) createDownloadRecord(peer *resource.Peer, parents []*resource.Peer, var parentRecords []storage.Parent for _, parent := range parents { parentRecord := storage.Parent{ - ID: parent.ID, - Tag: parent.Task.Tag, - Application: parent.Task.Application, - State: parent.FSM.Current(), - Cost: parent.Cost.Load().Nanoseconds(), - UploadPieceCount: 0, - CreatedAt: parent.CreatedAt.Load().UnixNano(), - UpdatedAt: parent.UpdatedAt.Load().UnixNano(), + ID: parent.ID, + Tag: parent.Task.Tag, + Application: parent.Task.Application, + State: parent.FSM.Current(), + Cost: parent.Cost.Load().Nanoseconds(), + UploadPieceCount: 0, + FinishedPieceCount: int32(parent.FinishedPieces.Count()), + CreatedAt: parent.CreatedAt.Load().UnixNano(), + UpdatedAt: parent.UpdatedAt.Load().UnixNano(), Host: storage.Host{ ID: parent.Host.ID, Type: parent.Host.Type.Name(), @@ -1450,14 +1451,15 @@ func (v *V1) createDownloadRecord(peer *resource.Peer, parents []*resource.Peer, } download := storage.Download{ - ID: peer.ID, - Tag: peer.Task.Tag, - Application: peer.Task.Application, - State: peer.FSM.Current(), - Cost: peer.Cost.Load().Nanoseconds(), - Parents: parentRecords, - CreatedAt: peer.CreatedAt.Load().UnixNano(), - UpdatedAt: peer.UpdatedAt.Load().UnixNano(), + ID: peer.ID, + Tag: peer.Task.Tag, + Application: peer.Task.Application, + State: peer.FSM.Current(), + Cost: peer.Cost.Load().Nanoseconds(), + FinishedPieceCount: int32(peer.FinishedPieces.Count()), + Parents: parentRecords, + CreatedAt: peer.CreatedAt.Load().UnixNano(), + UpdatedAt: peer.UpdatedAt.Load().UnixNano(), Task: storage.Task{ ID: peer.Task.ID, URL: peer.Task.URL, diff --git a/scheduler/storage/storage_test.go b/scheduler/storage/storage_test.go index bc38fdb3e..4261b4f0d 100644 --- a/scheduler/storage/storage_test.go +++ b/scheduler/storage/storage_test.go @@ -125,16 +125,17 @@ var ( mockPieces = append(make([]Piece, 9), mockPiece) mockParent = Parent{ - ID: "4", - Tag: "m", - Application: "db", - State: "Succeeded", - Cost: 1000, - UploadPieceCount: 10, - Host: mockHost, - Pieces: mockPieces, - CreatedAt: time.Now().UnixNano(), - UpdatedAt: time.Now().UnixNano(), + ID: "4", + Tag: "m", + Application: "db", + State: "Succeeded", + Cost: 1000, + UploadPieceCount: 10, + FinishedPieceCount: 10, + Host: mockHost, + Pieces: mockPieces, + CreatedAt: time.Now().UnixNano(), + UpdatedAt: time.Now().UnixNano(), } mockParents = append(make([]Parent, 19), mockParent) @@ -148,12 +149,13 @@ var ( Code: "unknow", Message: "unknow", }, - Cost: 1000, - Task: mockTask, - Host: mockHost, - Parents: mockParents, - CreatedAt: time.Now().UnixNano(), - UpdatedAt: time.Now().UnixNano(), + Cost: 1000, + FinishedPieceCount: 10, + Task: mockTask, + Host: mockHost, + Parents: mockParents, + CreatedAt: time.Now().UnixNano(), + UpdatedAt: time.Now().UnixNano(), } mockSrcHost = SrcHost{ diff --git a/scheduler/storage/types.go b/scheduler/storage/types.go index 3ae7e127b..ffa8ee637 100644 --- a/scheduler/storage/types.go +++ b/scheduler/storage/types.go @@ -156,6 +156,9 @@ type Parent struct { // UploadPieceCount is upload piece count. UploadPieceCount int32 `csv:"uploadPieceCount"` + // FinishedPieceCount is finished piece count. + FinishedPieceCount int32 `csv:"finishedPieceCount"` + // Host is peer host. Host Host `csv:"host"` @@ -199,6 +202,9 @@ type Download struct { // Cost is the task download duration of nanosecond. Cost int64 `csv:"cost"` + // FinishedPieceCount is finished piece count. + FinishedPieceCount int32 `csv:"finishedPieceCount"` + // Task is peer task. Task Task `csv:"task"` diff --git a/trainer/storage/testdata/download.csv b/trainer/storage/testdata/download.csv index c9fbc9b5f..442487065 100644 --- a/trainer/storage/testdata/download.csv +++ b/trainer/storage/testdata/download.csv @@ -1 +1 @@ -5,d,mq,Succeeded,unknow,unknow,1000,1,example.com,normal,2048,1,10,2,Succeeded,1689072709228040702,1689072709228040802,2,normal,localhost,127.0.0.1,8080,8081,linux,ubuntu,debian,1.0.0,1.0.0,100,40,20,3,24,12,0.8,0.4,100,101,102,103,104,105,106,107,108,109,20,19,16,0.7,0.2,15,400,200,china,e1,100,88,56,0.9,200,180,160,0.6,3.0.0,2bf4d5e,1.19,linux,1689072709228040863,1689072709228044069,,,,,0,0,,,,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,,,,,0,0,,,,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,,,,,0,0,,,,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,,,,,0,0,,,,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,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ux,ubuntu,debian,1.0.0,1.0.0,100,40,20,3,24,12,0.8,0.4,100,101,102,103,104,105,106,107,108,109,20,19,16,0.7,0.2,15,400,200,china,e1,100,88,56,0.9,200,180,160,0.6,3.0.0,2bf4d5e,1.19,linux,1689072709228040863,1689072709228044069,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,10,1689072709228044129,1689072709228045381,1689072709228045441,1689072709228053546,1689072709228053606 +5,d,mq,Succeeded,unknow,unknow,1000,10,1,example.com,normal,2048,1,10,2,Succeeded,1689685929626279983,1689685929626280083,2,normal,localhost,127.0.0.1,8080,8081,linux,ubuntu,debian,1.0.0,1.0.0,100,40,20,3,24,12,0.8,0.4,100,101,102,103,104,105,106,107,108,109,20,19,16,0.7,0.2,15,400,200,china,e1,100,88,56,0.9,200,180,160,0.6,3.0.0,2bf4d5e,1.19,linux,1689685929626280163,1689685929626284802,,,,,0,0,0,,,,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,,,,,0,0,0,,,,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,,,,,0,0,0,,,,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,,,,,0,0,0,,,,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,,,,,0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127.0.0.1,8080,8081,linux,ubuntu,debian,1.0.0,1.0.0,100,40,20,3,24,12,0.8,0.4,100,101,102,103,104,105,106,107,108,109,20,19,16,0.7,0.2,15,400,200,china,e1,100,88,56,0.9,200,180,160,0.6,3.0.0,2bf4d5e,1.19,linux,1689685929626280163,1689685929626284802,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,10,1689685929626284872,1689685929626286204,1689685929626286274,1689685929626310119,1689685929626310189