Skip to content

Commit

Permalink
[java] fix bug in getClosestServerInfo code
Browse files Browse the repository at this point in the history
When client handles tablet not found error, it removes the tablet server
from the RemoteTablet's locations. If all tablet servers are removed,
the code in getClosestServerInfo will throw a division by zero exception.
This patch fixed it and added a test to verify getClosestServerInfo
returns null when all locations of a tablet are invalid.

Change-Id: Ib4dc471b5044ea4b5bd6202ccd2a707d6e229ea0
Reviewed-on: http://gerrit.cloudera.org:8080/15444
Reviewed-by: Adar Dembo <[email protected]>
Tested-by: Kudu Jenkins
  • Loading branch information
zhangyifan27 committed Mar 16, 2020
1 parent c4e2561 commit acabee5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ ServerInfo getClosestServerInfo(String location) {
// TODO(wdberkeley): Eventually, the client might use the hierarchical
// structure of a location to determine proximity.
synchronized (tabletServers) {
if (tabletServers.isEmpty()) {
return null;
}
ServerInfo result = null;
List<ServerInfo> localServers = new ArrayList<>();
List<ServerInfo> serversInSameLocation = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ public void testNoLocalOrSameLocationReplica() {
assertNotNull(tablet.getClosestServerInfo(kClientLocation).getUuid());
}

@Test
public void testReplicaWithNoValidLocation() {
RemoteTablet tablet = getTablet(0, 1, 2);

// Test removing all tablet servers doesn't break.
for (String uuid : kUuids) {
assertTrue(tablet.removeTabletClient(uuid));
}
assertNull(tablet.getLeaderServerInfo());
assertNull(tablet.getClosestServerInfo(kNoLocation));
assertNull(tablet.getClosestServerInfo(kClientLocation));
}

@Test
public void testReplicaSelection() {
{
Expand Down

0 comments on commit acabee5

Please sign in to comment.