@@ -451,7 +451,7 @@ func writeBytes(tctx *tcontext.Context, writer storage.ExternalFileWriter, p []b
451451 return errors .Trace (err )
452452}
453453
454- func buildFileWriter (tctx * tcontext.Context , s storage.ExternalStorage , fileName string , compressType storage.CompressType ) (storage.ExternalFileWriter , func (ctx context.Context ), error ) {
454+ func buildFileWriter (tctx * tcontext.Context , s storage.ExternalStorage , fileName string , compressType storage.CompressType ) (storage.ExternalFileWriter , func (ctx context.Context ) error , error ) {
455455 fileName += compressFileSuffix (compressType )
456456 fullPath := s .URI () + "/" + fileName
457457 writer , err := storage .WithCompression (s , compressType ).Create (tctx , fileName )
@@ -462,20 +462,24 @@ func buildFileWriter(tctx *tcontext.Context, s storage.ExternalStorage, fileName
462462 return nil , nil , errors .Trace (err )
463463 }
464464 tctx .L ().Debug ("opened file" , zap .String ("path" , fullPath ))
465- tearDownRoutine := func (ctx context.Context ) {
465+ tearDownRoutine := func (ctx context.Context ) error {
466466 err := writer .Close (ctx )
467+ failpoint .Inject ("FailToCloseMetaFile" , func (_ failpoint.Value ) {
468+ err = errors .New ("injected error: fail to close meta file" )
469+ })
467470 if err == nil {
468- return
471+ return nil
469472 }
470473 err = errors .Trace (err )
471474 tctx .L ().Warn ("fail to close file" ,
472475 zap .String ("path" , fullPath ),
473476 zap .Error (err ))
477+ return err
474478 }
475479 return writer , tearDownRoutine , nil
476480}
477481
478- func buildInterceptFileWriter (pCtx * tcontext.Context , s storage.ExternalStorage , fileName string , compressType storage.CompressType ) (storage.ExternalFileWriter , func (context.Context )) {
482+ func buildInterceptFileWriter (pCtx * tcontext.Context , s storage.ExternalStorage , fileName string , compressType storage.CompressType ) (storage.ExternalFileWriter , func (context.Context ) error ) {
479483 fileName += compressFileSuffix (compressType )
480484 var writer storage.ExternalFileWriter
481485 fullPath := s .URI () + "/" + fileName
@@ -497,17 +501,21 @@ func buildInterceptFileWriter(pCtx *tcontext.Context, s storage.ExternalStorage,
497501 }
498502 fileWriter .initRoutine = initRoutine
499503
500- tearDownRoutine := func (ctx context.Context ) {
504+ tearDownRoutine := func (ctx context.Context ) error {
501505 if writer == nil {
502- return
506+ return nil
503507 }
504508 pCtx .L ().Debug ("tear down lazy file writer..." , zap .String ("path" , fullPath ))
505509 err := writer .Close (ctx )
510+ failpoint .Inject ("FailToCloseDataFile" , func (_ failpoint.Value ) {
511+ err = errors .New ("injected error: fail to close data file" )
512+ })
506513 if err != nil {
507514 pCtx .L ().Warn ("fail to close file" ,
508515 zap .String ("path" , fullPath ),
509516 zap .Error (err ))
510517 }
518+ return err
511519 }
512520 return fileWriter , tearDownRoutine
513521}
0 commit comments