[filer] UploadRequestToChunks: terminate the upload of remaining chunks as early as possible might be more reasonable when one chunk upload goroutine encounters a failure. (#6610)

This commit is contained in:
hoverseu 2025-03-10 11:38:26 +08:00 committed by GitHub
parent 271505717e
commit 14cb8a24c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -64,6 +64,16 @@ func (fs *FilerServer) uploadReaderToChunks(reader io.Reader, startOffset int64,
// need to throttle used byte buffer // need to throttle used byte buffer
bytesBufferLimitChan <- struct{}{} bytesBufferLimitChan <- struct{}{}
// As long as there is an error in the upload of one chunk, it can be terminated early
// uploadErr may be modified in other go routines, lock is needed to avoid race condition
uploadErrLock.Lock()
if uploadErr != nil {
<-bytesBufferLimitChan
uploadErrLock.Unlock()
break
}
uploadErrLock.Unlock()
bytesBuffer := bufPool.Get().(*bytes.Buffer) bytesBuffer := bufPool.Get().(*bytes.Buffer)
limitedReader := io.LimitReader(partReader, int64(chunkSize)) limitedReader := io.LimitReader(partReader, int64(chunkSize))