Skip to content

Commit

Permalink
Don't throw error when updateStatus has not run yet
Browse files Browse the repository at this point in the history
When Manager.StatusThread.updateStatus has not run yet, then
the set of current tablet server information will be empty.
  • Loading branch information
dlmarion committed Oct 27, 2023
1 parent 759b5d5 commit 40b41d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@
import org.apache.accumulo.core.spi.balancer.TabletBalancer;
import org.apache.accumulo.core.spi.balancer.data.TServerStatus;
import org.apache.accumulo.core.spi.balancer.data.TabletServerId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AssignmentParamsImpl implements TabletBalancer.AssignmentParameters {

private static final Logger LOG = LoggerFactory.getLogger(AssignmentParamsImpl.class);

private final SortedMap<TabletServerId,TServerStatus> currentStatus;
private final Map<TabletId,TabletServerId> unassigned;
private final Map<TabletId,TabletServerId> assignmentsOut;
Expand All @@ -50,16 +55,23 @@ public static AssignmentParamsImpl fromThrift(
Map<KeyExtent,TServerInstance> unassigned, Map<KeyExtent,TServerInstance> assignmentsOut) {

SortedMap<TabletServerId,TServerStatus> currentStatusNew = new TreeMap<>();
currentStatus.forEach((tsi, status) -> currentStatusNew.put(new TabletServerIdImpl(tsi),
TServerStatusImpl.fromThrift(status)));

Map<String,Set<TabletServerId>> tserverGroups = new HashMap<>();
currentTServerGrouping.forEach((k, v) -> {
currentTServerGrouping.forEach((group, serversInGroup) -> {
Set<TabletServerId> servers = new HashSet<>();
v.forEach(tsi -> servers.add(TabletServerIdImpl.fromThrift(tsi)));
tserverGroups.put(k, servers);
serversInGroup.forEach(tsi -> {
TabletServerIdImpl id = TabletServerIdImpl.fromThrift(tsi);
if (currentStatus.containsKey(tsi)) {
currentStatusNew.put(id, TServerStatusImpl.fromThrift(currentStatus.get(tsi)));
servers.add(id);
} else {
LOG.debug("Dropping tserver {} from group as it's not in set of all servers", id, group);
}
});
tserverGroups.put(group, servers);
});

LOG.debug("TServer groups for balancer assignment: {}", tserverGroups);

Map<TabletId,TabletServerId> unassignedNew = new HashMap<>();
unassigned.forEach(
(ke, tsi) -> unassignedNew.put(new TabletIdImpl(ke), TabletServerIdImpl.fromThrift(tsi)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ private static TableId busiest(Map<String,TableStatistics> tables) {

@Override
public void getAssignments(AssignmentParameters params) {
if (params.currentStatus().isEmpty()) {
log.debug("No known TabletServers, skipping tablet assignment for now.");
return;
}
params.unassignedTablets().forEach((tabletId, tserverId) -> params.addAssignment(tabletId,
getAssignment(params.currentStatus(), tserverId)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ private SortedMap<TabletServerId,TServerStatus> getCurrentSetForTable(
tserversInGroup.forEach(tsid -> {
TServerStatus tss = allTServers.get(tsid);
if (tss == null) {
throw new IllegalStateException("TabletServer " + tsid + " in " + groupNameInUse
+ " TabletServer group, but not in set of all TabletServers");
log.warn(
"Excluding TabletServer {} from group {} because TabletServerStatus is null, likely that Manager.StatusThread.updateStatus has not discovered it yet.",
tsid, groupNameInUse);
} else {
group.put(tsid, tss);
}
group.put(tsid, tss);
});
return group;
}
Expand Down

0 comments on commit 40b41d1

Please sign in to comment.