Skip to content

Commit

Permalink
HDDS-3498. Shutdown datanode if address is already in use (#7256)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniilchik authored Oct 4, 2024
1 parent 2401d27 commit 30da31f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,17 @@ public void logIfNeeded(Exception ex) {
}

if (missCounter == 0) {
long missedDurationSeconds = TimeUnit.MILLISECONDS.toSeconds(
this.getMissedCount() * getScmHeartbeatInterval(this.conf)
);
LOG.warn(
"Unable to communicate to {} server at {} for past {} seconds.",
serverName,
getAddress().getHostString() + ":" + getAddress().getPort(),
TimeUnit.MILLISECONDS.toSeconds(this.getMissedCount() *
getScmHeartbeatInterval(this.conf)), ex);
"Unable to communicate to {} server at {}:{} for past {} seconds.",
serverName,
address.getAddress(),
address.getPort(),
missedDurationSeconds,
ex
);
}

if (LOG.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.hadoop.ozone.container.common.states.endpoint;

import java.io.IOException;
import java.net.BindException;
import java.util.concurrent.Callable;

import org.apache.hadoop.hdds.conf.ConfigurationSource;
Expand Down Expand Up @@ -104,7 +105,7 @@ public EndpointStateMachine.EndPointStates call() throws Exception {
LOG.debug("Cannot execute GetVersion task as endpoint state machine " +
"is in {} state", rpcEndPoint.getState());
}
} catch (DiskOutOfSpaceException ex) {
} catch (DiskOutOfSpaceException | BindException ex) {
rpcEndPoint.setState(EndpointStateMachine.EndPointStates.SHUTDOWN);
} catch (IOException ex) {
rpcEndPoint.logIfNeeded(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.ozone.container.common.transport.server;

import java.io.IOException;
import java.net.BindException;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -185,7 +186,16 @@ public HddsProtos.ReplicationType getServerType() {
@Override
public void start() throws IOException {
if (!isStarted) {
server.start();
try {
server.start();
} catch (IOException e) {
LOG.error("Error while starting the server", e);
if (e.getMessage().contains("Failed to bind to address")) {
throw new BindException(e.getMessage());
} else {
throw e;
}
}
int realPort = server.getPort();

if (port == 0) {
Expand Down

0 comments on commit 30da31f

Please sign in to comment.