Skip to content

Commit

Permalink
HDDS-8715. Hadoop RPC server creation renames current thread (#4788)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai committed May 31, 2023
1 parent e76f312 commit f5ba2f5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.TreeMap;
Expand Down Expand Up @@ -82,6 +83,7 @@

import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.token.SecretManager;
import org.apache.hadoop.util.CheckedSupplier;
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
import org.apache.ratis.util.SizeInBytes;
import org.apache.hadoop.ozone.conf.OzoneServiceConfig;
Expand Down Expand Up @@ -824,4 +826,23 @@ public static Map<String, String> processForLogging(OzoneConfiguration conf) {
}
return sortedOzoneProps;
}

/**
* Execute some code and ensure thread name is not changed
* (workaround for HADOOP-18433).
*/
public static <T, E extends IOException> T preserveThreadName(
CheckedSupplier<T, E> supplier) throws E {
final Thread thread = Thread.currentThread();
final String threadName = thread.getName();

try {
return supplier.get();
} finally {
if (!Objects.equals(threadName, thread.getName())) {
LOG.info("Restoring thread name: {}", threadName);
thread.setName(threadName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DATANODE_CLIENT_ADDRESS_KEY;
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DATANODE_HANDLER_COUNT_DEFAULT;
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DATANODE_HANDLER_COUNT_KEY;
import static org.apache.hadoop.hdds.HddsUtils.preserveThreadName;
import static org.apache.hadoop.hdds.protocol.DatanodeDetails.Port.Name.CLIENT_RPC;

/**
Expand Down Expand Up @@ -162,8 +163,8 @@ private RPC.Server getRpcServer(OzoneConfiguration configuration)
.ReconfigureProtocolService.newReflectiveBlockingService(
reconfigureServerProtocol);

return startRpcServer(configuration, rpcAddress,
ReconfigureProtocolPB.class, reconfigureService, handlerCount);
return preserveThreadName(() -> startRpcServer(configuration, rpcAddress,
ReconfigureProtocolPB.class, reconfigureService, handlerCount));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static org.apache.hadoop.hdds.HddsUtils.preserveThreadName;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_EVENT_REPORT_EXEC_WAIT_THRESHOLD_DEFAULT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_EVENT_REPORT_QUEUE_WAIT_THRESHOLD_DEFAULT;
import static org.apache.hadoop.hdds.security.x509.certificate.authority.CertificateStore.CertType.VALID_CERTS;
Expand Down Expand Up @@ -1078,16 +1079,16 @@ public static RPC.Server startRpcServer(
BlockingService instance,
int handlerCount)
throws IOException {
RPC.Server rpcServer =
new RPC.Builder(conf)
.setProtocol(protocol)
.setInstance(instance)
.setBindAddress(addr.getHostString())
.setPort(addr.getPort())
.setNumHandlers(handlerCount)
.setVerbose(false)
.setSecretManager(null)
.build();

RPC.Server rpcServer = preserveThreadName(() -> new RPC.Builder(conf)
.setProtocol(protocol)
.setInstance(instance)
.setBindAddress(addr.getHostString())
.setPort(addr.getPort())
.setNumHandlers(handlerCount)
.setVerbose(false)
.setSecretManager(null)
.build());

HddsServerUtil.addPBProtocol(conf, protocol, instance, rpcServer);
return rpcServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_BLOCK_TOKEN_ENABLED;
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_BLOCK_TOKEN_ENABLED_DEFAULT;
import static org.apache.hadoop.hdds.HddsUtils.getScmAddressForClients;
import static org.apache.hadoop.hdds.HddsUtils.preserveThreadName;
import static org.apache.hadoop.hdds.server.ServerUtils.updateRPCListenAddress;
import static org.apache.hadoop.hdds.utils.HAUtils.getScmInfo;
import static org.apache.hadoop.ozone.OmUtils.MAX_TRXN_ID;
Expand Down Expand Up @@ -1262,15 +1263,16 @@ private RPC.Server startRpcServer(OzoneConfiguration conf,
BlockingService reconfigureProtocolService,
int handlerCount)
throws IOException {
RPC.Server rpcServer = new RPC.Builder(conf)

RPC.Server rpcServer = preserveThreadName(() -> new RPC.Builder(conf)
.setProtocol(OzoneManagerProtocolPB.class)
.setInstance(clientProtocolService)
.setBindAddress(addr.getHostString())
.setPort(addr.getPort())
.setNumHandlers(handlerCount)
.setVerbose(false)
.setSecretManager(delegationTokenMgr)
.build();
.build());

HddsServerUtil.addPBProtocol(conf, OMInterServiceProtocolPB.class,
interOMProtocolService, rpcServer);
Expand Down

0 comments on commit f5ba2f5

Please sign in to comment.