KeeProMise commented on code in PR #5990: URL: https://github.com/apache/hadoop/pull/5990#discussion_r1306285491
########## 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 Review Comment: The reason for not judging outside here is that we should ensure that get cache and modify cache are atomic, considering the following situation: 1. After **Thread1** judges that the cache is not empty, it gets the ns no active in the cache 2. **Thread2** (StateStoreCacheUpdateService loadCache )clear the cache 3. **Thread3** processes the client request and finds that the cache is empty(MembershipNamenodeResolver.getNamenodesForNameserviceId()), then updates the cache. At this time, the ns - in the cache has active nn 4. **Thread1** rotates the previously acquired data of non-active nn and writes it into the cache, causing ns in the cache to have no active nn so, guaranteed atomicity can ensure that the above 2 and 3 are recognized before modifying the cache -- 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