Skip to content

Commit

Permalink
multipart: Sort parts by number and server creation time
Browse files Browse the repository at this point in the history
Closes #901.

Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Feb 12, 2024
1 parent bdb5e35 commit 5cdde04
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
5 changes: 4 additions & 1 deletion api/data/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ type PartInfo struct {
OID oid.ID
Size int64
ETag string
Created time.Time
// Creation time from the client.
Created time.Time
// Server creation time.
ServerCreated time.Time
}

// ToHeaderString form short part representation to use in S3-Completed-Parts header.
Expand Down
14 changes: 14 additions & 0 deletions api/layer/multipart_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/user"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -616,6 +617,19 @@ func (n *layer) getUploadParts(ctx context.Context, p *UploadInfoParams) (*data.
return nil, nil, err
}

// Sort parts by part number, then by server creation time to make actual last uploaded parts with the same number.
slices.SortFunc(parts, func(a, b *data.PartInfo) int {
if a.Number < b.Number {
return -1
}

Check warning on line 624 in api/layer/multipart_upload.go

View check run for this annotation

Codecov / codecov/patch

api/layer/multipart_upload.go#L621-L624

Added lines #L621 - L624 were not covered by tests

if a.ServerCreated.Before(b.ServerCreated) {
return -1
}

Check warning on line 628 in api/layer/multipart_upload.go

View check run for this annotation

Codecov / codecov/patch

api/layer/multipart_upload.go#L626-L628

Added lines #L626 - L628 were not covered by tests

return 1

Check warning on line 630 in api/layer/multipart_upload.go

View check run for this annotation

Codecov / codecov/patch

api/layer/multipart_upload.go#L630

Added line #L630 was not covered by tests
})

res := make(map[int]*data.PartInfo, len(parts))
partsNumbers := make([]int, len(parts))
oids := make([]string, len(parts))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/urfave/cli/v2 v2.3.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.17.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
)
Expand All @@ -34,7 +35,6 @@ require (
github.com/nspcc-dev/go-ordered-json v0.0.0-20231123160306-3374ff1e7a3c // indirect
github.com/nspcc-dev/hrw/v2 v2.0.0-20231115095647-bf62f4ad0a43 // indirect
github.com/twmb/murmur3 v1.1.8 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sync v0.3.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
)
Expand Down
18 changes: 13 additions & 5 deletions internal/neofs/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const (
isDeleteMarkerKV = "IsDeleteMarker"
ownerKV = "Owner"
createdKV = "Created"
serverCreatedKV = "SrvCreated"

settingsFileName = "bucket-settings"
notifConfFileName = "bucket-notifications"
Expand Down Expand Up @@ -259,6 +260,12 @@ func newPartInfo(node NodeResponse) (*data.PartInfo, error) {
return nil, fmt.Errorf("invalid created timestamp: %w", err)
}
partInfo.Created = time.UnixMilli(utcMilli)
case serverCreatedKV:
var utcMilli int64
if utcMilli, err = strconv.ParseInt(value, 10, 64); err != nil {
return nil, fmt.Errorf("invalid server created timestamp: %w", err)
}
partInfo.ServerCreated = time.UnixMilli(utcMilli)

Check warning on line 268 in internal/neofs/tree.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/tree.go#L263-L268

Added lines #L263 - L268 were not covered by tests
}
}

Expand Down Expand Up @@ -903,11 +910,12 @@ func (c *TreeClient) AddPart(ctx context.Context, bktInfo *data.BucketInfo, mult
}

meta := map[string]string{
partNumberKV: strconv.Itoa(info.Number),
oidKV: info.OID.EncodeToString(),
sizeKV: strconv.FormatInt(info.Size, 10),
createdKV: strconv.FormatInt(info.Created.UTC().UnixMilli(), 10),
etagKV: info.ETag,
partNumberKV: strconv.Itoa(info.Number),
oidKV: info.OID.EncodeToString(),
sizeKV: strconv.FormatInt(info.Size, 10),
createdKV: strconv.FormatInt(info.Created.UTC().UnixMilli(), 10),
serverCreatedKV: strconv.FormatInt(time.Now().UTC().UnixMilli(), 10),
etagKV: info.ETag,

Check warning on line 918 in internal/neofs/tree.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/tree.go#L913-L918

Added lines #L913 - L918 were not covered by tests
}

var foundPartID uint64
Expand Down

0 comments on commit 5cdde04

Please sign in to comment.