KeeProMise commented on code in PR #6208:
URL: https://github.com/apache/hadoop/pull/6208#discussion_r1371090045
##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MembershipNamenodeResolver.java:
##########
@@ -494,29 +494,31 @@ public void rotateCache(
if (namenodeContexts == null || namenodeContexts.size() <= 1) {
return namenodeContexts;
}
- FederationNamenodeContext firstNamenodeContext = namenodeContexts.get(0);
- /*
- * If the first nn in the cache is active, the active nn priority cannot
be lowered.
- * This happens when other threads have already updated the cache.
- */
- if (firstNamenodeContext.getState().equals(ACTIVE)) {
- return namenodeContexts;
+
+ // If there is active nn, rotateCache is not needed
+ // because the router has already loaded the cache.
+ for (FederationNamenodeContext namenodeContext : namenodeContexts) {
+ if (namenodeContext.getState() == ACTIVE) {
+ return namenodeContexts;
+ }
}
- /*
- * If the first nn in the cache at this time is not the nn
- * that needs to be lowered in priority, there is no need to rotate.
- * This happens when other threads have already rotated the cache.
- */
- if
(firstNamenodeContext.getRpcAddress().equals(namenode.getRpcAddress())) {
- List<FederationNamenodeContext> rotatedNnContexts = new
ArrayList<>(namenodeContexts);
- Collections.rotate(rotatedNnContexts, -1);
- String firstNamenodeId = namenodeContexts.get(0).getNamenodeId();
- LOG.info("Rotate cache of pair <ns: {}, observer first: {}>, put
namenode: {} in the " +
- "first position of the cache and namenode: {} in the last position
of the cache",
- nsId, listObserversFirst, firstNamenodeId,
namenode.getNamenodeId());
- return rotatedNnContexts;
+
+ // If the last namenode in the cache at this time is the namenode.
+ // No need to rotate cache, because other threads have already rotated
the cache.
+ FederationNamenodeContext lastNamenode =
namenodeContexts.get(namenodeContexts.size()-1);
+ if (lastNamenode.getRpcAddress().equals(namenode.getRpcAddress())) {
+ return namenodeContexts;
}
- return namenodeContexts;
+
+ // Move the abnormal namenode to the end of the cache,
+ // to ensure that the current namenode will not be accessed first next
time.
Review Comment:
yes, I have modified the comment
##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MembershipNamenodeResolver.java:
##########
@@ -494,29 +494,31 @@ public void rotateCache(
if (namenodeContexts == null || namenodeContexts.size() <= 1) {
return namenodeContexts;
}
- FederationNamenodeContext firstNamenodeContext = namenodeContexts.get(0);
- /*
- * If the first nn in the cache is active, the active nn priority cannot
be lowered.
- * This happens when other threads have already updated the cache.
- */
- if (firstNamenodeContext.getState().equals(ACTIVE)) {
- return namenodeContexts;
+
+ // If there is active nn, rotateCache is not needed
+ // because the router has already loaded the cache.
+ for (FederationNamenodeContext namenodeContext : namenodeContexts) {
+ if (namenodeContext.getState() == ACTIVE) {
+ return namenodeContexts;
+ }
}
- /*
- * If the first nn in the cache at this time is not the nn
- * that needs to be lowered in priority, there is no need to rotate.
- * This happens when other threads have already rotated the cache.
- */
- if
(firstNamenodeContext.getRpcAddress().equals(namenode.getRpcAddress())) {
- List<FederationNamenodeContext> rotatedNnContexts = new
ArrayList<>(namenodeContexts);
- Collections.rotate(rotatedNnContexts, -1);
- String firstNamenodeId = namenodeContexts.get(0).getNamenodeId();
- LOG.info("Rotate cache of pair <ns: {}, observer first: {}>, put
namenode: {} in the " +
- "first position of the cache and namenode: {} in the last position
of the cache",
- nsId, listObserversFirst, firstNamenodeId,
namenode.getNamenodeId());
- return rotatedNnContexts;
+
+ // If the last namenode in the cache at this time is the namenode.
+ // No need to rotate cache, because other threads have already rotated
the cache.
+ FederationNamenodeContext lastNamenode =
namenodeContexts.get(namenodeContexts.size()-1);
+ if (lastNamenode.getRpcAddress().equals(namenode.getRpcAddress())) {
+ return namenodeContexts;
}
- return namenodeContexts;
+
+ // Move the abnormal namenode to the end of the cache,
Review Comment:
thanks for your advice, done
##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MembershipNamenodeResolver.java:
##########
@@ -494,29 +494,31 @@ public void rotateCache(
if (namenodeContexts == null || namenodeContexts.size() <= 1) {
return namenodeContexts;
}
- FederationNamenodeContext firstNamenodeContext = namenodeContexts.get(0);
- /*
- * If the first nn in the cache is active, the active nn priority cannot
be lowered.
- * This happens when other threads have already updated the cache.
- */
- if (firstNamenodeContext.getState().equals(ACTIVE)) {
- return namenodeContexts;
+
+ // If there is active nn, rotateCache is not needed
+ // because the router has already loaded the cache.
+ for (FederationNamenodeContext namenodeContext : namenodeContexts) {
+ if (namenodeContext.getState() == ACTIVE) {
+ return namenodeContexts;
+ }
}
- /*
- * If the first nn in the cache at this time is not the nn
- * that needs to be lowered in priority, there is no need to rotate.
- * This happens when other threads have already rotated the cache.
- */
- if
(firstNamenodeContext.getRpcAddress().equals(namenode.getRpcAddress())) {
- List<FederationNamenodeContext> rotatedNnContexts = new
ArrayList<>(namenodeContexts);
- Collections.rotate(rotatedNnContexts, -1);
- String firstNamenodeId = namenodeContexts.get(0).getNamenodeId();
- LOG.info("Rotate cache of pair <ns: {}, observer first: {}>, put
namenode: {} in the " +
- "first position of the cache and namenode: {} in the last position
of the cache",
- nsId, listObserversFirst, firstNamenodeId,
namenode.getNamenodeId());
- return rotatedNnContexts;
+
+ // If the last namenode in the cache at this time is the namenode.
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]