morningman commented on code in PR #16073:
URL: https://github.com/apache/doris/pull/16073#discussion_r1103793147


##########
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/TokenManager.java:
##########
@@ -0,0 +1,133 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.load.loadv2;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.thrift.FrontendService;
+import org.apache.doris.thrift.TMySqlLoadAcquireTokenResult;
+import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.thrift.TStatusCode;
+
+import com.google.common.collect.EvictingQueue;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.thrift.TException;
+import org.apache.thrift.transport.TTransportException;
+
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+public class TokenManager {
+    private static final Logger LOG = LogManager.getLogger(TokenManager.class);
+
+    private final int thriftTimeoutMs = 300 * 1000;
+    private final EvictingQueue<String> tokenQueue;
+    private final ScheduledExecutorService tokenGenerator;
+
+    public TokenManager() {
+        this.tokenQueue = EvictingQueue.create(Config.token_queue_size);
+        // init one token to avoid async issue.
+        this.tokenQueue.offer(generateNewToken());
+        this.tokenGenerator = Executors.newScheduledThreadPool(1);
+        this.tokenGenerator.scheduleAtFixedRate(() -> {
+            tokenQueue.offer(generateNewToken());
+        }, 0, Config.token_generate_period_hour, TimeUnit.HOURS);
+    }
+
+    private String generateNewToken() {
+        return UUID.randomUUID().toString();
+    }
+
+    // this method only will be called in master node, since stream load only 
send message to master.
+    public boolean checkAuthToken(String token) {
+        return tokenQueue.contains(token);
+    }
+
+    public String acquireToken() {

Review Comment:
   Better throw exception when acquiring token failed, instead of returning 
`null`.
   It is every error prone and I saw some place which not handle `null` value.



##########
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/TokenManager.java:
##########
@@ -0,0 +1,133 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.load.loadv2;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.thrift.FrontendService;
+import org.apache.doris.thrift.TMySqlLoadAcquireTokenResult;
+import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.thrift.TStatusCode;
+
+import com.google.common.collect.EvictingQueue;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.thrift.TException;
+import org.apache.thrift.transport.TTransportException;
+
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+public class TokenManager {
+    private static final Logger LOG = LogManager.getLogger(TokenManager.class);
+
+    private final int thriftTimeoutMs = 300 * 1000;
+    private final EvictingQueue<String> tokenQueue;
+    private final ScheduledExecutorService tokenGenerator;
+
+    public TokenManager() {
+        this.tokenQueue = EvictingQueue.create(Config.token_queue_size);
+        // init one token to avoid async issue.
+        this.tokenQueue.offer(generateNewToken());
+        this.tokenGenerator = Executors.newScheduledThreadPool(1);
+        this.tokenGenerator.scheduleAtFixedRate(() -> {
+            tokenQueue.offer(generateNewToken());
+        }, 0, Config.token_generate_period_hour, TimeUnit.HOURS);
+    }
+
+    private String generateNewToken() {
+        return UUID.randomUUID().toString();
+    }
+
+    // this method only will be called in master node, since stream load only 
send message to master.
+    public boolean checkAuthToken(String token) {
+        return tokenQueue.contains(token);
+    }
+
+    public String acquireToken() {
+        if (Env.getCurrentEnv().isMaster() || FeConstants.runningUnitTest) {
+            return tokenQueue.peek();
+        } else {
+            try {
+                return acquireTokenFromMaster();
+            } catch (TException e) {
+                LOG.warn("acquire token error", e);
+                return null;
+            }
+        }
+    }
+
+    public String acquireTokenFromMaster() throws TException {
+        TNetworkAddress thriftAddress = getMasterAddress();
+
+        FrontendService.Client client = getClient(thriftAddress);
+
+        LOG.info("Send acquire token to Master {}", thriftAddress);

Review Comment:
   ```suggestion
           LOG.debug("Send acquire token to Master {}", thriftAddress);
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java:
##########
@@ -349,6 +349,11 @@ public boolean isForwardToMaster() {
             return false;
         }
 
+        // mysql load don't format to master.
+        if (parsedStmt instanceof LoadStmt && ((LoadStmt) 
parsedStmt).isMysqlLoad()) {
+            return false;

Review Comment:
   You can override the `getRedirectStatus()` in LoadStmt to do this.



##########
fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java:
##########
@@ -349,6 +349,11 @@ public boolean isForwardToMaster() {
             return false;
         }
 
+        // mysql load don't format to master.

Review Comment:
   ```suggestion
           // mysql load don't forward to master.
   ```



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to