[SUPPORT] node: Keep order for equal elements when sort priority metrics #1530
2 changed files with 1 additions and 33 deletions
|
@ -1,15 +1,12 @@
|
||||||
package object
|
package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"cmp"
|
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
||||||
|
@ -507,7 +504,6 @@ func isObjectStoredOnNode(ctx context.Context, cmd *cobra.Command, cnrID cid.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPlacement(cmd *cobra.Command, objID oid.ID, objects []phyObject, result *objectNodesResult) {
|
func printPlacement(cmd *cobra.Command, objID oid.ID, objects []phyObject, result *objectNodesResult) {
|
||||||
normilizeObjectNodesResult(objects, result)
|
|
||||||
if json, _ := cmd.Flags().GetBool(commonflags.JSON); json {
|
if json, _ := cmd.Flags().GetBool(commonflags.JSON); json {
|
||||||
printObjectNodesAsJSON(cmd, objID, objects, result)
|
printObjectNodesAsJSON(cmd, objID, objects, result)
|
||||||
} else {
|
} else {
|
||||||
|
@ -515,34 +511,6 @@ func printPlacement(cmd *cobra.Command, objID oid.ID, objects []phyObject, resul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func normilizeObjectNodesResult(objects []phyObject, result *objectNodesResult) {
|
|
||||||
slices.SortFunc(objects, func(lhs, rhs phyObject) int {
|
|
||||||
if lhs.ecHeader == nil && rhs.ecHeader == nil {
|
|
||||||
return bytes.Compare(lhs.objectID[:], rhs.objectID[:])
|
|
||||||
}
|
|
||||||
if lhs.ecHeader == nil {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if rhs.ecHeader == nil {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if lhs.ecHeader.parent == rhs.ecHeader.parent {
|
|
||||||
return cmp.Compare(lhs.ecHeader.index, rhs.ecHeader.index)
|
|
||||||
}
|
|
||||||
return bytes.Compare(lhs.ecHeader.parent[:], rhs.ecHeader.parent[:])
|
|
||||||
})
|
|
||||||
for _, obj := range objects {
|
|
||||||
op := result.placements[obj.objectID]
|
|
||||||
slices.SortFunc(op.confirmedNodes, func(lhs, rhs netmapSDK.NodeInfo) int {
|
|
||||||
return bytes.Compare(lhs.PublicKey(), rhs.PublicKey())
|
|
||||||
})
|
|
||||||
slices.SortFunc(op.requiredNodes, func(lhs, rhs netmapSDK.NodeInfo) int {
|
|
||||||
return bytes.Compare(lhs.PublicKey(), rhs.PublicKey())
|
|
||||||
})
|
|
||||||
result.placements[obj.objectID] = op
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func printObjectNodesAsText(cmd *cobra.Command, objID oid.ID, objects []phyObject, result *objectNodesResult) {
|
func printObjectNodesAsText(cmd *cobra.Command, objID oid.ID, objects []phyObject, result *objectNodesResult) {
|
||||||
fmt.Fprintf(cmd.OutOrStdout(), "Object %s stores payload in %d data objects:\n", objID.EncodeToString(), len(objects))
|
fmt.Fprintf(cmd.OutOrStdout(), "Object %s stores payload in %d data objects:\n", objID.EncodeToString(), len(objects))
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,7 @@ func sortVector(cfg *cfg, unsortedVector []netmap.NodeInfo) ([]netmap.NodeInfo,
|
||||||
metrics: m,
|
metrics: m,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slices.SortFunc(nm, func(a, b nodeMetrics) int {
|
slices.SortStableFunc(nm, func(a, b nodeMetrics) int {
|
||||||
return slices.Compare(a.metrics, b.metrics)
|
return slices.Compare(a.metrics, b.metrics)
|
||||||
})
|
})
|
||||||
sortedVector := make([]netmap.NodeInfo, len(unsortedVector))
|
sortedVector := make([]netmap.NodeInfo, len(unsortedVector))
|
||||||
|
|
Loading…
Reference in a new issue