Skip to content

Commit 917a979

Browse files
committed
mmaprototype: make store iteration deterministic
We'll be producing more trace output into datadriven output shortly. Currently the one test case in TestClusterState that does this only considers one store, but once we add more test cases we will run into non-determinism. Avoid this problem.
1 parent 7123720 commit 917a979

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/kv/kvserver/allocator/mmaprototype/cluster_state_rebalance_stores.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,18 @@ func (re *rebalanceEnv) rebalanceStores(
147147
// fdDrain or fdDead, nor do we attempt to shed replicas from a store which
148148
// is storeMembershipRemoving (decommissioning). These are currently handled
149149
// via replicate_queue.go.
150-
for storeID, ss := range re.stores {
150+
151+
// Need deterministic order for datadriven testing.
152+
storeStateSlice := make([]*storeState, 0, len(re.stores))
153+
for _, ss := range re.stores {
154+
storeStateSlice = append(storeStateSlice, ss)
155+
}
156+
slices.SortFunc(storeStateSlice, func(a, b *storeState) int {
157+
return cmp.Compare(a.StoreID, b.StoreID)
158+
})
159+
160+
for _, ss := range storeStateSlice {
161+
storeID := ss.StoreID
151162
sls := re.meansMemo.getStoreLoadSummary(ctx, clusterMeans, storeID, ss.loadSeqNum)
152163
log.KvDistribution.VEventf(ctx, 2, "evaluating s%d: node load %s, store load %s, worst dim %s",
153164
storeID, sls.nls, sls.sls, sls.worstDim)

0 commit comments

Comments
 (0)