Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Modify replica struct to better describe deal spanning
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gammazero committed Oct 10, 2023
1 parent f0e5388 commit 6f534f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
15 changes: 8 additions & 7 deletions api/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
Expand Down
18 changes: 11 additions & 7 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions integration/singularity/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6f534f6

Please sign in to comment.