WIP: Fix infinite sort RPC #1068

Closed
alexvanin wants to merge 3 commits from alexvanin/frostfs-node:fix/infinite-forest-sort into master
2 changed files with 17 additions and 3 deletions

View file

@ -1073,8 +1073,9 @@ func (t *boltForest) TreeSortedByFilename(ctx context.Context, cid cidSDK.ID, tr
return bytes.Compare(result[i].Meta.GetAttr(AttributeFilename), result[j].Meta.GetAttr(AttributeFilename)) == -1 return bytes.Compare(result[i].Meta.GetAttr(AttributeFilename), result[j].Meta.GetAttr(AttributeFilename)) == -1
}) })
for i := range result { for i := range result {
if bytes.Compare([]byte(last), result[i].Meta.GetAttr(AttributeFilename)) == -1 { if cmp := bytes.Compare([]byte(last), result[i].Meta.GetAttr(AttributeFilename)); cmp <= 0 {
result = result[i:] // if last == result[i], return next [i+1:] values; if last < result[i], return all values from [i:]
result = result[i+cmp+1:]
break break
} }
} }

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"path" "path"
"path/filepath"
"sort" "sort"
"testing" "testing"
@ -123,9 +124,21 @@ func TestGetSubTree(t *testing.T) {
} }
func TestGetSubTreeOrderAsc(t *testing.T) { func TestGetSubTreeOrderAsc(t *testing.T) {
t.Run("memory forest", func(t *testing.T) {
testGetSubTreeOrderAsc(t, pilorama.NewMemoryForest())
})
t.Run("boltdb forest", func(t *testing.T) {
p := pilorama.NewBoltForest(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama")))
require.NoError(t, p.Open(context.Background(), 0644))
require.NoError(t, p.Init())
testGetSubTreeOrderAsc(t, p)
})
}
func testGetSubTreeOrderAsc(t *testing.T, p pilorama.ForestStorage) {
d := pilorama.CIDDescriptor{CID: cidtest.ID(), Size: 1} d := pilorama.CIDDescriptor{CID: cidtest.ID(), Size: 1}
treeID := "sometree" treeID := "sometree"
p := pilorama.NewMemoryForest()
tree := []struct { tree := []struct {
path []string path []string