vikaskr22 commented on code in PR #8888:
URL: https://github.com/apache/hadoop/pull/8888#discussion_r4443991150
##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java:
##########
@@ -501,27 +504,39 @@ private int incrSharedCount(SharedCount sharedCount, int
batchSize)
@Override
protected int incrementDelegationTokenSeqNum() {
- // The secret manager will keep a local range of seq num which won't be
- // seen by peers, so only when the range is exhausted it will ask zk for
- // another range again
- if (currentSeqNum >= currentMaxSeqNum) {
- try {
- // after a successful batch request, we can get the range starting
point
- currentSeqNum = incrSharedCount(delTokSeqCounter, seqNumBatchSize);
- currentMaxSeqNum = currentSeqNum + seqNumBatchSize;
- LOG.info("Fetched new range of seq num, from {} to {} ",
- currentSeqNum+1, currentMaxSeqNum);
- } catch (InterruptedException e) {
- // The ExpirationThread is just finishing.. so dont do anything..
- LOG.debug(
- "Thread interrupted while performing token counter increment", e);
- Thread.currentThread().interrupt();
- } catch (Exception e) {
- throw new RuntimeException("Could not increment shared counter !!", e);
+ synchronized (sequenceNumberLock) {
+ // A range belongs exclusively to this manager. Never consume a number
+ // beyond the range unless its replacement was successfully reserved.
+ if (currentSeqNum >= currentMaxSeqNum) {
+ try {
+ int start = incrSharedCount(delTokSeqCounter, seqNumBatchSize);
Review Comment:
Code to reserve seqNum range is duplicate at two places,
can following code be kept in a separate method say
```
private void refillTokenSequenceRangeIfNeeded() {
try {
int start = incrSharedCount(delTokSeqCounter, seqNumBatchSize);
currentSeqNum = start;
currentMaxSeqNum = start + seqNumBatchSize;
LOG.info("Fetched new range of seq num, from {} to {}",
currentSeqNum + 1, currentMaxSeqNum);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted reserving token
sequence range", e);
} catch (Exception e) {
throw new IllegalStateException("Could not increment shared
counter", e);
}
}
```
and called from both places , from init() block and from
incrementDelegationTokenSeqNum() ?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]