@@ -451,7 +451,7 @@ func writeBytes(tctx *tcontext.Context, writer storage.ExternalFileWriter, p []b
451
451
return errors .Trace (err )
452
452
}
453
453
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 ) {
455
455
fileName += compressFileSuffix (compressType )
456
456
fullPath := s .URI () + "/" + fileName
457
457
writer , err := storage .WithCompression (s , compressType ).Create (tctx , fileName )
@@ -462,20 +462,24 @@ func buildFileWriter(tctx *tcontext.Context, s storage.ExternalStorage, fileName
462
462
return nil , nil , errors .Trace (err )
463
463
}
464
464
tctx .L ().Debug ("opened file" , zap .String ("path" , fullPath ))
465
- tearDownRoutine := func (ctx context.Context ) {
465
+ tearDownRoutine := func (ctx context.Context ) error {
466
466
err := writer .Close (ctx )
467
+ failpoint .Inject ("FailToCloseMetaFile" , func (_ failpoint.Value ) {
468
+ err = errors .New ("injected error: fail to close meta file" )
469
+ })
467
470
if err == nil {
468
- return
471
+ return nil
469
472
}
470
473
err = errors .Trace (err )
471
474
tctx .L ().Warn ("fail to close file" ,
472
475
zap .String ("path" , fullPath ),
473
476
zap .Error (err ))
477
+ return err
474
478
}
475
479
return writer , tearDownRoutine , nil
476
480
}
477
481
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 ) {
479
483
fileName += compressFileSuffix (compressType )
480
484
var writer storage.ExternalFileWriter
481
485
fullPath := s .URI () + "/" + fileName
@@ -497,17 +501,21 @@ func buildInterceptFileWriter(pCtx *tcontext.Context, s storage.ExternalStorage,
497
501
}
498
502
fileWriter .initRoutine = initRoutine
499
503
500
- tearDownRoutine := func (ctx context.Context ) {
504
+ tearDownRoutine := func (ctx context.Context ) error {
501
505
if writer == nil {
502
- return
506
+ return nil
503
507
}
504
508
pCtx .L ().Debug ("tear down lazy file writer..." , zap .String ("path" , fullPath ))
505
509
err := writer .Close (ctx )
510
+ failpoint .Inject ("FailToCloseDataFile" , func (_ failpoint.Value ) {
511
+ err = errors .New ("injected error: fail to close data file" )
512
+ })
506
513
if err != nil {
507
514
pCtx .L ().Warn ("fail to close file" ,
508
515
zap .String ("path" , fullPath ),
509
516
zap .Error (err ))
510
517
}
518
+ return err
511
519
}
512
520
return fileWriter , tearDownRoutine
513
521
}
0 commit comments