Skip to content

Commit 3debbb8

Browse files
committed
update per comments
1 parent d57a66d commit 3debbb8

File tree

6 files changed

+13
-73
lines changed

6 files changed

+13
-73
lines changed

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/InnerNodeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public Node getLeaf(int leafIndex) {
301301
*
302302
* Input:
303303
* leafIndex = 2
304-
* excludedScope = /dc2
304+
* excludedScope = /dc2/rack2
305305
* excludedNodes = {/dc1/rack1/n1}
306306
* ancestorGen = 1
307307
*

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hdds.scm.net;
1919

20+
import org.apache.commons.collections.CollectionUtils;
2021
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
2223

@@ -76,9 +77,8 @@ public static int locationToDepth(String location) {
7677
public static void removeDuplicate(NetworkTopology topology,
7778
Collection<Node> mutableExcludedNodes, List<String> mutableExcludedScopes,
7879
int ancestorGen) {
79-
if (mutableExcludedNodes == null || mutableExcludedNodes.size() == 0 ||
80-
mutableExcludedScopes == null || mutableExcludedScopes.size() == 0 ||
81-
topology == null) {
80+
if (CollectionUtils.isEmpty(mutableExcludedNodes) ||
81+
CollectionUtils.isEmpty(mutableExcludedScopes) || topology == null) {
8282
return;
8383
}
8484

@@ -114,7 +114,7 @@ public static void removeDuplicate(NetworkTopology topology,
114114
*/
115115
public static void removeOutscope(Collection<Node> mutableExcludedNodes,
116116
String scope) {
117-
if (mutableExcludedNodes == null || scope == null) {
117+
if (CollectionUtils.isEmpty(mutableExcludedNodes) || scope == null) {
118118
return;
119119
}
120120
synchronized (mutableExcludedNodes) {
@@ -139,7 +139,7 @@ public static void removeOutscope(Collection<Node> mutableExcludedNodes,
139139
public static List<Node> getAncestorList(NetworkTopology topology,
140140
Collection<Node> nodes, int generation) {
141141
List<Node> ancestorList = new ArrayList<>();
142-
if (topology == null ||nodes == null || nodes.size() == 0 ||
142+
if (topology == null || CollectionUtils.isEmpty(nodes) ||
143143
generation == 0) {
144144
return ancestorList;
145145
}

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetworkTopology.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ public InvalidTopologyException(String msg) {
3939
*/
4040
void add(Node node);
4141

42-
4342
/**
4443
* Remove a node from the network topology. This will be called when a
4544
* existing datanode is removed from the system.
4645
* @param node node to be removed; cannot be null
4746
*/
4847
void remove(Node node);
4948

50-
5149
/**
5250
* Check if the tree already contains node <i>node</i>.
5351
* @param node a node
@@ -68,7 +66,6 @@ public InvalidTopologyException(String msg) {
6866
*/
6967
boolean isSameAncestor(Node node1, Node node2, int ancestorGen);
7068

71-
7269
/**
7370
* Get the ancestor for node on generation <i>ancestorGen</i>.
7471
*
@@ -160,26 +157,6 @@ public InvalidTopologyException(String msg) {
160157
Node chooseRandom(String scope, Collection<Node> excludedNodes,
161158
int ancestorGen);
162159

163-
164-
/**
165-
* Randomly choose a leaf node.
166-
*
167-
* @param scope range from which a node will be chosen, cannot start with ~
168-
* @param excludedNodes nodes to be excluded
169-
* @param excludedScopes excluded node ranges. Cannot start with ~
170-
* @param ancestorGen matters when excludeNodes is not null. It means the
171-
* ancestor generation that's not allowed to share between chosen node and the
172-
* excludedNodes. For example, if ancestorGen is 1, means chosen node
173-
* cannot share the same parent with excludeNodes. If value is 2, cannot
174-
* share the same grand parent, and so on. If ancestorGen is 0, then no
175-
* effect.
176-
*
177-
* @return the chosen node
178-
*/
179-
Node chooseRandom(String scope, List<String> excludedScopes,
180-
Collection<Node> excludedNodes, int ancestorGen);
181-
182-
183160
/**
184161
* Randomly choose one node from <i>scope</i>, share the same generation
185162
* ancestor with <i>affinityNode</i>, and exclude nodes in

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetworkTopologyImpl.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.annotations.VisibleForTesting;
2121
import com.google.common.base.Preconditions;
2222
import com.google.common.collect.Lists;
23+
import org.apache.commons.collections.CollectionUtils;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

@@ -365,27 +366,6 @@ public Node chooseRandom(String scope, Collection<Node> excludedNodes,
365366
}
366367
}
367368

368-
/**
369-
* Randomly choose a leaf node.
370-
*
371-
* @param scope range from which a node will be chosen, cannot start with ~
372-
* @param excludedNodes nodes to be excluded
373-
* @param excludedScopes excluded node ranges. Cannot start with ~
374-
* @param ancestorGen matters when excludeNodes is not null. It means the
375-
* ancestor generation that's not allowed to share between chosen node and the
376-
* excludedNodes. For example, if ancestorGen is 1, means chosen node
377-
* cannot share the same parent with excludeNodes. If value is 2, cannot
378-
* share the same grand parent, and so on. If ancestorGen is 0, then no
379-
* effect.
380-
*
381-
* @return the chosen node
382-
*/
383-
public Node chooseRandom(String scope, List<String> excludedScopes,
384-
Collection<Node> excludedNodes, int ancestorGen) {
385-
return chooseRandom(scope, excludedScopes, excludedNodes, null,
386-
ancestorGen);
387-
}
388-
389369
/**
390370
* Randomly choose one leaf node from <i>scope</i>, share the same generation
391371
* ancestor with <i>affinityNode</i>, and exclude nodes in
@@ -784,7 +764,7 @@ private void checkScope(String scope) {
784764
}
785765

786766
private void checkExcludedScopes(List<String> excludedScopes) {
787-
if (excludedScopes != null && excludedScopes.size() > 0) {
767+
if (!CollectionUtils.isEmpty(excludedScopes)) {
788768
excludedScopes.stream().forEach(scope -> {
789769
if (scope.startsWith(SCOPE_REVERSE_STR)) {
790770
throw new IllegalArgumentException("excludedScope " + scope +

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementMetrics.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class SCMContainerPlacementMetrics implements MetricsSource {
3737
public static final String SOURCE_NAME =
3838
SCMContainerPlacementMetrics.class.getSimpleName();
3939
private static final MetricsInfo RECORD_INFO = Interns.info(SOURCE_NAME,
40-
"SCM Placement Metrics");
40+
"SCM Container Placement Metrics");
4141
private static MetricsRegistry registry;
4242

4343
// total datanode allocation request count
@@ -55,27 +55,23 @@ public SCMContainerPlacementMetrics() {
5555
public static SCMContainerPlacementMetrics create() {
5656
MetricsSystem ms = DefaultMetricsSystem.instance();
5757
registry = new MetricsRegistry(RECORD_INFO);
58-
return ms.register(SOURCE_NAME, "SCM Placement Metrics",
58+
return ms.register(SOURCE_NAME, "SCM Container Placement Metrics",
5959
new SCMContainerPlacementMetrics());
6060
}
6161

6262
public void incrDatanodeRequestCount(long count) {
63-
System.out.println("request + 1");
6463
this.datanodeRequestCount.incr(count);
6564
}
6665

6766
public void incrDatanodeChooseSuccessCount() {
68-
System.out.println("success + 1");
6967
this.datanodeChooseSuccessCount.incr(1);
7068
}
7169

7270
public void incrDatanodeChooseFallbackCount() {
73-
System.out.println("fallback + 1");
7471
this.datanodeChooseFallbackCount.incr(1);
7572
}
7673

7774
public void incrDatanodeChooseAttemptCount() {
78-
System.out.println("attempt + 1");
7975
this.datanodeChooseAttemptCount.incr(1);
8076
}
8177

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,15 @@ private Node chooseNode(List<Node> excludedNodes, Node affinityNode,
242242
long sizeRequired) throws SCMException {
243243
int ancestorGen = RACK_LEVEL;
244244
int maxRetry = MAX_RETRY;
245-
<<<<<<< HEAD
246-
List<Node> excludedNodesForCapacity = null;
245+
List<String> excludedNodesForCapacity = null;
247246
boolean isFallbacked = false;
248247
while(true) {
249-
Node node = networkTopology.chooseRandom(NetConstants.ROOT, null,
250-
excludedNodes, affinityNode, ancestorGen);
251248
metrics.incrDatanodeChooseAttemptCount();
252-
=======
253-
List<String> excludedNodesForCapacity = null;
254-
while(true) {
255249
Node node = networkTopology.chooseRandom(NetConstants.ROOT,
256250
excludedNodesForCapacity, excludedNodes, affinityNode, ancestorGen);
257-
>>>>>>> HDDS-1879. Support multiple excluded scopes when choosing datanodes in NetworkTopology.
258251
if (node == null) {
259252
// cannot find the node which meets all constrains
260-
LOG.warn("Failed to find the datanode. excludedNodes:" +
253+
LOG.warn("Failed to find the datanode for container. excludedNodes:" +
261254
(excludedNodes == null ? "" : excludedNodes.toString()) +
262255
", affinityNode:" +
263256
(affinityNode == null ? "" : affinityNode.getNetworkFullPath()));
@@ -279,18 +272,12 @@ private Node chooseNode(List<Node> excludedNodes, Node affinityNode,
279272
" excludedNodes and affinityNode constrains.", null);
280273
}
281274
if (hasEnoughSpace((DatanodeDetails)node, sizeRequired)) {
282-
LOG.warn("Datanode {} is chosen. Required size is {}",
275+
LOG.debug("Datanode {} is chosen for container. Required size is {}",
283276
node.toString(), sizeRequired);
284-
<<<<<<< HEAD
285-
if (excludedNodes != null && excludedNodesForCapacity != null) {
286-
excludedNodes.removeAll(excludedNodesForCapacity);
287-
}
288277
metrics.incrDatanodeChooseSuccessCount();
289278
if (isFallbacked) {
290279
metrics.incrDatanodeChooseFallbackCount();
291280
}
292-
=======
293-
>>>>>>> HDDS-1879. Support multiple excluded scopes when choosing datanodes in NetworkTopology.
294281
return node;
295282
} else {
296283
maxRetry--;

0 commit comments

Comments
 (0)