Skip to content

Commit 4edd4cd

Browse files
committed
updated rebalance parameter output for automatic tolerance selection
1 parent 37b3fdf commit 4edd4cd

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

cmd/topicmappr/commands/rebalance.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func rebalance(cmd *cobra.Command, _ []string) {
8888
// of rebalance plans. A rebalanceResults holds
8989
// any relevant output along with metadata that
9090
// hints at the quality of the output, such as
91-
// the resulting storage utlization range.
91+
// the resulting storage utilization range.
9292
type rebalanceResults struct {
9393
storageRange float64
9494
tolerance float64
@@ -107,7 +107,7 @@ func rebalance(cmd *cobra.Command, _ []string) {
107107
tolFlag, _ := cmd.Flags().GetFloat64("tolerance")
108108
var tol float64
109109

110-
if tolFlag != 0.00 {
110+
if tolFlag == 0.00 {
111111
tol = i
112112
} else {
113113
tol = tolFlag
@@ -155,7 +155,7 @@ func rebalance(cmd *cobra.Command, _ []string) {
155155
// Populate the output.
156156
resultsByRange = append(resultsByRange, rebalanceResults{
157157
storageRange: params.brokers.StorageRange(),
158-
tolerance: i,
158+
tolerance: tol,
159159
partitionMap: partitionMap,
160160
relocations: params.relos,
161161
brokers: params.brokers,
@@ -167,18 +167,17 @@ func rebalance(cmd *cobra.Command, _ []string) {
167167
}
168168
}
169169

170+
// Sort the rebalance results by range ascending.
170171
sort.Slice(resultsByRange, func(i, j int) bool {
171172
return resultsByRange[i].storageRange < resultsByRange[j].storageRange
172173
})
173174

175+
// Chose the results with the lowest range.
174176
m := resultsByRange[0]
175177
partitionMap, relos, brokers := m.partitionMap, m.relocations, m.brokers
176178

177-
fmt.Printf("xxx using a tolerance of %f\n", m.tolerance)
178-
179-
for i := range resultsByRange {
180-
fmt.Printf("range for map %d: %f\n", i, resultsByRange[i].storageRange)
181-
}
179+
// Print parameters used for rebalance decisions.
180+
printRebalanceParams(cmd, brokersOrig, m.tolerance)
182181

183182
// Print planned relocations.
184183
printPlannedRelocations(offloadTargets, relos, partitionMeta)

cmd/topicmappr/commands/rebalance_steps.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,27 @@ func validateBrokersForRebalance(cmd *cobra.Command, brokers kafkazk.BrokerMap,
174174
}
175175
}
176176

177+
fmt.Printf("\n%s:\n", selectorMethod.String())
178+
179+
// Exit if no target brokers were found.
180+
if len(offloadTargets) == 0 {
181+
fmt.Printf("%s[none]\n", indent)
182+
os.Exit(0)
183+
} else {
184+
for _, id := range offloadTargets {
185+
fmt.Printf("%s%d\n", indent, id)
186+
}
187+
}
188+
189+
return offloadTargets
190+
}
191+
192+
func printRebalanceParams(cmd *cobra.Command, brokers kafkazk.BrokerMap, tol float64) {
177193
// Print rebalance parameters as a result of
178194
// input configurations and brokers found
179195
// to be beyond the storage threshold.
180196
fmt.Println("\nRebalance parameters:")
181197

182-
tol, _ := cmd.Flags().GetFloat64("tolerance")
183198
pst, _ := cmd.Flags().GetInt("partition-size-threshold")
184199
mean, hMean := brokers.Mean(), brokers.HMean()
185200

@@ -192,20 +207,6 @@ func validateBrokersForRebalance(cmd *cobra.Command, brokers kafkazk.BrokerMap,
192207

193208
fmt.Printf("%s%sSources limited to <= %.2fGB\n", indent, indent, mean*(1+tol)/div)
194209
fmt.Printf("%s%sDestinations limited to >= %.2fGB\n", indent, indent, mean*(1-tol)/div)
195-
196-
fmt.Printf("\n%s:\n", selectorMethod.String())
197-
198-
// Exit if no target brokers were found.
199-
if len(offloadTargets) == 0 {
200-
fmt.Printf("%s[none]\n", indent)
201-
os.Exit(0)
202-
} else {
203-
for _, id := range offloadTargets {
204-
fmt.Printf("%s%d\n", indent, id)
205-
}
206-
}
207-
208-
return offloadTargets
209210
}
210211

211212
func planRelocationsForBroker(cmd *cobra.Command, params planRelocationsForBrokerParams) int {

0 commit comments

Comments
 (0)