Skip to content

Commit baf56d6

Browse files
author
wuxiaobao
committed
YARN-11626. Optimize ResourceManager's operations on Zookeeper metadata
1 parent 7bedb96 commit baf56d6

File tree

3 files changed

+420
-15
lines changed

3 files changed

+420
-15
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
<artifactId>mockito-core</artifactId>
6868
<scope>test</scope>
6969
</dependency>
70+
<dependency>
71+
<groupId>org.mockito</groupId>
72+
<artifactId>mockito-inline</artifactId>
73+
<version>2.8.9</version>
74+
<scope>test</scope>
75+
</dependency>
7076
<!-- 'mvn dependency:analyze' fails to detect use of this dependency -->
7177
<dependency>
7278
<groupId>org.apache.hadoop</groupId>

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/ZKRMStateStore.java

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,15 @@ private void handleApplicationAttemptStateOp(
956956
zkAcl, fencingNodePath);
957957
break;
958958
case REMOVE:
959-
zkManager.safeDelete(path, zkAcl, fencingNodePath);
959+
try{
960+
zkManager.safeDelete(path, zkAcl, fencingNodePath);
961+
} catch (KeeperException.NoNodeException nne) {
962+
if(!exists(path)){
963+
LOG.info("Node " + path + " doesn't exist to delete");
964+
} else {
965+
throw nne;
966+
}
967+
}
960968
break;
961969
default:
962970
break;
@@ -1031,14 +1039,25 @@ private void removeApp(String removeAppId, boolean safeRemove,
10311039
LOG.debug("Removing info for app: {} at: {} and its attempts.",
10321040
removeAppId, appIdRemovePath);
10331041

1034-
if (attempts != null) {
1035-
for (ApplicationAttemptId attemptId : attempts) {
1036-
String attemptRemovePath =
1037-
getNodePath(appIdRemovePath, attemptId.toString());
1038-
zkManager.safeDelete(attemptRemovePath, zkAcl, fencingNodePath);
1042+
String path = appIdRemovePath;
1043+
try {
1044+
if (attempts != null) {
1045+
for (ApplicationAttemptId attemptId : attempts) {
1046+
String attemptRemovePath =
1047+
getNodePath(appIdRemovePath, attemptId.toString());
1048+
path = attemptRemovePath;
1049+
zkManager.safeDelete(attemptRemovePath, zkAcl, fencingNodePath);
1050+
}
1051+
path = appIdRemovePath;
1052+
}
1053+
zkManager.safeDelete(appIdRemovePath, zkAcl, fencingNodePath);
1054+
} catch (KeeperException.NoNodeException nne){
1055+
if(!exists(path)){
1056+
LOG.info("Node " + path + " doesn't exist to delete");
1057+
} else {
1058+
throw nne;
10391059
}
10401060
}
1041-
zkManager.safeDelete(appIdRemovePath, zkAcl, fencingNodePath);
10421061
} else {
10431062
CuratorFramework curatorFramework = zkManager.getCurator();
10441063
curatorFramework.delete().deletingChildrenIfNeeded().
@@ -1098,8 +1117,15 @@ protected synchronized void removeRMDelegationTokenState(
10981117

10991118
LOG.debug("Removing RMDelegationToken_{}",
11001119
rmDTIdentifier.getSequenceNumber());
1101-
1102-
zkManager.safeDelete(nodeRemovePath, zkAcl, fencingNodePath);
1120+
try {
1121+
zkManager.safeDelete(nodeRemovePath, zkAcl, fencingNodePath);
1122+
} catch (KeeperException.NoNodeException nne){
1123+
if(!exists(nodeRemovePath)){
1124+
LOG.info("Node " + nodeRemovePath + " doesn't exist to delete");
1125+
} else {
1126+
throw nne;
1127+
}
1128+
}
11031129

11041130
// Check if we should remove the parent app node as well.
11051131
checkRemoveParentZnode(nodeRemovePath, splitIndex);
@@ -1159,8 +1185,15 @@ protected synchronized void removeRMDTMasterKeyState(
11591185
+ delegationKey.getKeyId());
11601186

11611187
LOG.debug("Removing RMDelegationKey_{}", delegationKey.getKeyId());
1162-
1163-
zkManager.safeDelete(nodeRemovePath, zkAcl, fencingNodePath);
1188+
try {
1189+
zkManager.safeDelete(nodeRemovePath, zkAcl, fencingNodePath);
1190+
} catch (KeeperException.NoNodeException nne){
1191+
if(!exists(nodeRemovePath)){
1192+
LOG.info("Node " + nodeRemovePath + " doesn't exist to delete");
1193+
} else {
1194+
throw nne;
1195+
}
1196+
}
11641197
}
11651198

11661199
@Override
@@ -1200,12 +1233,22 @@ protected synchronized void removeReservationState(String planName,
12001233
LOG.debug("Removing reservationallocation {} for plan {}",
12011234
reservationIdName, planName);
12021235

1203-
zkManager.safeDelete(reservationPath, zkAcl, fencingNodePath);
1236+
String path = reservationPath;
1237+
try{
1238+
zkManager.safeDelete(reservationPath, zkAcl, fencingNodePath);
12041239

1205-
List<String> reservationNodes = getChildren(planNodePath);
1240+
List<String> reservationNodes = getChildren(planNodePath);
12061241

1207-
if (reservationNodes.isEmpty()) {
1208-
zkManager.safeDelete(planNodePath, zkAcl, fencingNodePath);
1242+
if (reservationNodes.isEmpty()) {
1243+
path = planNodePath;
1244+
zkManager.safeDelete(planNodePath, zkAcl, fencingNodePath);
1245+
}
1246+
} catch (KeeperException.NoNodeException nne){
1247+
if(!exists(path)){
1248+
LOG.info("Node " + path + " doesn't exist to delete");
1249+
} else {
1250+
throw nne;
1251+
}
12091252
}
12101253
}
12111254

0 commit comments

Comments
 (0)