This is an automated email from the ASF dual-hosted git repository.
zhangyifan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new acabee5 [java] fix bug in getClosestServerInfo code
acabee5 is described below
commit acabee5514573475aa944492dd763b219a3f0d60
Author: zhangyifan27 <[email protected]>
AuthorDate: Mon Mar 16 13:35:59 2020 +0800
[java] fix bug in getClosestServerInfo code
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
---
.../src/main/java/org/apache/kudu/client/RemoteTablet.java | 3 +++
.../test/java/org/apache/kudu/client/TestRemoteTablet.java | 13 +++++++++++++
2 files changed, 16 insertions(+)
diff --git
a/java/kudu-client/src/main/java/org/apache/kudu/client/RemoteTablet.java
b/java/kudu-client/src/main/java/org/apache/kudu/client/RemoteTablet.java
index 5ed424f..e330a6e 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/RemoteTablet.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/RemoteTablet.java
@@ -196,6 +196,9 @@ public class RemoteTablet implements
Comparable<RemoteTablet> {
// 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<>();
diff --git
a/java/kudu-client/src/test/java/org/apache/kudu/client/TestRemoteTablet.java
b/java/kudu-client/src/test/java/org/apache/kudu/client/TestRemoteTablet.java
index 44d652a..f793e41 100644
---
a/java/kudu-client/src/test/java/org/apache/kudu/client/TestRemoteTablet.java
+++
b/java/kudu-client/src/test/java/org/apache/kudu/client/TestRemoteTablet.java
@@ -147,6 +147,19 @@ public class TestRemoteTablet {
}
@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() {
{
RemoteTablet tablet = getTablet(0, 1, 2);