Skip to content

Commit

Permalink
fix shard length error
Browse files Browse the repository at this point in the history
  • Loading branch information
stardust committed Apr 19, 2023
1 parent 4e7f13b commit 2d3c7c8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sugon/sgclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ func (sg *sgclient) UploadBigFile(filePath string, reader io.Reader, totalLength

chunkCount := int(math.Ceil(float64(totalLength) / float64(CHUNK_SIZE)))
chunkNumber := 1
var readLength int64 = 0
for {
n := 0
dataBuffer := make([]byte, 0)
Expand All @@ -811,7 +812,9 @@ func (sg *sgclient) UploadBigFile(filePath string, reader io.Reader, totalLength
}
dataBuffer = append(dataBuffer, pipeBuffer...)
n += nn
if nn < READ_BUFFER_SIZE || n >= CHUNK_SIZE {
readLength += int64(nn)
logger.Infof("n=%d nn=%d dataBuffer=%d pipeBuffer=%d readLength=%d", n, nn, len(dataBuffer), len(pipeBuffer), readLength)
if readLength >= totalLength || n >= CHUNK_SIZE {
break
}
}
Expand All @@ -829,6 +832,9 @@ func (sg *sgclient) UploadBigFile(filePath string, reader io.Reader, totalLength
if err != nil {
return nil, err
}
logger.Infof("sugon&&&Upload shard, path=%s, totalLength=%d, currentChunkSize=%d"+
", chunkSize=%d,chunkNumber=%d, dataBuffer=%d, pipeBuffer=%d n=%d, length=%d",
filePath, totalLength, n, CHUNK_SIZE, chunkNumber, len(dataBuffer), len(pipeBuffer), n, length)
contentType := bodyWriter.FormDataContentType()
bodyWriter.Close()
//生成要访问的url
Expand Down Expand Up @@ -895,8 +901,8 @@ func (sg *sgclient) UploadBigFile(filePath string, reader io.Reader, totalLength
}
if uploadResp.Code != "0" {
return nil, false, fmt.Errorf("sugon---Upload failed, path=%s, totalLength=%d, currentChunkSize=%d"+
", chunkSize=%d, Code=%s, Message=%s, chunkNumber=%d, dataBuffer=%d, pipeBuffer=%d",
filePath, totalLength, n, CHUNK_SIZE, uploadResp.Code, uploadResp.Msg, chunkNumber, len(dataBuffer), len(pipeBuffer))
", chunkSize=%d, Code=%s, Message=%s, chunkNumber=%d, dataBuffer=%d, pipeBuffer=%d n=%d readlength=%d",
filePath, totalLength, n, CHUNK_SIZE, uploadResp.Code, uploadResp.Msg, chunkNumber, len(dataBuffer), len(pipeBuffer), n, readLength)
}
return response, false, err
})
Expand Down

0 comments on commit 2d3c7c8

Please sign in to comment.