[java client] Rename NoLeaderMasterFoundException and reuse I pushed d87486c too fast, Dan convinced me to reuse the exception.
Change-Id: I51ad20943fe8b4b808123dc8b7795215f3b12308 Reviewed-on: http://gerrit.cloudera.org:8080/4624 Reviewed-by: Dan Burkert <[email protected]> Tested-by: Kudu Jenkins Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/f26ab7d5 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/f26ab7d5 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/f26ab7d5 Branch: refs/heads/master Commit: f26ab7d5c28979b2cda9860faac1039920fd7a15 Parents: 07ce9fb Author: Jean-Daniel Cryans <[email protected]> Authored: Tue Oct 4 16:30:54 2016 -0700 Committer: Jean-Daniel Cryans <[email protected]> Committed: Wed Oct 5 22:34:42 2016 +0000 ---------------------------------------------------------------------- .../org/apache/kudu/client/AsyncKuduClient.java | 2 +- .../client/GetMasterRegistrationReceived.java | 11 +++--- .../kudu/client/NoLeaderFoundException.java | 38 ++++++++++++++++++++ .../client/NoLeaderMasterFoundException.java | 37 ------------------- .../kudu/client/NoSuitableReplicaException.java | 32 ----------------- .../apache/kudu/client/TestAsyncKuduClient.java | 2 +- .../TestGetMasterRegistrationReceived.java | 4 +-- 7 files changed, 47 insertions(+), 79 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/f26ab7d5/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java index 0c0d9bb..cedd111 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java @@ -1410,7 +1410,7 @@ public class AsyncKuduClient implements AutoCloseable { // sleep before retrying. TableLocationsCache.Entry entry = locationsCache.get(requestPartitionKey); if (!entry.isNonCoveredRange() && clientFor(entry.getTablet()) == null) { - throw new NoSuitableReplicaException( + throw new NoLeaderFoundException( Status.NotFound("Tablet " + entry.toString() + " doesn't have a leader")); } } http://git-wip-us.apache.org/repos/asf/kudu/blob/f26ab7d5/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java b/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java index 3f2c745..02410a8 100644 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/GetMasterRegistrationReceived.java @@ -59,7 +59,6 @@ final class GetMasterRegistrationReceived { private final AtomicInteger countResponsesReceived = new AtomicInteger(0); // Exceptions received so far: kept for debugging purposes. - // (see: NoLeaderMasterFoundException#create() for how this is used). private final List<Exception> exceptionsReceived = Collections.synchronizedList(new ArrayList<Exception>()); @@ -102,7 +101,7 @@ final class GetMasterRegistrationReceived { /** * Checks if we've already received a response or an exception from every master that * we've sent a GetMasterRegistrationRequest to. If so -- and no leader has been found - * (that is, 'responseD' was never called) -- pass a {@link NoLeaderMasterFoundException} + * (that is, 'responseD' was never called) -- pass a {@link NoLeaderFoundException} * to responseD. */ private void incrementCountAndCheckExhausted() { @@ -142,7 +141,7 @@ final class GetMasterRegistrationReceived { LOG.warn(String.format( "None of the provided masters (%s) is a leader, will retry.", allHosts)); - ex = new NoLeaderMasterFoundException(Status.ServiceUnavailable(message)); + ex = new NoLeaderFoundException(Status.ServiceUnavailable(message)); } else { LOG.warn(String.format( "Unable to find the leader master (%s), will retry", @@ -151,7 +150,7 @@ final class GetMasterRegistrationReceived { Joiner.on(",").join(Lists.transform( exceptionsReceived, Functions.toStringFunction())); Status s = Status.ServiceUnavailable(joinedMsg); - ex = new NoLeaderMasterFoundException(s, + ex = new NoLeaderFoundException(s, exceptionsReceived.get(exceptionsReceived.size() - 1)); } responseD.callback(ex); @@ -166,7 +165,7 @@ final class GetMasterRegistrationReceived { * the callback in 'responseD' is invoked with an initialized GetTableLocationResponsePB * object containing the leader's RPC address. * If the master is not a leader, increment 'countResponsesReceived': if the count equals to - * the number of masters, pass {@link NoLeaderMasterFoundException} into + * the number of masters, pass {@link NoLeaderFoundException} into * 'responseD' if no one else had called 'responseD' before; otherwise, do nothing. */ final class GetMasterRegistrationCB implements Callback<Void, GetMasterRegistrationResponse> { @@ -220,7 +219,7 @@ final class GetMasterRegistrationReceived { * Errback for each GetMasterRegistrationRequest sent in getMasterTableLocations() above. * Stores each exception in 'exceptionsReceived'. Increments 'countResponseReceived': if * the count is equal to the number of masters and no one else had called 'responseD' before, - * pass a {@link NoLeaderMasterFoundException} into 'responseD'; otherwise, do + * pass a {@link NoLeaderFoundException} into 'responseD'; otherwise, do * nothing. */ final class GetMasterRegistrationErrCB implements Callback<Void, Exception> { http://git-wip-us.apache.org/repos/asf/kudu/blob/f26ab7d5/java/kudu-client/src/main/java/org/apache/kudu/client/NoLeaderFoundException.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/NoLeaderFoundException.java b/java/kudu-client/src/main/java/org/apache/kudu/client/NoLeaderFoundException.java new file mode 100644 index 0000000..86aeccf --- /dev/null +++ b/java/kudu-client/src/main/java/org/apache/kudu/client/NoLeaderFoundException.java @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.kudu.client; + +import org.apache.kudu.annotations.InterfaceAudience; +import org.apache.kudu.annotations.InterfaceStability; + +import java.util.List; + +/** + * Indicates that the request failed because we couldn't find a leader. It is retried as long + * as the original call hasn't timed out. + */ [email protected] [email protected] +final class NoLeaderFoundException extends RecoverableException { + + NoLeaderFoundException(Status status) { + super(status); + } + NoLeaderFoundException(Status status, Exception cause) { + super(status, cause); + } +} http://git-wip-us.apache.org/repos/asf/kudu/blob/f26ab7d5/java/kudu-client/src/main/java/org/apache/kudu/client/NoLeaderMasterFoundException.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/NoLeaderMasterFoundException.java b/java/kudu-client/src/main/java/org/apache/kudu/client/NoLeaderMasterFoundException.java deleted file mode 100644 index 587741e..0000000 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/NoLeaderMasterFoundException.java +++ /dev/null @@ -1,37 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package org.apache.kudu.client; - -import org.apache.kudu.annotations.InterfaceAudience; -import org.apache.kudu.annotations.InterfaceStability; - -import java.util.List; - -/** - * Indicates that the request failed because we couldn't find a leader master server. - */ [email protected] [email protected] -final class NoLeaderMasterFoundException extends RecoverableException { - - NoLeaderMasterFoundException(Status status) { - super(status); - } - NoLeaderMasterFoundException(Status status, Exception cause) { - super(status, cause); - } -} http://git-wip-us.apache.org/repos/asf/kudu/blob/f26ab7d5/java/kudu-client/src/main/java/org/apache/kudu/client/NoSuitableReplicaException.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/NoSuitableReplicaException.java b/java/kudu-client/src/main/java/org/apache/kudu/client/NoSuitableReplicaException.java deleted file mode 100644 index e51a346..0000000 --- a/java/kudu-client/src/main/java/org/apache/kudu/client/NoSuitableReplicaException.java +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package org.apache.kudu.client; - -/** - * Indicates that the master lookup failed because no suitable replicas were found for - * the given RPC. - */ -final class NoSuitableReplicaException extends RecoverableException { - - NoSuitableReplicaException(Status status) { - super(status); - } - - NoSuitableReplicaException(Status status, Exception cause) { - super(status, cause); - } -} http://git-wip-us.apache.org/repos/asf/kudu/blob/f26ab7d5/java/kudu-client/src/test/java/org/apache/kudu/client/TestAsyncKuduClient.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestAsyncKuduClient.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestAsyncKuduClient.java index 1511221..a91124d 100644 --- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestAsyncKuduClient.java +++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestAsyncKuduClient.java @@ -192,7 +192,7 @@ public class TestAsyncKuduClient extends BaseKuduTest { try { client.discoverTablets(table, new byte[0], tabletLocations, 1000); fail("discoverTablets should throw an exception if there's no leader"); - } catch (NoSuitableReplicaException ex) { + } catch (NoLeaderFoundException ex) { // Expected. } } http://git-wip-us.apache.org/repos/asf/kudu/blob/f26ab7d5/java/kudu-client/src/test/java/org/apache/kudu/client/TestGetMasterRegistrationReceived.java ---------------------------------------------------------------------- diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestGetMasterRegistrationReceived.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestGetMasterRegistrationReceived.java index 8570668..3882acd 100644 --- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestGetMasterRegistrationReceived.java +++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestGetMasterRegistrationReceived.java @@ -46,8 +46,8 @@ public class TestGetMasterRegistrationReceived { Status.RuntimeError("")); RecoverableException reusableRE = new RecoverableException( Status.RuntimeError("")); - NoLeaderMasterFoundException retryResponse = - new NoLeaderMasterFoundException(Status.RuntimeError("")); + NoLeaderFoundException retryResponse = + new NoLeaderFoundException(Status.RuntimeError("")); // We don't test for a particular good response, so as long as we pass something that's not an // exception to runTest() we're good. Object successResponse = new Object();
