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

Update object Put to avoid loosing last chunk #995

Merged
merged 1 commit into from Jun 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 28 additions & 22 deletions object.go
Expand Up @@ -372,37 +372,43 @@ func (obs *obs) Put(meta *ObjectMeta, r io.Reader, opts ...ObjectOpt) (*ObjectIn

// Actual read.
// TODO(dlc) - Deadline?
n, err := r.Read(chunk)
n, readErr := r.Read(chunk)

// Handle all non EOF errors
if readErr != nil && readErr != io.EOF {
purgePartial()
return nil, readErr
}

// Add chunk only if we received data
if n > 0 {
// Chunk processing.
m.Data = chunk[:n]
h.Write(m.Data)

// Send msg itself.
if _, err := js.PublishMsgAsync(m); err != nil {
purgePartial()
return nil, err
}
if err := getErr(); err != nil {
purgePartial()
return nil, err
}
// Update totals.
sent++
total += uint64(n)
}

// EOF Processing.
if err == io.EOF {
if readErr == io.EOF {
// Finalize sha.
sha := h.Sum(nil)
// Place meta info.
info.Size, info.Chunks = uint64(total), uint32(sent)
info.Digest = fmt.Sprintf(objDigestTmpl, base64.URLEncoding.EncodeToString(sha[:]))
break
} else if err != nil {
purgePartial()
return nil, err
}

// Chunk processing.
m.Data = chunk[:n]
h.Write(m.Data)

// Send msg itself.
if _, err := js.PublishMsgAsync(m); err != nil {
purgePartial()
return nil, err
}
if err := getErr(); err != nil {
purgePartial()
return nil, err
}
// Update totals.
sent++
total += uint64(n)
}

// Publish the metadata.
Expand Down