Skip to content

Commit

Permalink
kvserver: annotate rebalance ctx with objective
Browse files Browse the repository at this point in the history
Previously, the easiest method of determining the current rebalance
objective from logs was to view the cluster setting and check for
logging indicating a mixed version cluster - this was cumbersome.

This commit annotates the ctx in the store rebalancer loop with an
additional tag: `obj`. The `obj` tag indicates the current rebalance
objective, either `cpu` or `qps` currently.

resolves: cockroachdb#102812

Release note: None
  • Loading branch information
kvoli committed May 5, 2023
1 parent 071876a commit 8da1cea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/kv/kvserver/rebalance_objective.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ const (
LBRebalancingCPU
)

// LoadBasedRebalancingObjectiveMap maps the LoadBasedRebalancingObjective enum
// value to a string.
var LoadBasedRebalancingObjectiveMap map[int64]string = map[int64]string{
int64(LBRebalancingQueries): "qps",
int64(LBRebalancingCPU): "cpu",
}

func (lbro LBRebalancingObjective) String() string {
return LoadBasedRebalancingObjectiveMap[int64(lbro)]
}

// LoadBasedRebalancingObjective is a cluster setting that defines the load
// balancing objective of the cluster.
var LoadBasedRebalancingObjective = settings.RegisterEnumSetting(
Expand All @@ -101,10 +112,7 @@ var LoadBasedRebalancingObjective = settings.RegisterEnumSetting(
"the cluster will attempt to balance qps among stores, if set to "+
"`cpu` the cluster will attempt to balance cpu usage among stores",
"cpu",
map[int64]string{
int64(LBRebalancingQueries): "qps",
int64(LBRebalancingCPU): "cpu",
},
LoadBasedRebalancingObjectiveMap,
).WithPublic()

// ToDimension returns the equivalent allocator load dimension of a rebalancing
Expand Down
3 changes: 3 additions & 0 deletions pkg/kv/kvserver/store_rebalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ func (sr *StoreRebalancer) Start(ctx context.Context, stopper *stop.Stopper) {
continue
}
objective := sr.RebalanceObjective()
sr.AddLogTag("obj", objective)
ctx = sr.AnnotateCtx(ctx)

hottestRanges := sr.replicaRankings.TopLoad(objective.ToDimension())
options := sr.scorerOptions(ctx, objective.ToDimension())
rctx := sr.NewRebalanceContext(ctx, options, hottestRanges, mode)
Expand Down

0 comments on commit 8da1cea

Please sign in to comment.