diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/TokenManager.java b/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/TokenManager.java index ca714d66b29d29..21e9f9b04342b3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/TokenManager.java +++ b/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/TokenManager.java @@ -44,6 +44,7 @@ public class TokenManager { private int thriftTimeoutMs = 300 * 1000; private EvictingQueue tokenQueue; + private String latestToken; private ScheduledExecutorService tokenGenerator; public TokenManager() { @@ -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();