Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@
public class ServerNotLeaderException extends IOException {
private final String leader;
private static final Pattern CURRENT_PEER_ID_PATTERN =
Pattern.compile("Server:(.*) is not the leader[.]+.*", Pattern.DOTALL);
Pattern.compile(".* Server:(.*?) is not the leader[.]+.*", Pattern.DOTALL);
private static final Pattern SUGGESTED_LEADER_PATTERN =
Pattern.compile(".*Suggested leader is Server:([^:]*)(:[0-9]+).*",
Pattern.DOTALL);

public ServerNotLeaderException(RaftPeerId currentPeerId) {
super("Server:" + currentPeerId + " is not the leader. Could not " +
public ServerNotLeaderException(RaftPeerId currentPeerId, String hostname,
String roleType) {
super(roleType + " Server:" + currentPeerId + "(" + hostname + ") is not the leader. Could not " +
"determine the leader node.");
this.leader = null;
}

public ServerNotLeaderException(RaftPeerId currentPeerId,
String suggestedLeader) {
super("Server:" + currentPeerId + " is not the leader. Suggested leader is"
String suggestedLeader, String hostname, String roleType) {
super(roleType + " Server:" + currentPeerId + "(" + hostname + ") is not the leader. Suggested leader is"
+ " Server:" + suggestedLeader + ".");
this.leader = suggestedLeader;
}
Expand Down Expand Up @@ -90,7 +91,7 @@ public String getSuggestedLeader() {
*/
public static ServerNotLeaderException convertToNotLeaderException(
NotLeaderException notLeaderException,
RaftPeerId currentPeer, String port) {
RaftPeerId currentPeer, String port, String hostname, String roleType) {
String suggestedLeader = notLeaderException.getSuggestedLeader() != null ?
HddsUtils
.getHostName(notLeaderException.getSuggestedLeader().getAddress())
Expand All @@ -100,9 +101,9 @@ public static ServerNotLeaderException convertToNotLeaderException(
if (suggestedLeader != null) {
String suggestedLeaderHostPort = suggestedLeader + ":" + port;
serverNotLeaderException =
new ServerNotLeaderException(currentPeer, suggestedLeaderHostPort);
new ServerNotLeaderException(currentPeer, suggestedLeaderHostPort, hostname, roleType);
} else {
serverNotLeaderException = new ServerNotLeaderException(currentPeer);
serverNotLeaderException = new ServerNotLeaderException(currentPeer, hostname, roleType);
}
return serverNotLeaderException;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public void testServerNotLeaderException() {

// Test hostname with "."
final String msg =
"Server:cf0bc565-a41b-4784-a24d-3048d5a5b013 is not the leader. "
"SCM Server:cf0bc565-a41b-4784-a24d-3048d5a5b013 (172.16.102.111) is not the leader. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chiacyu This exception should match the actual ServerNotLeaderException message. Based on your patch to the ServerNotLeaderException.java there shouldn't be a space between the RaftPeerID and hostname, right?
The message will be SCM Server:cf0bc565-a41b-4784-a24d-3048d5a5b013(172.16.102.111) is not the leader.

Could you correct this in all the messages?

+ "Suggested leader is Server:scm5-3.scm5.root.hwx.site:9863";
ServerNotLeaderException snle = new ServerNotLeaderException(msg);
assertEquals(snle.getSuggestedLeader(), "scm5-3.scm5.root.hwx" +
".site:9863");

String message = "Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 is not the " +
String message = "SCM Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 (172.16.102.111) is not the " +
"leader.Suggested leader is Server:scm5-3.scm5.root.hwx.site:9863 \n" +
"at org.apache.hadoop.hdds.ratis.ServerNotLeaderException" +
".convertToNotLeaderException(ServerNotLeaderException.java:96)";
Expand All @@ -45,30 +45,30 @@ public void testServerNotLeaderException() {
snle.getSuggestedLeader());

// Test hostname with out "."
message = "Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 is not the " +
message = "SCM Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 (172.16.102.111) is not the " +
"leader.Suggested leader is Server:localhost:98634 \n" +
"at org.apache.hadoop.hdds.ratis.ServerNotLeaderException" +
".convertToNotLeaderException(ServerNotLeaderException.java:96)";
snle = new ServerNotLeaderException(message);
assertEquals("localhost:98634",
snle.getSuggestedLeader());

message = "Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 is not the " +
message = "SCM Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 (172.16.102.111) is not the " +
"leader.Suggested leader is Server::98634 \n" +
"at org.apache.hadoop.hdds.ratis.ServerNotLeaderException" +
".convertToNotLeaderException(ServerNotLeaderException.java:96)";
snle = new ServerNotLeaderException(message);
assertNull(snle.getSuggestedLeader());

message = "Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 is not the " +
message = "SCM Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 (172.16.102.111) is not the " +
"leader.Suggested leader is Server:localhost:98634:8988 \n" +
"at org.apache.hadoop.hdds.ratis.ServerNotLeaderException" +
".convertToNotLeaderException(ServerNotLeaderException.java:96)";
snle = new ServerNotLeaderException(message);
assertEquals("localhost:98634",
snle.getSuggestedLeader());

message = "Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 is not the " +
message = "SCM Server:7fdd7170-75cc-4e11-b343-c2657c2f2f39 (172.16.102.111) is not the " +
"leader.Suggested leader is Server:localhost \n" +
"at org.apache.hadoop.hdds.ratis.ServerNotLeaderException" +
".convertToNotLeaderException(ServerNotLeaderException.java)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static void setRaftSnapshotProperties(
}

public static void checkRatisException(IOException e, String port,
String scmId) throws ServiceException {
String scmId, String hostname, String roleType) throws ServiceException {
if (SCMHAUtils.isNonRetriableException(e)) {
throw new ServiceException(new NonRetriableException(e));
} else if (SCMHAUtils.isRetriableWithNoFailoverException(e)) {
Expand All @@ -246,7 +246,7 @@ public static void checkRatisException(IOException e, String port,
(NotLeaderException) SCMHAUtils.getNotLeaderException(e);
throw new ServiceException(ServerNotLeaderException
.convertToNotLeaderException(nle,
SCMRatisServerImpl.getSelfPeerId(scmId), port));
SCMRatisServerImpl.getSelfPeerId(scmId), port, hostname, roleType));
} else if (e instanceof SCMSecurityException) {
// For NOT_A_PRIMARY_SCM error client needs to retry on next SCM.
// GetSCMCertificate call can happen on non-leader SCM and only an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public SCMSecurityResponse submitRequest(RpcController controller,
if (!scm.checkLeader()) {
RatisUtil.checkRatisException(
scm.getScmHAManager().getRatisServer().triggerNotLeaderException(),
scm.getSecurityProtocolRpcPort(), scm.getScmId());
scm.getSecurityProtocolRpcPort(), scm.getScmId(), scm.getHostname(), "SCM");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You could make role type SCM a static final field.

}
return dispatcher.processRequest(request, this::processRequest,
request.getCmdType(), request.getTraceID());
Expand Down Expand Up @@ -150,7 +150,7 @@ public SCMSecurityResponse processRequest(SCMSecurityRequest request)
}
} catch (IOException e) {
RatisUtil.checkRatisException(e, scm.getSecurityProtocolRpcPort(),
scm.getScmId());
scm.getScmId(), scm.getHostname(), "SCM");
scmSecurityResponse.setSuccess(false);
scmSecurityResponse.setStatus(exceptionToResponseStatus(e));
// If actual cause is set in SCMSecurityException, set message with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public SCMBlockLocationResponse send(RpcController controller,
if (!scm.checkLeader()) {
RatisUtil.checkRatisException(
scm.getScmHAManager().getRatisServer().triggerNotLeaderException(),
scm.getBlockProtocolRpcPort(), scm.getScmId());
scm.getBlockProtocolRpcPort(), scm.getScmId(), scm.getHostname(), "SCM");
}
return dispatcher.processRequest(
request,
Expand Down Expand Up @@ -173,7 +173,7 @@ private SCMBlockLocationResponse processMessage(
}
} catch (IOException e) {
RatisUtil.checkRatisException(e, scm.getBlockProtocolRpcPort(),
scm.getScmId());
scm.getScmId(), scm.getHostname(), "SCM");
response.setSuccess(false);
response.setStatus(exceptionToResponseStatus(e));
if (e.getMessage() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public SCMSecretKeyResponse submitRequest(RpcController controller,
if (!scm.checkLeader()) {
RatisUtil.checkRatisException(
scm.getScmHAManager().getRatisServer().triggerNotLeaderException(),
scm.getSecurityProtocolRpcPort(), scm.getScmId());
scm.getSecurityProtocolRpcPort(), scm.getScmId(), scm.getHostname(), "SCM");
}
return dispatcher.processRequest(request, this::processRequest,
request.getCmdType(), request.getTraceID());
Expand Down Expand Up @@ -115,7 +115,7 @@ public SCMSecretKeyResponse processRequest(SCMSecretKeyRequest request)
}
} catch (IOException e) {
RatisUtil.checkRatisException(e, scm.getSecurityProtocolRpcPort(),
scm.getScmId());
scm.getScmId(), scm.getHostname(), "SCM");
scmSecurityResponse.setSuccess(false);
scmSecurityResponse.setStatus(exceptionToResponseStatus(e));
// If actual cause is set in SCMSecurityException, set message with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public ScmContainerLocationResponse submitRequest(RpcController controller,
&& !ADMIN_COMMAND_TYPE.contains(request.getCmdType())) {
RatisUtil.checkRatisException(
scm.getScmHAManager().getRatisServer().triggerNotLeaderException(),
scm.getClientRpcPort(), scm.getScmId());
scm.getClientRpcPort(), scm.getScmId(), scm.getHostname(), "SCM");
}
// After the request interceptor (now validator) framework is extended to
// this server interface, this should be removed and solved via new
Expand Down Expand Up @@ -737,7 +737,7 @@ public ScmContainerLocationResponse processRequest(
}
} catch (IOException e) {
RatisUtil
.checkRatisException(e, scm.getClientRpcPort(), scm.getScmId());
.checkRatisException(e, scm.getClientRpcPort(), scm.getScmId(), scm.getHostname(), "SCM");
throw new ServiceException(e);
}
}
Expand Down