Skip to content

Commit 9a6a11c

Browse files
committed
YARN-10767. Yarn Logs Command retrying on Standby RM for 30 times. Contributed by D M Murali Krishna Reddy.
1 parent a77bf7c commit 9a6a11c

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/RMHAUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.List;
2424
import org.apache.hadoop.classification.InterfaceAudience.Private;
2525
import org.apache.hadoop.classification.InterfaceStability.Unstable;
26+
import org.apache.hadoop.conf.Configuration;
2627
import org.apache.hadoop.fs.CommonConfigurationKeys;
2728
import org.apache.hadoop.ha.HAServiceProtocol;
2829
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
@@ -35,7 +36,7 @@
3536
@Unstable
3637
public class RMHAUtils {
3738

38-
public static String findActiveRMHAId(YarnConfiguration conf) {
39+
public static String findActiveRMHAId(Configuration conf) {
3940
YarnConfiguration yarnConf = new YarnConfiguration(conf);
4041
Collection<String> rmIds =
4142
yarnConf.getStringCollection(YarnConfiguration.RM_HA_IDS);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/WebAppUtils.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.apache.hadoop.yarn.util.StringHelper.PATH_JOINER;
2121

2222
import java.io.IOException;
23+
import java.net.ConnectException;
2324
import java.net.InetAddress;
2425
import java.net.InetSocketAddress;
2526
import java.net.UnknownHostException;
@@ -97,24 +98,17 @@ public static void setNMWebAppHostNameAndPort(Configuration conf,
9798
*/
9899
public static <T, R> R execOnActiveRM(Configuration conf,
99100
ThrowingBiFunction<String, T, R> func, T arg) throws Exception {
100-
String rm1Address = getRMWebAppURLWithScheme(conf, 0);
101-
try {
102-
return func.apply(rm1Address, arg);
103-
} catch (Exception e) {
104-
if (HAUtil.isHAEnabled(conf)) {
105-
int rms = HAUtil.getRMHAIds(conf).size();
106-
for (int i=1; i<rms; i++) {
107-
try {
108-
rm1Address = getRMWebAppURLWithScheme(conf, i);
109-
return func.apply(rm1Address, arg);
110-
} catch (Exception e1) {
111-
// ignore and try next one when RM is down
112-
e = e1;
113-
}
114-
}
101+
int haIndex = 0;
102+
if (HAUtil.isHAEnabled(conf)) {
103+
String activeRMId = RMHAUtils.findActiveRMHAId(conf);
104+
if (activeRMId != null) {
105+
haIndex = new ArrayList<>(HAUtil.getRMHAIds(conf)).indexOf(activeRMId);
106+
} else {
107+
throw new ConnectException("No Active RM available");
115108
}
116-
throw e;
117109
}
110+
String rm1Address = getRMWebAppURLWithScheme(conf, haIndex);
111+
return func.apply(rm1Address, arg);
118112
}
119113

120114
/** A BiFunction which throws on Exception. */

0 commit comments

Comments
 (0)