Skip to content

Commit

Permalink
Merge pull request #1421 from 0chain/fix/conn-size
Browse files Browse the repository at this point in the history
Fix update connection size
  • Loading branch information
dabasov committed May 16, 2024
2 parents 8aaf842 + a89b435 commit feda209
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 4 additions & 1 deletion code/go/0chain.net/blobbercore/allocation/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func UpdateConnectionObjSize(connectionID string, addSize int64) {
connectionObj.UpdatedAt = time.Now()
}

func SaveFileChange(connectionID, pathHash, fileName string, cmd FileCommand, isFinal bool, contentSize int64, offset, dataWritten int64) (bool, error) {
func SaveFileChange(connectionID, pathHash, fileName string, cmd FileCommand, isFinal bool, contentSize, offset, dataWritten, addSize int64) (bool, error) {
connectionObjMutex.RLock()
connectionObj := connectionProcessor[connectionID]
connectionObjMutex.RUnlock()
Expand Down Expand Up @@ -210,6 +210,9 @@ func SaveFileChange(connectionID, pathHash, fileName string, cmd FileCommand, is
Offset: offset,
DataBytes: dataWritten,
}, contentSize)
if addSize != 0 {
UpdateConnectionObjSize(connectionID, addSize)
}
} else {
change.seqPQ.Push(seqpriorityqueue.UploadData{
Offset: offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func (cmd *UpdateFileCommand) ProcessContent(allocationObj *allocation.Allocatio
if fileOutputData.ContentSize != cmd.fileChanger.Size {
return result, common.NewError("upload_error", fmt.Sprintf("File size mismatch. Expected: %d, Actual: %d", cmd.fileChanger.Size, fileOutputData.ContentSize))
}
allocation.UpdateConnectionObjSize(connID, cmd.fileChanger.Size-cmd.existingFileRef.Size)
}

if cmd.thumbFile != nil {
Expand All @@ -157,7 +156,7 @@ func (cmd *UpdateFileCommand) ProcessContent(allocationObj *allocation.Allocatio
}
}

saveChange, err := allocation.SaveFileChange(connID, cmd.fileChanger.PathHash, cmd.fileChanger.Filename, cmd, cmd.fileChanger.IsFinal, cmd.fileChanger.Size, cmd.fileChanger.UploadOffset, fileOutputData.Size)
saveChange, err := allocation.SaveFileChange(connID, cmd.fileChanger.PathHash, cmd.fileChanger.Filename, cmd, cmd.fileChanger.IsFinal, cmd.fileChanger.Size, cmd.fileChanger.UploadOffset, fileOutputData.Size, cmd.fileChanger.Size-cmd.existingFileRef.Size)
if err != nil {
return result, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func (cmd *UploadFileCommand) ProcessContent(allocationObj *allocation.Allocatio
if fileOutputData.ContentSize != cmd.fileChanger.Size {
return result, common.NewError("upload_error", fmt.Sprintf("File size mismatch. Expected: %d, Actual: %d", cmd.fileChanger.Size, fileOutputData.ContentSize))
}
allocation.UpdateConnectionObjSize(connectionID, cmd.fileChanger.Size)
}

if cmd.thumbFile != nil {
Expand All @@ -175,7 +174,7 @@ func (cmd *UploadFileCommand) ProcessContent(allocationObj *allocation.Allocatio
}
}

saveChange, err := allocation.SaveFileChange(connectionID, cmd.fileChanger.PathHash, cmd.fileChanger.Filename, cmd, cmd.fileChanger.IsFinal, cmd.fileChanger.Size, cmd.fileChanger.UploadOffset, fileOutputData.Size)
saveChange, err := allocation.SaveFileChange(connectionID, cmd.fileChanger.PathHash, cmd.fileChanger.Filename, cmd, cmd.fileChanger.IsFinal, cmd.fileChanger.Size, cmd.fileChanger.UploadOffset, fileOutputData.Size, cmd.fileChanger.Size)
if err != nil {
logging.Logger.Error("UploadFileCommand.ProcessContent", zap.Error(err))
return result, err
Expand Down

0 comments on commit feda209

Please sign in to comment.