Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chunked break #1479

Draft
wants to merge 5 commits into
base: sprint-1.14
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion zboxcore/sdk/chunked_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ func (su *ChunkedUpload) process() error {
if chunks.isFinal {
if su.fileMeta.ActualHash == "" {
su.fileMeta.ActualHash, err = su.chunkReader.GetFileHash()
logger.Logger.Info("ActualHash: ", su.fileMeta.ActualHash)
if err != nil {
if su.statusCallback != nil {
su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err)
Expand Down Expand Up @@ -611,6 +612,9 @@ func (su *ChunkedUpload) readChunks(num int) (*batchChunksData, error) {
//blobber i
data.fileShards[i] = append(data.fileShards[i], v)
}
} else {
data.isFinal = true
break
}

if chunk.IsFinal {
Expand Down Expand Up @@ -646,7 +650,10 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int,

wgErrors := make(chan error, len(su.blobbers))
if len(fileShards) == 0 {
return thrown.New("upload_failed", "Upload failed. No data to upload")
if !isFinal {
return thrown.New("upload_failed", "Upload failed. No data to upload")
}
fileShards = make([]blobberShards, len(su.blobbers))
}

for i := su.uploadMask; !i.Equals64(0); i = i.And(zboxutil.NewUint128(1).Lsh(pos).Not()) {
Expand Down
15 changes: 0 additions & 15 deletions zboxcore/sdk/chunked_upload_blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,6 @@ func (sb *ChunkedUploadBlobber) sendUploadRequest(
}
}()

if formData.FileBytesLen == 0 {
//fixed fileRef in last chunk on stream. io.EOF with nil bytes
if isFinal {
sb.fileRef.ChunkSize = su.chunkSize
sb.fileRef.Size = su.shardUploadedSize
sb.fileRef.Path = su.fileMeta.RemotePath
sb.fileRef.ActualFileHash = su.fileMeta.ActualHash
sb.fileRef.ActualFileSize = su.fileMeta.ActualSize

sb.fileRef.EncryptedKey = encryptedKey
sb.fileRef.CalculateHash()
consensus.Done()
}
}

eg, _ := errgroup.WithContext(ctx)

for dataInd := 0; dataInd < len(dataBuffers); dataInd++ {
Expand Down
46 changes: 23 additions & 23 deletions zboxcore/sdk/chunked_upload_form_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ func (b *chunkedUploadFormBuilder) Build(

var res blobberData

if len(fileChunksData) == 0 {
return res, nil
}

numBodies := len(fileChunksData) / MAX_BLOCKS
if len(fileChunksData)%MAX_BLOCKS > 0 {
numBodies++
}
if len(fileChunksData) == 0 {
numBodies = 1
}
dataBuffers := make([]*bytes.Buffer, 0, numBodies)
contentSlice := make([]string, 0, numBodies)

Expand Down Expand Up @@ -103,33 +102,34 @@ func (b *chunkedUploadFormBuilder) Build(
body := bytes.NewBuffer(bodyBuf)
formWriter := multipart.NewWriter(body)
defer formWriter.Close()

uploadFile, err := formWriter.CreateFormFile("uploadFile", formData.Filename)
if err != nil {
return res, err
}

for _, chunkBytes := range fileChunksData[startRange:endRange] {
_, err = uploadFile.Write(chunkBytes)
if endRange > startRange {
uploadFile, err := formWriter.CreateFormFile("uploadFile", formData.Filename)
if err != nil {
return res, err
}

err = hasher.WriteToFixedMT(chunkBytes)
if err != nil {
return res, err
}
for _, chunkBytes := range fileChunksData[startRange:endRange] {
_, err = uploadFile.Write(chunkBytes)
if err != nil {
return res, err
}

err = hasher.WriteToValidationMT(chunkBytes)
if err != nil {
return res, err
}
err = hasher.WriteToFixedMT(chunkBytes)
if err != nil {
return res, err
}

err = hasher.WriteToValidationMT(chunkBytes)
if err != nil {
return res, err
}

metadata.FileBytesLen += len(chunkBytes)
metadata.FileBytesLen += len(chunkBytes)
}
}

if isFinal && i == numBodies-1 {
err = hasher.Finalize()
err := hasher.Finalize()
if err != nil {
return res, err
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func (b *chunkedUploadFormBuilder) Build(
formData.UploadOffset = formData.UploadOffset + chunkSize*int64(MAX_BLOCKS)
}

err = formWriter.WriteField("connection_id", connectionID)
err := formWriter.WriteField("connection_id", connectionID)
if err != nil {
return res, err
}
Expand Down
Loading