@@ -4,9 +4,11 @@ import (
44 "context"
55 "errors"
66 "net/http"
7+ "strings"
78 "sync/atomic"
89 "time"
910
11+ "github.com/aws/aws-sdk-go/service/s3"
1012 "gorm.io/gorm"
1113
1214 "github.com/bnb-chain/greenfield-storage-provider/base/types/gfsperrors"
@@ -39,6 +41,10 @@ func ErrPieceStoreWithDetail(detail string) *gfsperrors.GfSpError {
3941 return gfsperrors .Register (module .ReceiveModularName , http .StatusInternalServerError , 85101 , detail )
4042}
4143
44+ func ErrPieceStoreNoSuchKeyWithDetail (detail string ) * gfsperrors.GfSpError {
45+ return gfsperrors .Register (module .ReceiveModularName , http .StatusNotFound , 85102 , detail )
46+ }
47+
4248func ErrGfSpDBWithDetail (detail string ) * gfsperrors.GfSpError {
4349 return gfsperrors .Register (module .ReceiveModularName , http .StatusInternalServerError , 85201 , detail )
4450}
@@ -175,8 +181,12 @@ func (d *DownloadModular) HandleDownloadObjectTask(ctx context.Context, download
175181 int64 (pInfo .Offset ), int64 (pInfo .Length ))
176182 if getPieceErr != nil {
177183 log .CtxErrorw (ctx , "failed to get piece data from piece store" , "task_info" , downloadObjectTask .Info (), "piece_info" , pInfo , "error" , getPieceErr )
178- err = ErrPieceStoreWithDetail ("failed to get piece data from piece store, error: " + getPieceErr .Error ())
179- return nil , err
184+ pieceStoreErrDetail := "failed to get piece data from piece store, task_info: " + downloadObjectTask .Info () + ", error: " + err .Error ()
185+ if isErrNoSuchKey (err ) {
186+ return nil , ErrPieceStoreNoSuchKeyWithDetail (pieceStoreErrDetail )
187+ } else {
188+ return nil , ErrPieceStoreWithDetail (pieceStoreErrDetail )
189+ }
180190 }
181191 d .pieceCache .Add (key , piece )
182192 data = append (data , piece ... )
@@ -389,7 +399,11 @@ func (d *DownloadModular) HandleDownloadPieceTask(ctx context.Context, downloadP
389399 int64 (downloadPieceTask .GetPieceOffset ()), int64 (downloadPieceTask .GetPieceLength ())); err != nil {
390400 metrics .PerfGetObjectTimeHistogram .WithLabelValues ("get_object_put_piece_time" ).Observe (time .Since (putPieceTime ).Seconds ())
391401 log .CtxErrorw (ctx , "failed to get piece data from piece store" , "task_info" , downloadPieceTask .Info (), "error" , err )
392- return nil , ErrPieceStoreWithDetail ("failed to get piece data from piece store, task_info: " + downloadPieceTask .Info () + ", error: " + err .Error ())
402+ pieceStoreErrDetail := "failed to get piece data from piece store, task_info: " + downloadPieceTask .Info () + ", error: " + err .Error ()
403+ if isErrNoSuchKey (err ) {
404+ return nil , ErrPieceStoreNoSuchKeyWithDetail (pieceStoreErrDetail )
405+ }
406+ return nil , ErrPieceStoreWithDetail (pieceStoreErrDetail )
393407 }
394408 metrics .PerfGetObjectTimeHistogram .WithLabelValues ("get_object_put_piece_time" ).Observe (time .Since (putPieceTime ).Seconds ())
395409 return pieceData , nil
@@ -462,7 +476,12 @@ func (d *DownloadModular) HandleChallengePiece(ctx context.Context, challengePie
462476 metrics .PerfChallengeTimeHistogram .WithLabelValues ("challenge_get_piece_time" ).Observe (time .Since (getPieceTime ).Seconds ())
463477 if err != nil {
464478 log .CtxErrorw (ctx , "failed to get piece data" , "task" , challengePieceTask , "error" , err )
465- return nil , nil , nil , ErrPieceStoreWithDetail ("failed to get piece data, error: " + err .Error ())
479+ pieceStoreErrDetail := "failed to get piece data, task: " + challengePieceTask .Info () + ", error: " + err .Error ()
480+ if isErrNoSuchKey (err ) {
481+ return nil , nil , nil , ErrPieceStoreNoSuchKeyWithDetail (pieceStoreErrDetail )
482+ } else {
483+ return nil , nil , nil , ErrPieceStoreWithDetail (pieceStoreErrDetail )
484+ }
466485 }
467486
468487 return integrity .IntegrityChecksum , integrity .PieceChecksumList , data , nil
@@ -474,3 +493,8 @@ func (d *DownloadModular) PostChallengePiece(context.Context, task.ChallengePiec
474493func (d * DownloadModular ) QueryTasks (context.Context , task.TKey ) ([]task.Task , error ) {
475494 return nil , nil
476495}
496+
497+ func isErrNoSuchKey (err error ) bool {
498+ msg := err .Error ()
499+ return strings .Contains (msg , s3 .ErrCodeNoSuchKey )
500+ }
0 commit comments