From 6f534f69380bb47964ec3f64d096d89046559b24 Mon Sep 17 00:00:00 2001 From: gammazero Date: Tue, 10 Oct 2023 16:52:27 -0700 Subject: [PATCH] Modify replica struct to better describe deal spanning This PR changes a replica to be composed of a slice of pieces, each with a different status, verification time, etc. as per #65. Fixes #65 --- api/server/handler.go | 15 ++++++++------- blob/blob.go | 18 +++++++++++------- integration/singularity/store.go | 15 +++++++++------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/api/server/handler.go b/api/server/handler.go index 851b65c..23b6183 100644 --- a/api/server/handler.go +++ b/api/server/handler.go @@ -152,14 +152,15 @@ func (m *HttpServer) handleBlobGetStatusByID(w http.ResponseWriter, r *http.Requ ID: idUriSegment, } - if blobDesc.Status != nil { - response.Replicas = make([]api.Replica, 0, len(blobDesc.Status.Replicas)) - for _, replica := range blobDesc.Status.Replicas { + if blobDesc.Replica != nil && len(blobDesc.Replica.Pieces) != 0 { + response.Replicas = make([]api.Replica, 0, len(blobDesc.Replica.Pieces)) + provider := blobDesc.Replica.Provider + for _, piece := range blobDesc.Replica.Pieces { response.Replicas = append(response.Replicas, api.Replica{ - Provider: replica.Provider, - Status: replica.Status, - LastVerified: replica.LastUpdated, - Expiration: replica.Expiration, + Provider: provider, + Status: piece.Status, + LastVerified: piece.LastUpdated, + Expiration: piece.Expiration, }) } } diff --git a/blob/blob.go b/blob/blob.go index 29d7553..63759fc 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -30,17 +30,21 @@ type ( Size uint64 // ModificationTime is the latest time at which the blob was modified. ModificationTime time.Time - Status *Status + Replica *Replica } - Status struct { - Replicas []Replica + + Piece struct { + Expiration time.Time + LastUpdated time.Time + PieceCID string + Status string } + Replica struct { - Provider string - Status string - LastUpdated time.Time - Expiration time.Time + Provider string + Pieces []Piece } + Store interface { Put(context.Context, io.ReadCloser) (*Descriptor, error) Describe(context.Context, ID) (*Descriptor, error) diff --git a/integration/singularity/store.go b/integration/singularity/store.go index b209857..1c82d13 100644 --- a/integration/singularity/store.go +++ b/integration/singularity/store.go @@ -460,22 +460,25 @@ func (s *SingularityStore) Describe(ctx context.Context, id blob.ID) (*blob.Desc if err != nil { return nil, err } - replicas := make([]blob.Replica, 0, len(getFileDealsRes.Payload)) + pieces := make([]blob.Piece, 0, len(getFileDealsRes.Payload)) for _, deal := range getFileDealsRes.Payload { updatedAt, err := time.Parse("2006-01-02 15:04:05-07:00", deal.UpdatedAt) if err != nil { updatedAt = time.Time{} } - replicas = append(replicas, blob.Replica{ + pieces = append(pieces, blob.Piece{ + Expiration: epochutil.EpochToTime(int32(deal.EndEpoch)), LastUpdated: updatedAt, - Provider: deal.Provider, + PieceCID: deal.PieceCid, Status: string(deal.State), - Expiration: epochutil.EpochToTime(int32(deal.EndEpoch)), }) } - descriptor.Status = &blob.Status{ - Replicas: replicas, + if len(pieces) != 0 { + descriptor.Replica = &blob.Replica{ + Provider: getFileDealsRes.Payload[0].Provider, + Pieces: pieces, + } } return descriptor, nil }