Repository: hadoop Updated Branches: refs/heads/branch-2.8 0f9f7bb0c -> 83eacccc1
HADOOP-14044. Synchronization issue in delegation token cancel functionality. Contributed by Hrishikesh Gadre. (cherry picked from commit ba75bc759334c8987e5f7dd4b21d025f0cccbde7) (cherry picked from commit 05ed48b75a53df9ad4456ecddc981250006540ae) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/83eacccc Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/83eacccc Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/83eacccc Branch: refs/heads/branch-2.8 Commit: 83eacccc178d74eaed0e2e1287afde195678e693 Parents: 0f9f7bb Author: Xiao Chen <[email protected]> Authored: Fri Feb 3 17:13:53 2017 -0800 Committer: Xiao Chen <[email protected]> Committed: Mon Jul 10 13:48:12 2017 -0700 ---------------------------------------------------------------------- .../ZKDelegationTokenSecretManager.java | 33 ++++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/83eacccc/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java index 6c66e98..4a7ddb2 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java @@ -670,6 +670,26 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract return tokenInfo; } + /** + * This method synchronizes the state of a delegation token information in + * local cache with its actual value in Zookeeper. + * + * @param ident Identifier of the token + */ + private synchronized void syncLocalCacheWithZk(TokenIdent ident) { + try { + DelegationTokenInformation tokenInfo = getTokenInfoFromZK(ident); + if (tokenInfo != null && !currentTokens.containsKey(ident)) { + currentTokens.put(ident, tokenInfo); + } else if (tokenInfo == null && currentTokens.containsKey(ident)) { + currentTokens.remove(ident); + } + } catch (IOException e) { + LOG.error("Error retrieving tokenInfo [" + ident.getSequenceNumber() + + "] from ZK", e); + } + } + private DelegationTokenInformation getTokenInfoFromZK(TokenIdent ident) throws IOException { return getTokenInfoFromZK(ident, false); @@ -851,16 +871,9 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract DataInputStream in = new DataInputStream(buf); TokenIdent id = createIdentifier(); id.readFields(in); - try { - if (!currentTokens.containsKey(id)) { - // See if token can be retrieved and placed in currentTokens - getTokenInfo(id); - } - return super.cancelToken(token, canceller); - } catch (Exception e) { - LOG.error("Exception while checking if token exist !!", e); - return id; - } + + syncLocalCacheWithZk(id); + return super.cancelToken(token, canceller); } private void addOrUpdateToken(TokenIdent ident, --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
