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

Add shard size to formData #1175

Merged
merged 14 commits into from
Aug 23, 2023
11 changes: 6 additions & 5 deletions zboxcore/sdk/chunked_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ func CreateChunkedUpload(
}

su.loadProgress()

su.fileHasher = CreateHasher(getShardSize(su.fileMeta.ActualSize, su.allocationObj.DataShards, su.encryptOnUpload))
su.shardSize = getShardSize(su.fileMeta.ActualSize, su.allocationObj.DataShards, su.encryptOnUpload)
su.fileHasher = CreateHasher(su.shardSize)

// encrypt option has been changed. upload it from scratch
// chunkSize has been changed. upload it from scratch
Expand Down Expand Up @@ -324,6 +324,8 @@ type ChunkedUpload struct {
shardUploadedSize int64
// shardUploadedThumbnailSize how much thumbnail bytes a shard has. it is original size
shardUploadedThumbnailSize int64
// size of shard
shardSize int64

// statusCallback trigger progress on StatusCallback
statusCallback StatusCallback
Expand Down Expand Up @@ -395,7 +397,7 @@ func (su *ChunkedUpload) createUploadProgress(connectionId string) {

for i := 0; i < len(su.progress.Blobbers); i++ {
su.progress.Blobbers[i] = &UploadBlobberStatus{
Hasher: CreateHasher(getShardSize(su.fileMeta.ActualSize, su.allocationObj.DataShards, su.encryptOnUpload)),
Hasher: CreateHasher(su.shardSize),
}
}

Expand Down Expand Up @@ -626,7 +628,6 @@ func (su *ChunkedUpload) readChunks(num int) (*batchChunksData, error) {
func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int,
fileShards []blobberShards, thumbnailShards blobberShards,
isFinal bool, uploadLength int64) error {

su.consensus.Reset()

ctx, cancel := context.WithCancel(context.TODO())
Expand Down Expand Up @@ -663,7 +664,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int,
body, formData, err := su.formBuilder.Build(
&su.fileMeta, blobber.progress.Hasher, su.progress.ConnectionID,
su.chunkSize, chunkStartIndex, chunkEndIndex, isFinal, encryptedKey,
fileShards[pos], thumbnailChunkData)
fileShards[pos], thumbnailChunkData, su.shardSize)
if err != nil {
errC := atomic.AddInt32(&errCount, 1)
if errC > int32(su.allocationObj.ParityShards-1) { // If atleast data shards + 1 number of blobbers can process the upload, it can be repaired later
Expand Down
5 changes: 3 additions & 2 deletions zboxcore/sdk/chunked_upload_form_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ChunkedUploadFormBuilder interface {
fileMeta *FileMeta, hasher Hasher, connectionID string,
chunkSize int64, chunkStartIndex, chunkEndIndex int,
isFinal bool, encryptedKey string, fileChunksData [][]byte,
thumbnailChunkData []byte,
thumbnailChunkData []byte, shardSize int64,
) (*bytes.Buffer, ChunkedUploadFormMetadata, error)
}

Expand All @@ -48,7 +48,7 @@ func (b *chunkedUploadFormBuilder) Build(
fileMeta *FileMeta, hasher Hasher, connectionID string,
chunkSize int64, chunkStartIndex, chunkEndIndex int,
isFinal bool, encryptedKey string, fileChunksData [][]byte,
thumbnailChunkData []byte,
thumbnailChunkData []byte, shardSize int64,
) (*bytes.Buffer, ChunkedUploadFormMetadata, error) {

metadata := ChunkedUploadFormMetadata{
Expand Down Expand Up @@ -78,6 +78,7 @@ func (b *chunkedUploadFormBuilder) Build(
ChunkStartIndex: chunkStartIndex,
ChunkEndIndex: chunkEndIndex,
UploadOffset: chunkSize * int64(chunkStartIndex),
Size: shardSize,
}

formWriter := multipart.NewWriter(body)
Expand Down
2 changes: 1 addition & 1 deletion zboxcore/sdk/chunked_upload_form_builder_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func BenchmarkChunkedUploadFormBuilder(b *testing.B) {

fileBytes := buf[begin:end]

_, _, err := builder.Build(fileMeta, hasher, "connectionID", int64(bm.ChunkSize), chunkIndex, chunkIndex, isFinal, "", [][]byte{fileBytes}, nil)
_, _, err := builder.Build(fileMeta, hasher, "connectionID", int64(bm.ChunkSize), chunkIndex, chunkIndex, isFinal, "", [][]byte{fileBytes}, nil, getShardSize(fileMeta.ActualSize, 1, false))
if err != nil {
b.Fatal(err)
return
Expand Down
1 change: 1 addition & 0 deletions zboxcore/sdk/chunked_upload_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type UploadFormData struct {
ChunkEndIndex int `json:"chunk_end_index,omitempty"` // end index of chunks. all chunks MUST be uploaded one by one because of streaming merkle hash
ChunkSize int64 `json:"chunk_size,omitempty"` // the size of a chunk. 64*1024 is default
UploadOffset int64 `json:"upload_offset,omitempty"` // It is next position that new incoming chunk should be append to
Size int64 `json:"size"` // total size of shard

}

Expand Down
Loading