Skip to content

Commit

Permalink
[fix](load) acquire latest token instead of oldest token in TokenMana…
Browse files Browse the repository at this point in the history
…ger (#34424)

* [fix](load) acquire latest token instead of oldest token

* fixup
  • Loading branch information
kaijchen authored and Doris-Extras committed May 6, 2024
1 parent aa156f0 commit b7b843d
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class TokenManager {

private int thriftTimeoutMs = 300 * 1000;
private EvictingQueue<String> tokenQueue;
private String latestToken;
private ScheduledExecutorService tokenGenerator;

public TokenManager() {
Expand All @@ -52,20 +53,25 @@ public TokenManager() {
public void start() {
this.tokenQueue = EvictingQueue.create(Config.token_queue_size);
// init one token to avoid async issue.
this.tokenQueue.offer(generateNewToken());
this.addNewToken(generateNewToken());
this.tokenGenerator = Executors.newScheduledThreadPool(1,
new CustomThreadFactory("token-generator"));
this.tokenGenerator.scheduleAtFixedRate(() -> tokenQueue.offer(generateNewToken()), 0,
this.tokenGenerator.scheduleAtFixedRate(() -> this.addNewToken(generateNewToken()), 0,
Config.token_generate_period_hour, TimeUnit.HOURS);
}

private void addNewToken(String token) {
tokenQueue.offer(token);
latestToken = token;
}

private String generateNewToken() {
return UUID.randomUUID().toString();
}

public String acquireToken() throws UserException {
if (Env.getCurrentEnv().isMaster() || FeConstants.runningUnitTest) {
return tokenQueue.peek();
return latestToken;
} else {
try {
return acquireTokenFromMaster();
Expand Down

0 comments on commit b7b843d

Please sign in to comment.