Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: use FastIntMap for QueryState.RangesPerNode #74343

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/sql/physicalplan/replicaoracle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"//pkg/rpc",
"//pkg/settings/cluster",
"//pkg/sql/sqlerrors",
"//pkg/util",
"@com_github_cockroachdb_errors//:errors",
],
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/physicalplan/replicaoracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/rpc"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/sqlerrors"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/errors"
)

Expand Down Expand Up @@ -106,14 +107,13 @@ var oracleFactories = map[Policy]OracleFactory{}
// QueryState encapsulates the history of assignments of ranges to nodes
// done by an oracle on behalf of one particular query.
type QueryState struct {
RangesPerNode map[roachpb.NodeID]int
RangesPerNode util.FastIntMap
AssignedRanges map[roachpb.RangeID]roachpb.ReplicaDescriptor
}

// MakeQueryState creates an initialized QueryState.
func MakeQueryState() QueryState {
return QueryState{
RangesPerNode: make(map[roachpb.NodeID]int),
AssignedRanges: make(map[roachpb.RangeID]roachpb.ReplicaDescriptor),
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func (o *binPackingOracle) ChoosePreferredReplica(
minLoad := int(math.MaxInt32)
var leastLoadedIdx int
for i, repl := range replicas {
assignedRanges := queryState.RangesPerNode[repl.NodeID]
assignedRanges := queryState.RangesPerNode.GetDefault(int(repl.NodeID))
if assignedRanges != 0 && assignedRanges < o.maxPreferredRangesPerLeaseHolder {
return repl.ReplicaDescriptor, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/physicalplan/span_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ func (it *spanResolverIterator) ReplicaInfo(
if err != nil {
return roachpb.ReplicaDescriptor{}, err
}
it.queryState.RangesPerNode[repl.NodeID]++
prev := it.queryState.RangesPerNode.GetDefault(int(repl.NodeID))
it.queryState.RangesPerNode.Set(int(repl.NodeID), prev+1)
it.queryState.AssignedRanges[rngID] = repl
return repl, nil
}