[TrueCloudLab/hrw#2] sdk-go: Use typed HRW methods

Update HRW pkg and use typed HRW methods to sort nodes

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-02-28 14:04:02 +03:00 committed by fyrchik
parent e355e5eeba
commit 2cbc585edd
5 changed files with 8 additions and 6 deletions

2
go.mod
View file

@ -5,7 +5,7 @@ go 1.18
require (
github.com/TrueCloudLab/frostfs-api-go/v2 v2.0.0-20221212144048-1351b6656d68
github.com/TrueCloudLab/frostfs-contract v0.0.0-20221213081248-6c805c1b4e42
github.com/TrueCloudLab/hrw v1.1.0
github.com/TrueCloudLab/hrw v1.1.1-0.20230227111858-79b208bebf52
github.com/TrueCloudLab/tzhash v1.7.0
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12
github.com/google/uuid v1.3.0

2
go.sum
View file

@ -45,6 +45,8 @@ github.com/TrueCloudLab/frostfs-crypto v0.5.0 h1:ZoLjixSkQv3j1EwZ1WJzMEJY2NR+9nO
github.com/TrueCloudLab/frostfs-crypto v0.5.0/go.mod h1:775MUewpH8AWpXrimAG2NYWOXB6lpKOI5kqgu+eI5zs=
github.com/TrueCloudLab/hrw v1.1.0 h1:2U69PpUX1UtMWgh/RAg6D8mQW+/WsxbLNE+19EUhLhY=
github.com/TrueCloudLab/hrw v1.1.0/go.mod h1:Pzi8Hy3qx12cew+ajVxgbtDVM4sRG9/gJnJLcL/yRyY=
github.com/TrueCloudLab/hrw v1.1.1-0.20230227111858-79b208bebf52 h1:fBeG0EkL7Pa2D0SIiZt3yQYGpP/IvrXg4xEPAZ4Jjys=
github.com/TrueCloudLab/hrw v1.1.1-0.20230227111858-79b208bebf52/go.mod h1:BG6NztCuNc0UFr6MWJ4MM1sUl9lxx6PBRwLmTxdre20=
github.com/TrueCloudLab/rfc6979 v0.3.0 h1:0SYMAfQWh/TjnofqYQHy+s3rmQ5gi0fvOaDbqd60/Ic=
github.com/TrueCloudLab/rfc6979 v0.3.0/go.mod h1:qylxFXFQ/sMvpZC/8JyWp+mfzk5Zj/KDT5FAbekhobc=
github.com/TrueCloudLab/tzhash v1.7.0 h1:btGORepc7Dg+n4MxgJxv73c9eYhwSBI5HqsqUBRmJiw=

View file

@ -152,7 +152,7 @@ func (m NetMap) PlacementVectors(vectors [][]NodeInfo, pivot []byte) ([][]NodeIn
for i := range vectors {
result[i] = make([]NodeInfo, len(vectors[i]))
copy(result[i], vectors[i])
hrw.SortSliceByWeightValue(result[i], nodes(result[i]).weights(wf), h)
hrw.SortHasherSliceByWeightValue(result[i], nodes(result[i]).weights(wf), h)
}
return result, nil

View file

@ -108,7 +108,7 @@ func (c *context) getSelection(p PlacementPolicy, s netmap.Selector) ([]nodes, e
weights[i] = calcBucketWeight(res[i], newMeanIQRAgg(), c.weightFunc)
}
hrw.SortSliceByWeightValue(res, weights, c.hrwSeedHash)
hrw.SortHasherSliceByWeightValue(res, weights, c.hrwSeedHash)
}
if s.GetAttribute() == "" {
@ -164,7 +164,7 @@ func (c *context) getSelectionBase(subnetID subnetid.ID, s netmap.Selector) []no
if len(c.hrwSeed) != 0 {
for i := range result {
hrw.SortSliceByWeightValue(result[i].nodes, result[i].nodes.weights(c.weightFunc), c.hrwSeedHash)
hrw.SortHasherSliceByWeightValue(result[i].nodes, result[i].nodes.weights(c.weightFunc), c.hrwSeedHash)
}
}

View file

@ -50,7 +50,7 @@ func BenchmarkHRWSort(b *testing.B) {
copy(realNodes, vectors)
b.StartTimer()
hrw.SortSliceByValue(realNodes, pivot)
hrw.SortHasherSliceByValue(realNodes, pivot)
}
})
b.Run("only sort by index", func(b *testing.B) {
@ -72,7 +72,7 @@ func BenchmarkHRWSort(b *testing.B) {
copy(realNodes, vectors)
b.StartTimer()
hrw.SortSliceByWeightValue(realNodes, weights, pivot)
hrw.SortHasherSliceByWeightValue(realNodes, weights, pivot)
}
})
b.Run("sort by ID, then by index (deterministic)", func(b *testing.B) {