-
Notifications
You must be signed in to change notification settings - Fork 625
HDDS-7492. Placement Policy Interface changes to handle misreplication changes #4006
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
Changes from 14 commits
f6b0d03
daeddb4
b4b891b
7d36041
7efb3ee
fd3ed13
209429e
ce6654d
045fbb8
0e107f7
b261b17
96ece79
923d940
d3f052e
8f023aa
0d231eb
15472d0
26244fa
20620e7
f62044d
75963bd
50648fa
7eb77ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ | |
|
|
||
| import org.apache.hadoop.hdds.scm.ContainerPlacementStatus; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Simple Status object to check if a container is replicated across enough | ||
| * racks. | ||
|
|
@@ -29,33 +32,56 @@ public class ContainerPlacementStatusDefault | |
| private final int currentRacks; | ||
| private final int totalRacks; | ||
|
|
||
| private final int maxReplicasPerRack; | ||
| private final List<Integer> rackReplicaCnts; | ||
|
|
||
|
|
||
| public ContainerPlacementStatusDefault(int currentRacks, int requiredRacks, | ||
| int totalRacks) { | ||
| int totalRacks, int maxReplicasPerRack, List<Integer> rackReplicaCnts) { | ||
| this.requiredRacks = requiredRacks; | ||
| this.currentRacks = currentRacks; | ||
| this.totalRacks = totalRacks; | ||
| this.maxReplicasPerRack = maxReplicasPerRack; | ||
| this.rackReplicaCnts = rackReplicaCnts; | ||
| } | ||
|
|
||
| public ContainerPlacementStatusDefault(int requiredRacks, int currentRacks, | ||
| int totalRacks) { | ||
| this(requiredRacks, currentRacks, totalRacks, 1, | ||
| currentRacks == 0 ? Collections.emptyList() | ||
| : Collections.nCopies(currentRacks, 1)); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isPolicySatisfied() { | ||
| return currentRacks >= totalRacks || currentRacks >= requiredRacks; | ||
| if (currentRacks < Math.min(totalRacks, requiredRacks)) { | ||
| return false; | ||
| } | ||
| return rackReplicaCnts.stream().allMatch(cnt -> cnt <= maxReplicasPerRack); | ||
| } | ||
|
|
||
| @Override | ||
| public String misReplicatedReason() { | ||
| if (isPolicySatisfied()) { | ||
| return null; | ||
| } | ||
| return "The container is mis-replicated as it is on " + currentRacks + | ||
| " racks but should be on " + requiredRacks + " racks."; | ||
| if (currentRacks < Math.min(requiredRacks, maxReplicasPerRack)) { | ||
| return "The container is mis-replicated as it is on " + currentRacks + | ||
| " racks but should be on " + requiredRacks + " racks."; | ||
| } | ||
| return "The container is mis-replicated as max number of replicas per rack " | ||
| + "is " + maxReplicasPerRack + " but number of replicas per rack" + | ||
| " are " + rackReplicaCnts.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public int misReplicationCount() { | ||
| if (isPolicySatisfied()) { | ||
| return 0; | ||
| } | ||
| return requiredRacks - currentRacks; | ||
| return Math.max(requiredRacks - currentRacks, | ||
| rackReplicaCnts.stream().mapToInt( | ||
| cnt -> Math.max(maxReplicasPerRack - cnt, 0)).sum()); | ||
|
Comment on lines
+82
to
+84
Contributor
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. Trying to figure out what this part is doing. Should it be
Contributor
Author
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. yeah you are right
Contributor
Author
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. Thanks for pointing this out. Let me fix this. |
||
| } | ||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.