From 1f400b9115d10b6c09a5123cf04207b5d5c69e85 Mon Sep 17 00:00:00 2001 From: "Chen, Junjie" Date: Wed, 7 Aug 2019 11:51:36 +0800 Subject: [PATCH] HDDS-1553: Add metric for rack aware placement policy --- .../SCMContainerPlacementRackAware.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java index e126f27c1f1dd..bd2c2ec1c3405 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java @@ -53,6 +53,9 @@ public final class SCMContainerPlacementRackAware extends SCMCommonPolicy { private boolean fallback; private static final int RACK_LEVEL = 1; private static final int MAX_RETRY= 3; + private int numOfTotalRequests = 0; + private int numOfSuccessRequests = 0; + private int numOfSuccessRequestsWithCondition = 0; /** * Constructs a Container Placement with rack awareness. @@ -93,6 +96,7 @@ public List chooseDatanodes( List excludedNodes, List favoredNodes, int nodesRequired, final long sizeRequired) throws SCMException { Preconditions.checkArgument(nodesRequired > 0); + numOfTotalRequests += nodesRequired; int datanodeCount = networkTopology.getNumOfLeafNode(NetConstants.ROOT); int excludedNodesCount = excludedNodes == null ? 0 : excludedNodes.size(); @@ -125,6 +129,7 @@ public List chooseDatanodes( } chosenNodes.add(firstNode); nodesRequired--; + numOfSuccessRequests++; if (nodesRequired == 0) { return Arrays.asList(chosenNodes.toArray(new DatanodeDetails[0])); } @@ -142,6 +147,7 @@ public List chooseDatanodes( } chosenNodes.add(secondNode); nodesRequired--; + numOfSuccessRequests++; if (nodesRequired == 0) { return Arrays.asList(chosenNodes.toArray(new DatanodeDetails[0])); } @@ -170,6 +176,8 @@ public List chooseDatanodes( } chosenNodes.add(firstNode); nodesRequired--; + numOfSuccessRequests++; + numOfSuccessRequestsWithCondition++; if (nodesRequired == 0) { return Arrays.asList(chosenNodes.toArray(new DatanodeDetails[0])); } @@ -206,6 +214,8 @@ public List chooseDatanodes( chosenNodes.add(secondNode); mutableExcludedNodes.add(secondNode); nodesRequired--; + numOfSuccessRequests++; + numOfSuccessRequestsWithCondition++; if (nodesRequired == 0) { return Arrays.asList(chosenNodes.toArray(new DatanodeDetails[0])); } @@ -334,9 +344,45 @@ private List chooseNodes(List excludedNodes, chosenNodes.add(chosenNode); } nodesRequired--; + numOfSuccessRequests++; + numOfSuccessRequestsWithCondition++; if (nodesRequired == 0) { return Arrays.asList(chosenNodes.toArray(new DatanodeDetails[0])); } } } + + /** + * Get the total number of total requests. + * + * + * @return the total number of requests for data node. + */ + public int getNumOfTotalRequests() { + return numOfTotalRequests; + } + + /** + * Get the number of requests which return data node successfully. + * + * + * @return the number of requests which return data node successfully + */ + public int getGetNumOfSuccessRequests() { + return numOfSuccessRequests; + } + + /** + * Get the number of requests with conditions and return data node + * successfully. + * + * + * @return the number of requests with conditions and return data node + * successfully + */ + public int getNumOfSuccessRequestsWithCondition() { + return numOfSuccessRequestsWithCondition; + } + + }