-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HDFS-16831. [RBF SBN] GetNamenodesForNameserviceId should shuffle Observer NameNodes every time #5098
Merged
Merged
HDFS-16831. [RBF SBN] GetNamenodesForNameserviceId should shuffle Observer NameNodes every time #5098
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
15470ab
HDFS-16831. [RBF SBN] GetNamenodesForNameserviceId should shuffle Obs…
ZanderXu a2b59c3
HDFS-16831. Modify code based on comments
ZanderXu 2a0cff3
HDFS-16831. Remove unused import
ZanderXu ebadfb1
HDFS-16831. Add one UT to test it.
ZanderXu 4451a84
HDFS-16831. Add doc for shuffleObserverNN.
ZanderXu 2329cb7
HDFS-16831. Modify the doc for shuffleObserverNN
ZanderXu d154c04
HDFS-16831. Add one ut to test shuffler
ZanderXu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.apache.hadoop.classification.VisibleForTesting; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hdfs.server.federation.store.DisabledNameserviceStore; | ||
import org.apache.hadoop.hdfs.server.federation.store.MembershipStore; | ||
|
@@ -189,13 +190,43 @@ private void updateNameNodeState(final String nsId, | |
} | ||
} | ||
|
||
@VisibleForTesting | ||
public <T extends FederationNamenodeContext> List<T> shuffleObserverNN( | ||
List<T> inputNameNodes, boolean listObserversFirst) { | ||
if (!listObserversFirst) { | ||
return inputNameNodes; | ||
} else { | ||
List<T> observerNNList = new ArrayList<>(); | ||
List<T> activeAndStandbyList = new ArrayList<>(); | ||
for (T t : inputNameNodes) { | ||
if (t.getState() == OBSERVER) { | ||
observerNNList.add(t); | ||
} else { | ||
activeAndStandbyList.add(t); | ||
} | ||
} | ||
|
||
if (observerNNList.size() <= 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could've done this check earlier. |
||
return inputNameNodes; | ||
} else { | ||
List<T> ret = new ArrayList<>(observerNNList.size() + activeAndStandbyList.size()); | ||
Collections.shuffle(observerNNList); | ||
// No need because the inputNameNodes has already been sorted | ||
// activeAndStandbyList.sort(new NamenodePriorityComparator()); | ||
ret.addAll(observerNNList); | ||
ret.addAll(activeAndStandbyList); | ||
return ret; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public List<? extends FederationNamenodeContext> getNamenodesForNameserviceId( | ||
final String nsId, boolean listObserversFirst) throws IOException { | ||
|
||
List<? extends FederationNamenodeContext> ret = cacheNS.get(Pair.of(nsId, listObserversFirst)); | ||
if (ret != null) { | ||
return ret; | ||
return shuffleObserverNN(ret, listObserversFirst); | ||
} | ||
|
||
// Not cached, generate the value | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No ned for elses when we do the return.