HADOOP-14044. Synchronization issue in delegation token cancel functionality. Contributed by Hrishikesh Gadre.
(cherry picked from commit ba75bc7593
)
This commit is contained in:
parent
7baa6dac54
commit
05ed48b75a
|
@ -670,6 +670,26 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
|
||||||
return tokenInfo;
|
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)
|
private DelegationTokenInformation getTokenInfoFromZK(TokenIdent ident)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return getTokenInfoFromZK(ident, false);
|
return getTokenInfoFromZK(ident, false);
|
||||||
|
@ -851,16 +871,9 @@ public abstract class ZKDelegationTokenSecretManager<TokenIdent extends Abstract
|
||||||
DataInputStream in = new DataInputStream(buf);
|
DataInputStream in = new DataInputStream(buf);
|
||||||
TokenIdent id = createIdentifier();
|
TokenIdent id = createIdentifier();
|
||||||
id.readFields(in);
|
id.readFields(in);
|
||||||
try {
|
|
||||||
if (!currentTokens.containsKey(id)) {
|
syncLocalCacheWithZk(id);
|
||||||
// See if token can be retrieved and placed in currentTokens
|
return super.cancelToken(token, canceller);
|
||||||
getTokenInfo(id);
|
|
||||||
}
|
|
||||||
return super.cancelToken(token, canceller);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.error("Exception while checking if token exist !!", e);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addOrUpdateToken(TokenIdent ident,
|
private void addOrUpdateToken(TokenIdent ident,
|
||||||
|
|
Loading…
Reference in New Issue