-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: lakectl local diff slowness (#7842)
* Fix: lakectl local diff slowness * Fix upload * Update pkg/local/diff.go Co-authored-by: Ariel Shaqed (Scolnicov) <[email protected]> * Add unit tests * Add a fuzzer for walking POSIX directories in S3 order Looks like it found somethine almost immediately :-/ AFAIU tests will run _existing_ failures in testdata/fuzz. You can fuzz more by running something like: ```sh $ go test -v ./pkg/local/ -fuzz FuzzWalkS3 --fuzztime 5m === RUN TestDiffLocal === RUN TestDiffLocal/t1_no_diff === RUN TestDiffLocal/t1_modified === RUN TestDiffLocal/t1_local_before === RUN TestDiffLocal/t1_local_after === RUN TestDiffLocal/t1_hidden_changed --- PASS: TestDiffLocal (0.00s) --- PASS: TestDiffLocal/t1_no_diff (0.00s) --- PASS: TestDiffLocal/t1_modified (0.00s) --- PASS: TestDiffLocal/t1_local_before (0.00s) --- PASS: TestDiffLocal/t1_local_after (0.00s) --- PASS: TestDiffLocal/t1_hidden_changed (0.00s) === RUN TestWalkS3 === RUN TestWalkS3/reverse_order === RUN TestWalkS3/file_in_the_middle === RUN TestWalkS3/dirs_at_the_end === RUN TestWalkS3/files_mixed_with_directories --- PASS: TestWalkS3 (0.00s) --- PASS: TestWalkS3/reverse_order (0.00s) --- PASS: TestWalkS3/file_in_the_middle (0.00s) --- PASS: TestWalkS3/dirs_at_the_end (0.00s) --- PASS: TestWalkS3/files_mixed_with_directories (0.00s) === RUN TestWriteIndex --- PASS: TestWriteIndex (0.00s) === RUN TestReadIndex --- PASS: TestReadIndex (0.00s) === RUN TestFindIndices --- PASS: TestFindIndices (0.00s) === RUN FuzzWalkS3 fuzz: elapsed: 0s, gathering baseline coverage: 0/47 completed failure while testing seed corpus entry: FuzzWalkS3/0345f16af6907ab1 fuzz: elapsed: 0s, gathering baseline coverage: 0/47 completed --- FAIL: FuzzWalkS3 (0.03s) --- FAIL: FuzzWalkS3 (0.00s) diff_test.go:323: Error Trace: /home/ariels/dev/lakeFS/pkg/local/diff_test.go:323 /home/ariels/sdk/go1.21.3/src/reflect/value.go:596 /home/ariels/sdk/go1.21.3/src/reflect/value.go:380 /home/ariels/sdk/go1.21.3/src/testing/fuzz.go:335 Error: Not equal: expected: []string{"imported 0", "imported/0"} actual : []string{"imported/0", "imported 0"} Diff: --- Expected +++ Actual @@ -1,4 +1,4 @@ ([]string) (len=2) { - (string) (len=10) "imported 0", - (string) (len=10) "imported/0" + (string) (len=10) "imported/0", + (string) (len=10) "imported 0" } Test: FuzzWalkS3 === NAME FAIL exit status 1 FAIL github.com/treeverse/lakefs/pkg/local 0.038s ``` Note that Go only finds a _first_ bug - but at least it tries to minimize it. * Add sorted queue * CR fixes * CR Fixes last --------- Co-authored-by: Ariel Shaqed (Scolnicov) <[email protected]>
- Loading branch information
1 parent
65918ac
commit 5630d85
Showing
7 changed files
with
285 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package local | ||
|
||
// A StringHeap is a min-heap of strings | ||
type StringHeap []string | ||
|
||
func (pq *StringHeap) Len() int { return len(*pq) } | ||
|
||
func (pq *StringHeap) Less(i, j int) bool { | ||
// We want Pop to give us the smallest string | ||
return (*pq)[i] < (*pq)[j] | ||
} | ||
|
||
func (pq *StringHeap) Swap(i, j int) { | ||
(*pq)[i], (*pq)[j] = (*pq)[j], (*pq)[i] | ||
} | ||
|
||
func (pq *StringHeap) Push(x any) { | ||
*pq = append(*pq, x.(string)) | ||
} | ||
|
||
func (pq *StringHeap) Pop() any { | ||
old := *pq | ||
n := len(old) | ||
x := old[n-1] | ||
*pq = old[0 : n-1] | ||
return x | ||
} | ||
|
||
// Peek - according to heap documentation (https://pkg.go.dev/container/heap) "The minimum element in the tree is the root, at index 0." | ||
func (pq *StringHeap) Peek() any { | ||
x := (*pq)[0] | ||
return x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package local_test | ||
|
||
import ( | ||
"container/heap" | ||
"fmt" | ||
"sort" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/treeverse/lakefs/pkg/local" | ||
) | ||
|
||
func TestStringHeap(t *testing.T) { | ||
// Some items and their priorities. | ||
items := []string{"imported/0000/1", "imported../00000", "imported/00010/1"} | ||
|
||
// Create a priority queue, put the items in it, and | ||
// establish the priority queue (heap) invariants. | ||
pq := local.StringHeap{} | ||
heap.Init(&pq) | ||
|
||
for _, item := range items { | ||
heap.Push(&pq, item) | ||
} | ||
|
||
// Insert a new item and then modify its priority. | ||
items = append(items, "imported./0000/1") | ||
heap.Push(&pq, "imported./0000/1") | ||
|
||
// Take the items out; they arrive in decreasing priority order. | ||
sort.Strings(items) | ||
fmt.Println(items) | ||
i := 0 | ||
for pq.Len() > 0 { | ||
item := heap.Pop(&pq).(string) | ||
require.Equal(t, items[i], item) | ||
i++ | ||
} | ||
} |
Oops, something went wrong.