diff --git a/netmap/json_test.go b/netmap/json_test.go index b8749d998..323c2be7a 100644 --- a/netmap/json_test.go +++ b/netmap/json_test.go @@ -6,6 +6,7 @@ import ( "path/filepath" "testing" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/stretchr/testify/require" ) @@ -62,7 +63,10 @@ func TestPlacementPolicy_Interopability(t *testing.T) { for name, tt := range tc.Tests { t.Run(name, func(t *testing.T) { - v, err := nm.ContainerNodes(tt.Policy, tt.Pivot) + var pivot cid.ID + copy(pivot[:], tt.Pivot) + + v, err := nm.ContainerNodes(tt.Policy, pivot) if tt.Result == nil { require.Error(t, err) require.Contains(t, err.Error(), tt.Error) @@ -108,11 +112,14 @@ func BenchmarkPlacementPolicyInteropability(b *testing.B) { for name, tt := range tc.Tests { b.Run(name, func(b *testing.B) { + var pivot cid.ID + copy(pivot[:], tt.Pivot) + b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { b.StartTimer() - v, err := nm.ContainerNodes(tt.Policy, tt.Pivot) + v, err := nm.ContainerNodes(tt.Policy, pivot) b.StopTimer() if tt.Result == nil { require.Error(b, err) @@ -150,11 +157,14 @@ func BenchmarkManySelects(b *testing.B) { var nm NetMap nm.SetNodes(tc.Nodes) + var pivot cid.ID + copy(pivot[:], tt.Pivot) + b.ResetTimer() b.ReportAllocs() for i := 0; i < b.N; i++ { - _, err = nm.ContainerNodes(tt.Policy, tt.Pivot) + _, err = nm.ContainerNodes(tt.Policy, pivot) if err != nil { b.FailNow() } diff --git a/netmap/json_tests/many_selects.json b/netmap/json_tests/many_selects.json index f0bb8a2bb..e49b4d800 100644 --- a/netmap/json_tests/many_selects.json +++ b/netmap/json_tests/many_selects.json @@ -183,9 +183,9 @@ "policy": {"replicas":[{"count":1,"selector":"SameRU"},{"count":1,"selector":"DistinctRU"},{"count":1,"selector":"Good"},{"count":1,"selector":"Main"}],"containerBackupFactor":2,"selectors":[{"name":"SameRU","count":2,"clause":"SAME","attribute":"City","filter":"FromRU"},{"name":"DistinctRU","count":2,"clause":"DISTINCT","attribute":"City","filter":"FromRU"},{"name":"Good","count":2,"clause":"DISTINCT","attribute":"Country","filter":"Good"},{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[{"name":"FromRU","key":"Country","op":"EQ","value":"Russia"},{"name":"Good","key":"Rating","op":"GE","value":"4"}]}, "result": [ [0, 5, 9, 10], - [2, 6, 0, 5], + [0, 5, 2, 6], [1, 8, 2, 5], - [3, 4, 1, 7, 0, 2] + [0, 2, 1, 7, 3, 4] ] } } diff --git a/netmap/json_tests/multiple_rep_asymmetric.json b/netmap/json_tests/multiple_rep_asymmetric.json index 0e6e79645..303231aaa 100644 --- a/netmap/json_tests/multiple_rep_asymmetric.json +++ b/netmap/json_tests/multiple_rep_asymmetric.json @@ -321,10 +321,10 @@ 4 ], [ - 8, - 12, 5, - 10 + 10, + 8, + 12 ] ] } diff --git a/netmap/netmap.go b/netmap/netmap.go index 3d312db5e..159c95794 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/hrw" "github.com/nspcc-dev/neofs-api-go/v2/netmap" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" ) // NetMap represents NeoFS network map. It includes information about all @@ -166,11 +167,14 @@ func (m NetMap) PlacementVectors(vectors [][]NodeInfo, pivot []byte) ([][]NodeIn // the fixed NetMap and parameters. // // Result can be used in PlacementVectors. -func (m NetMap) ContainerNodes(p PlacementPolicy, pivot []byte) ([][]NodeInfo, error) { +func (m NetMap) ContainerNodes(p PlacementPolicy, containerID cid.ID) ([][]NodeInfo, error) { c := newContext(m) - c.setPivot(pivot) c.setCBF(p.backupFactor) + var pivot []byte + containerID.Encode(pivot) + c.setPivot(pivot) + if err := c.processFilters(p); err != nil { return nil, err } diff --git a/netmap/selector_test.go b/netmap/selector_test.go index 7f31e499d..3cdc4f018 100644 --- a/netmap/selector_test.go +++ b/netmap/selector_test.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/hrw" "github.com/nspcc-dev/neofs-api-go/v2/netmap" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/stretchr/testify/require" ) @@ -129,7 +130,7 @@ func BenchmarkPolicyHRWType(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - _, err := nm.ContainerNodes(p, []byte{1}) + _, err := nm.ContainerNodes(p, cid.ID{1}) if err != nil { b.Fatal() } @@ -173,7 +174,7 @@ func TestPlacementPolicy_DeterministicOrder(t *testing.T) { nm.SetNodes(nodeList) getIndices := func(t *testing.T) (uint64, uint64) { - v, err := nm.ContainerNodes(p, []byte{1}) + v, err := nm.ContainerNodes(p, cid.ID{1}) require.NoError(t, err) nss := make([]nodes, len(v))