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

Sort parts by number and server creation time #929

Merged
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
8 changes: 7 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
cache: true
go-version: '1.21'

- name: Get tree-service client
run: make sync-tree

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: latest

Expand Down
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
18 changes: 18 additions & 0 deletions api/layer/multipart_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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,23 @@
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

if a.ServerCreated.Equal(b.ServerCreated) {
return 0
}

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

View check run for this annotation

Codecov / codecov/patch

api/layer/multipart_upload.go#L630-L632

Added lines #L630 - L632 were not covered by tests

return 1

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

View check run for this annotation

Codecov / codecov/patch

api/layer/multipart_upload.go#L634

Added line #L634 was not covered by tests
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
})

res := make(map[int]*data.PartInfo, len(parts))
partsNumbers := make([]int, len(parts))
oids := make([]string, len(parts))
Expand Down
6 changes: 3 additions & 3 deletions cmd/s3-authmate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ It will be ceil rounded to the nearest amount of epoch.`,
Destination: &slicerEnabledFlag,
},
},
Action: func(c *cli.Context) error {
Action: func(_ *cli.Context) error {
ctx, log := prepare()

password := wallet.GetPassword(viper.GetViper(), envWalletPassphrase)
Expand Down Expand Up @@ -465,7 +465,7 @@ It will be ceil rounded to the nearest amount of epoch.`,
Destination: &secretAccessKeyFlag,
},
},
Action: func(c *cli.Context) error {
Action: func(_ *cli.Context) error {
var cfg aws.Config
if regionFlag != "" {
cfg.Region = &regionFlag
Expand Down Expand Up @@ -646,7 +646,7 @@ func obtainSecret() *cli.Command {
Value: poolStreamTimeout,
},
},
Action: func(c *cli.Context) error {
Action: func(_ *cli.Context) error {
ctx, log := prepare()

password := wallet.GetPassword(viper.GetViper(), envWalletPassphrase)
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 @@
isDeleteMarkerKV = "IsDeleteMarker"
ownerKV = "Owner"
createdKV = "Created"
serverCreatedKV = "SrvCreated"

settingsFileName = "bucket-settings"
notifConfFileName = "bucket-notifications"
Expand Down Expand Up @@ -259,6 +260,12 @@
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 @@
}

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
Loading