KeeProMise commented on code in PR #5990:
URL: https://github.com/apache/hadoop/pull/5990#discussion_r1309488817


##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MembershipNamenodeResolver.java:
##########
@@ -478,4 +478,40 @@ private List<MembershipState> 
getRecentRegistrationForQuery(
   public void setRouterId(String router) {
     this.routerId = router;
   }
+
+  /**
+   * Rotate cache, make the current namenode have the lowest priority,
+   * to ensure that the current namenode will not be accessed first next time.
+   *
+   * @param nsId name service id
+   * @param namenode namenode contexts
+   */
+  @Override
+  public synchronized void rotateCache(String nsId, FederationNamenodeContext 
namenode) {
+    cacheNS.compute(Pair.of(nsId, false), (ns, namenodeContexts) -> {
+      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 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);
+        return rotatedNnContexts;
+      }else {

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: common-issues-unsubscr...@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to