Skip to content

Commit bf7d292

Browse files
anton-107denik
andauthored
Copy and sort lists of changed files when instantiating EventChanges (#2836)
## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> In #2824 in-place sorting was added which caused the slices to be mutated on every event read and changed the order of the sync operations ## Tests <!-- How have you tested the changes? --> Existing acceptance test run with hyperfine ``` hyperfine -m 100 --show-output 'go test ./acceptance -run ^TestAccept$/^bundle$/^sync$/^dryrun$ -count=1' ``` was consistently failing on 20-30th iteration before this change and is not failing on 100 iterations after the change. <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. --> --------- Co-authored-by: Denis Bilenko <denis.bilenko@databricks.com>
1 parent 8e23550 commit bf7d292

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

libs/sync/event.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package sync
33
import (
44
"context"
55
"fmt"
6-
"sort"
6+
"slices"
77
"strings"
88
"time"
99
)
@@ -48,18 +48,21 @@ type EventChanges struct {
4848
Delete []string `json:"delete,omitempty"`
4949
}
5050

51+
// creates EventChanges with filenames in Put and Delete sorted alphabetically
52+
func newEventChanges(put, delete []string) *EventChanges {
53+
return &EventChanges{Put: slices.Sorted(slices.Values(put)), Delete: slices.Sorted(slices.Values(delete))}
54+
}
55+
5156
func (e *EventChanges) IsEmpty() bool {
5257
return len(e.Put) == 0 && len(e.Delete) == 0
5358
}
5459

5560
func (e *EventChanges) String() string {
5661
var changes []string
5762
if len(e.Put) > 0 {
58-
sort.Strings(e.Put)
5963
changes = append(changes, "PUT: "+strings.Join(e.Put, ", "))
6064
}
6165
if len(e.Delete) > 0 {
62-
sort.Strings(e.Delete)
6366
changes = append(changes, "DELETE: "+strings.Join(e.Delete, ", "))
6467
}
6568
return strings.Join(changes, ", ")
@@ -81,7 +84,7 @@ func (e *EventStart) String() string {
8184
func newEventStart(seq int, put, delete []string, dryRun bool) Event {
8285
return &EventStart{
8386
EventBase: newEventBase(seq, EventTypeStart, dryRun),
84-
EventChanges: &EventChanges{Put: put, Delete: delete},
87+
EventChanges: newEventChanges(put, delete),
8588
}
8689
}
8790

@@ -141,7 +144,7 @@ func (e *EventSyncComplete) String() string {
141144
func newEventComplete(seq int, put, delete []string, dryRun bool) Event {
142145
return &EventSyncComplete{
143146
EventBase: newEventBase(seq, EventTypeComplete, dryRun),
144-
EventChanges: &EventChanges{Put: put, Delete: delete},
147+
EventChanges: newEventChanges(put, delete),
145148
}
146149
}
147150

0 commit comments

Comments
 (0)