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

log more information about s3 and client state when getting a mismatc… #2

Open
wants to merge 1 commit into
base: acj/wistia-patch-series
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package tusd

import (
"io"
"strconv"
"time"
)

type MetaData map[string]string
Expand All @@ -25,6 +27,45 @@ type FileInfo struct {
// ordered slice containing the ids of the uploads of which the final upload
// will consist after concatenation.
PartialUploads []string
//Added for diagnosing annoying mismatch offsets for wistia uploads
Parts []Part
}

type Part struct {

// Entity tag returned when the part was uploaded.
ETag *string `type:"string"`

// Date and time at which the part was uploaded.
LastModified *time.Time `type:"timestamp"`

// Part number identifying the part. This is a positive integer between 1 and
// 10,000.
PartNumber *int64 `type:"integer"`

// Size in bytes of the uploaded part data.
Size *int64 `type:"integer"`
// contains filtered or unexported fields
}

func (p Part) String() string {
etag := ""
lastModified := ""
partNumber := ""
size := ""
if p.ETag != nil {
etag = *p.ETag
}
if p.LastModified != nil {
lastModified = p.LastModified.String()
}
if p.PartNumber != nil {
partNumber = strconv.FormatInt(*p.PartNumber, 10)
}
if p.Size != nil {
size = strconv.FormatInt(*p.Size, 10)
}
return "etag: " + etag + ",lastModified: " + lastModified + ",partNumber: " + partNumber + ",size: " + size
}

type DataStore interface {
Expand Down
16 changes: 16 additions & 0 deletions s3store/s3store.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ func (store S3Store) GetInfo(id string) (info tusd.FileInfo, err error) {
offset += *part.Size
}

info.Parts = convertParts(parts)

incompletePartObject, err := store.getIncompletePartForUpload(uploadId)
if err != nil {
return info, err
Expand Down Expand Up @@ -617,6 +619,20 @@ func (store S3Store) DeclareLength(id string, length int64) error {
return store.writeInfo(uploadId, info)
}

func convertParts(parts []*s3.Part) []tusd.Part {
var convertedParts []tusd.Part
for _, part := range parts {
convertedPart := tusd.Part {
ETag: part.ETag,
LastModified: part.LastModified,
PartNumber: part.PartNumber,
Size: part.Size,
}
convertedParts = append(convertedParts, convertedPart)
}
return convertedParts
}

func (store S3Store) listAllParts(id string) (parts []*s3.Part, err error) {
uploadId, multipartId := splitIds(id)

Expand Down
18 changes: 18 additions & 0 deletions unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/base64"
"errors"
"fmt"
"io"
"log"
"math"
Expand Down Expand Up @@ -455,6 +456,23 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
}

if offset != info.Offset {
parts := info.Parts
loggableParts := ""
for _, part := range parts {
loggableParts += part.String() + ":"
}
handler.log("ErrMismatchOffset",
"id", id,
"size", strconv.FormatInt(info.Size, 10),
"size is deferred?", strconv.FormatBool(info.SizeIsDeferred),
"header offset", strconv.FormatInt(offset, 10),
"s3 offset", strconv.FormatInt(info.Offset, 10),
"metadata", fmt.Sprintf("%v", info.MetaData),
"is partial?", strconv.FormatBool(info.IsPartial),
"is final?", strconv.FormatBool(info.IsFinal),
"partial uploads", strings.Join(info.PartialUploads[:], ","),
"upload parts", loggableParts)

handler.sendError(w, r, ErrMismatchOffset)
return
}
Expand Down