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


##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MembershipNamenodeResolver.java:
##########
@@ -478,4 +476,27 @@ private List<MembershipState> 
getRecentRegistrationForQuery(
   public void setRouterId(String router) {
     this.routerId = router;
   }
+
+  /**
+   * Shuffle cache, to ensure that the current nn will not be accessed first 
next time.
+   *
+   *
+   * @param nsId name service id
+   * @param namenode namenode contexts
+   */
+  @Override
+  public synchronized void shuffleCache(String nsId, FederationNamenodeContext 
namenode) {
+    cacheNS.compute(Pair.of(nsId, false), (ns, namenodeContexts) -> {
+      if (namenodeContexts != null
+              && namenodeContexts.size() > 0
+              && !namenodeContexts.get(0).getState().equals(ACTIVE)
+              && 
namenodeContexts.get(0).getRpcAddress().equals(namenode.getRpcAddress())) {
+        List<FederationNamenodeContext> rotatedNnContexts = new 
ArrayList<>(namenodeContexts);
+        Collections.rotate(rotatedNnContexts, -1);

Review Comment:
   When there is no active nn in the cache, but there is active nn in the 
actual environment, Let the priority of the wrong  nn be the lowest of all 
cache nns, so the next access can access other nn. In the default 
implementation of MembershipNamenodeResolver, we can directly rotate the cache 
to the left, because the cache of ns in the MembershipNamenodeResolver is a 
list, but considering the implementation of other NamenodeResolver (Maybe there 
will be in the future), therefore I used shuffleCache. This name may be changed 
to a more intuitive method name, do you have some good suggestions?



-- 
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]

Reply via email to