Skip to content

Commit 26a4c09

Browse files
committed
filter on table ids in SimpleLoadBalancer
1 parent 61c38ea commit 26a4c09

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

core/src/main/java/org/apache/accumulo/core/spi/balancer/SimpleLoadBalancer.java

+22-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.ArrayList;
2525
import java.util.Collections;
2626
import java.util.HashMap;
27+
import java.util.HashSet;
2728
import java.util.Iterator;
2829
import java.util.List;
2930
import java.util.Map;
@@ -151,6 +152,7 @@ public int compareTo(ServerCounts obj) {
151152
}
152153

153154
public boolean getMigrations(BalanceParameters params) {
155+
Set<TableId> tableIdsToBalance = new HashSet<>(params.getTablesToBalance().values());
154156
List<TabletMigration> resultingMigrations = new ArrayList<>();
155157
boolean moreBalancingNeeded = false;
156158
try {
@@ -171,10 +173,8 @@ public boolean getMigrations(BalanceParameters params) {
171173
* The check below was on entry.getKey(), but that resolves to a tabletserver not a
172174
* tablename. Believe it should be e.getKey() which is a tablename
173175
*/
174-
for (TableId tableId : params.getTablesToBalance().values()) {
175-
if (tableId.canonical().equals(e.getKey())) {
176-
serverTotal += e.getValue().getOnlineTabletCount();
177-
}
176+
if (tableIdsToBalance.contains(TableId.of(e.getKey()))) {
177+
serverTotal += e.getValue().getOnlineTabletCount();
178178
}
179179
}
180180
}
@@ -209,11 +209,13 @@ public boolean getMigrations(BalanceParameters params) {
209209
break;
210210
}
211211
if (needToUnload >= needToLoad) {
212-
resultingMigrations.addAll(move(tooMany, tooLittle, needToLoad, donerTabletStats));
212+
resultingMigrations
213+
.addAll(move(tooMany, tooLittle, needToLoad, donerTabletStats, tableIdsToBalance));
213214
end--;
214215
movedAlready = 0;
215216
} else {
216-
resultingMigrations.addAll(move(tooMany, tooLittle, needToUnload, donerTabletStats));
217+
resultingMigrations
218+
.addAll(move(tooMany, tooLittle, needToUnload, donerTabletStats, tableIdsToBalance));
217219
movedAlready += needToUnload;
218220
}
219221
if (needToUnload > needToLoad) {
@@ -236,16 +238,17 @@ public boolean getMigrations(BalanceParameters params) {
236238
* busiest table
237239
*/
238240
List<TabletMigration> move(ServerCounts tooMuch, ServerCounts tooLittle, int count,
239-
Map<TableId,Map<TabletId,TabletStatistics>> donerTabletStats) {
241+
Map<TableId,Map<TabletId,TabletStatistics>> donerTabletStats,
242+
Set<TableId> tableIdsToBalance) {
240243

241244
if (count == 0) {
242245
return Collections.emptyList();
243246
}
244247

245248
List<TabletMigration> result = new ArrayList<>();
246249
// Copy counts so we can update them as we propose migrations
247-
Map<TableId,Integer> tooMuchMap = tabletCountsPerTable(tooMuch.status);
248-
Map<TableId,Integer> tooLittleMap = tabletCountsPerTable(tooLittle.status);
250+
Map<TableId,Integer> tooMuchMap = tabletCountsPerTable(tooMuch.status, tableIdsToBalance);
251+
Map<TableId,Integer> tooLittleMap = tabletCountsPerTable(tooLittle.status, tableIdsToBalance);
249252

250253
for (int i = 0; i < count; i++) {
251254
TableId table = getTableToMigrate(tooMuch, tooMuchMap, tooLittleMap);
@@ -291,6 +294,10 @@ List<TabletMigration> move(ServerCounts tooMuch, ServerCounts tooLittle, int cou
291294
private TableId getTableToMigrate(ServerCounts tooMuch, Map<TableId,Integer> tooMuchMap,
292295
Map<TableId,Integer> tooLittleMap) {
293296

297+
if (tooMuchMap.size() == 1) {
298+
return tooMuchMap.keySet().iterator().next();
299+
}
300+
294301
// find a table to migrate
295302
// look for an uneven table count
296303
Entry<TableId,Integer> biggestEntry = tooMuchMap.entrySet().stream().map(entry -> {
@@ -312,12 +319,16 @@ protected List<TabletStatistics> getOnlineTabletsForTable(TabletServerId tabletS
312319
return environment.listOnlineTabletsForTable(tabletServerId, tableId);
313320
}
314321

315-
static Map<TableId,Integer> tabletCountsPerTable(TServerStatus status) {
322+
static Map<TableId,Integer> tabletCountsPerTable(TServerStatus status,
323+
Set<TableId> tableIdsToBalance) {
316324
Map<TableId,Integer> result = new HashMap<>();
317325
if (status != null && status.getTableMap() != null) {
318326
Map<String,TableStatistics> tableMap = status.getTableMap();
319327
for (Entry<String,TableStatistics> entry : tableMap.entrySet()) {
320-
result.put(TableId.of(entry.getKey()), entry.getValue().getOnlineTabletCount());
328+
var tableId = TableId.of(entry.getKey());
329+
if (tableIdsToBalance.contains(tableId)) {
330+
result.put(tableId, entry.getValue().getOnlineTabletCount());
331+
}
321332
}
322333
}
323334
return result;

0 commit comments

Comments
 (0)