Skip to content

Commit

Permalink
don't count metadata not found as internal error (Layr-Labs#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooselumph authored Mar 30, 2024
1 parent b77f1dd commit 4db2480
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
9 changes: 7 additions & 2 deletions disperser/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ func (s *DispersalServer) GetBlobStatus(ctx context.Context, req *pb.BlobStatusR
s.logger.Debug("metadataKey", "metadataKey", metadataKey.String())
metadata, err := s.blobStore.GetBlobMetadata(ctx, metadataKey)
if err != nil {
// TODO: we need to distinguish NOT_FOUND from actual internal error.
if errors.Is(err, disperser.ErrMetadataNotFound) {
return nil, api.NewInvalidArgError("no metadata found for the requestID")
}
return nil, api.NewInternalError(fmt.Sprintf("failed to get blob metadata, blobkey: %s", metadataKey.String()))
}

Expand Down Expand Up @@ -650,7 +652,10 @@ func (s *DispersalServer) RetrieveBlob(ctx context.Context, req *pb.RetrieveBlob
blobMetadata, err := s.blobStore.GetMetadataInBatch(ctx, batchHeaderHash32, blobIndex)
if err != nil {
s.logger.Error("Failed to retrieve blob metadata", "err", err)
// TODO: we need to distinguish NOT_FOUND from actual internal error.
if errors.Is(err, disperser.ErrMetadataNotFound) {
s.metrics.IncrementFailedBlobRequestNum(codes.NotFound.String(), "", "RetrieveBlob")
return nil, api.NewInvalidArgError("no metadata found for the given batch header hash and blob index")
}
s.metrics.IncrementFailedBlobRequestNum(codes.Internal.String(), "", "RetrieveBlob")
return nil, api.NewInternalError("failed to get blob metadata, please retry")
}
Expand Down
2 changes: 1 addition & 1 deletion disperser/apiserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func TestRetrieveBlobFailsWhenBlobNotConfirmed(t *testing.T) {
// Try to retrieve the blob before it is confirmed
_, err = retrieveBlob(t, dispersalServer, requestID, 2)
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "rpc error: code = Internal desc = failed to get blob metadata, please retry")
assert.Equal(t, "rpc error: code = InvalidArgument desc = no metadata found for the given batch header hash and blob index", err.Error())

}

Expand Down
7 changes: 6 additions & 1 deletion disperser/common/blobstore/blob_metadata_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (s *BlobMetadataStore) GetBlobMetadata(ctx context.Context, metadataKey dis
Value: metadataKey.MetadataHash,
},
})

if item == nil {
return nil, fmt.Errorf("%w: metadata not found for key %s", disperser.ErrMetadataNotFound, metadataKey)
}

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -199,7 +204,7 @@ func (s *BlobMetadataStore) GetBlobMetadataInBatch(ctx context.Context, batchHea
}

if len(items) == 0 {
return nil, fmt.Errorf("there is no metadata for batch %s and blob index %d", batchHeaderHash, blobIndex)
return nil, fmt.Errorf("%w: there is no metadata for batch %s and blob index %d", disperser.ErrMetadataNotFound, batchHeaderHash, blobIndex)
}

if len(items) > 1 {
Expand Down
3 changes: 2 additions & 1 deletion disperser/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package disperser
import "errors"

var (
ErrBlobNotFound = errors.New("blob not found")
ErrBlobNotFound = errors.New("blob not found")
ErrMetadataNotFound = errors.New("metadata not found")
)

0 comments on commit 4db2480

Please sign in to comment.