fengnanli commented on a change in pull request #2110:
URL: https://github.com/apache/hadoop/pull/2110#discussion_r447993824



##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/AbstractDelegationTokenSecretManager.java
##########
@@ -726,4 +732,41 @@ public TokenIdent decodeTokenIdentifier(Token<TokenIdent> 
token) throws IOExcept
     return token.decodeIdentifier();
   }
 
+  /**
+   * Return top token real owners list as well as the tokens count.
+   *
+   * @param n top number of users
+   * @return map of owners to counts
+   */
+  public List<NameValuePair> getTopTokenRealOwners(int n) {
+    Map<String, Integer> tokenOwnerMap = new HashMap<>();
+    for (TokenIdent id : currentTokens.keySet()) {
+      String realUser;
+      if (id.getRealUser() != null && !id.getRealUser().toString().isEmpty()) {
+        realUser = id.getRealUser().toString();
+      } else {
+        // if there is no real user -> this is a non proxy user
+        // the user itself is the real owner
+        realUser = id.getUser().getUserName();
+      }
+      tokenOwnerMap.put(realUser, tokenOwnerMap.getOrDefault(realUser, 0)+1);
+    }
+    n = Math.min(n, tokenOwnerMap.size());
+    if (n == 0) {
+      return new LinkedList<>();
+    }
+
+    TopN topN = new TopN(n);
+    for (Map.Entry<String, Integer> entry : tokenOwnerMap.entrySet()) {
+      topN.offer(new NameValuePair(
+          entry.getKey(), entry.getValue()));
+    }
+
+    List<NameValuePair> list = new LinkedList<>();

Review comment:
       There is a reverse op and I think reverse linked list is faster without 
additional space.
   Not sure how java implement the reverse array list, but I think it will 
introduce copy and reassign.




----------------------------------------------------------------
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.

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

Reply via email to