@@ -13,8 +13,9 @@ import (
1313)
1414
1515// MMARebalanceAdvisor contains information that mma needs to determine if a
16- // candidate is in conflict with its goals. All fields should be immutable after
17- // its initialization.
16+ // candidate is in conflict with its goals. The caller should not access/change
17+ // its internal fields after creation and should use IsInConflictWithMMA
18+ // instead.
1819//
1920// MMARebalanceAdvisor uses the meansLoad summary to compute the load summary
2021// for a provided candidate. Then it compares the candidate load summary against
@@ -47,11 +48,32 @@ func NoopMMARebalanceAdvisor() *MMARebalanceAdvisor {
4748
4849// BuildMMARebalanceAdvisor constructs an MMARebalanceAdvisor for the given
4950// existing store and candidate stores. The advisor can be used to determine if
50- // a candidate is in conflict with the existing store via IsInConflictWithMMA.
51- // The provided cands list may or may not include the existing store. This
52- // method always adds the existing store to the cands list so that it is
53- // included in the mean calculation. It is up to computeMeansForStoreSet to
54- // handle the de-duplication of storeIDs from the cands list.
51+ // a candidate is vetoed by the multi-metric allocator due to running counter to
52+ // its goals. Currently, it is considered counter to its goal if the candidate
53+ // is more overloaded than the existing store with respect to the cands list.
54+ //
55+ // The provided cands list may or may not include the existing store. For the
56+ // replicate queue, the cands list is just the set of candidate stores for the
57+ // equivalence class, excluding the existing store. For the lease queue, the
58+ // cands list includes all stores that satisfy the constraint including the
59+ // existing store.
60+ //
61+ // This method always adds the existing store to the cands list to ensure it is
62+ // included in the mean calculation. This is subject to change, but currently it
63+ // does not make sense to compute the load summary of the existing store with
64+ // respect to the cands list that does not include the existing store itself.
65+ // Alternatively, we could require the cands list to be exactly the same as the
66+ // set of stores used to compute the means for lease / range count. The existing
67+ // store should be included for the lease queue but excluded for the replicate
68+ // queue. Note that since this method always adds the existing store to the
69+ // list, and the provided cands may or may not already include the existing
70+ // store, the cands slice passed to computeMeansForStoreSet may contain
71+ // duplicate storeIDs. It is up to computeMeansForStoreSet to handle
72+ // de-duplication of storeIDs from the cands list.
73+ //
74+ // The returned advisor should be passed to IsInConflictWithMMA as a helper to
75+ // determine if a candidate is vetoed by the multi-metric allocator due to
76+ // running counter to its goals.
5577func (a * allocatorState ) BuildMMARebalanceAdvisor (
5678 existing roachpb.StoreID , cands []roachpb.StoreID ,
5779) * MMARebalanceAdvisor {
@@ -70,8 +92,12 @@ func (a *allocatorState) BuildMMARebalanceAdvisor(
7092// IsInConflictWithMMA determines if the given candidate is in conflict with the
7193// existing store using the provided MMARebalanceAdvisor. For simplicity, we
7294// currently say that this is in conflict if the candidate is more overloaded
73- // than the existing store. This is subject to change in the future. Caller is
74- // responsible for making sure the MMARebalanceAdvisor is for the correct
95+ // than the existing store. This is subject to change in the future. When
96+ // cpuOnly is true, the candidate store's cpu load summary must not exceed that
97+ // of the existing store, or the operation is considered in conflict. When
98+ // cpuOnly is false, the worst dimension's summary is compared instead.
99+ //
100+ // Caller is responsible for making sure the MMARebalanceAdvisor is for the correct
75101// existing store and candidate set.
76102func (a * allocatorState ) IsInConflictWithMMA (
77103 ctx context.Context , cand roachpb.StoreID , advisor * MMARebalanceAdvisor , cpuOnly bool ,
@@ -88,13 +114,14 @@ func (a *allocatorState) IsInConflictWithMMA(
88114 // Always compute the candidate's load summary.
89115 candSLS := a .cs .computeLoadSummary (ctx , cand , & advisor .means .storeLoad , & advisor .means .nodeLoad )
90116
117+ // TODO(wenyihu6): unify the branches below by assigning based on sls.worstDim and cpuOnly.
91118 var conflict bool
92119 if cpuOnly {
93120 conflict = candSLS .dimSummary [CPURate ] > existingSLS .dimSummary [CPURate ]
94121 if conflict {
95122 log .KvDistribution .VEventf (
96123 ctx , 2 ,
97- "mma rejected candidate s%d(cpu-only) as a replacement for s%d: candidate=%v > existing=%v" ,
124+ "mma rejected candidate s%d(cpu-only) as a replacement for s%d: candidate=%v(cpu) > existing=%v(cpu) " ,
98125 cand , advisor .existingStoreID , candSLS .dimSummary [CPURate ], existingSLS .dimSummary [CPURate ],
99126 )
100127 }
@@ -103,8 +130,8 @@ func (a *allocatorState) IsInConflictWithMMA(
103130 if conflict {
104131 log .KvDistribution .VEventf (
105132 ctx , 2 ,
106- "mma rejected candidate s%d as a replacement for s%d: candidate=%v > existing=%v" ,
107- cand , advisor .existingStoreID , candSLS .sls , existingSLS .sls ,
133+ "mma rejected candidate s%d as a replacement for s%d: candidate=%v(%v) > existing=%v(%v) " ,
134+ cand , advisor .existingStoreID , candSLS .sls , candSLS . worstDim , existingSLS .sls , existingSLS . worstDim ,
108135 )
109136 }
110137 }
0 commit comments