sunchao commented on a change in pull request #2110: URL: https://github.com/apache/hadoop/pull/2110#discussion_r448022518
########## 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: Reverse shouldn't need extra space - it uses two indexes from begin and end of the array and swaps elements. I don't see real difference between the two for the reverse. ########## 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) { Review comment: Can we update the `TopN` queue when creating/deleting tokens? we are just paying an extra constant cost for updating that which I think is fine. Even though it is using concurrent hashmap, I'm not sure how much performance impact will be if one thread is iterating over the key set while others want to updating the map. ---------------------------------------------------------------- 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