You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/10/29 10:15:20 UTC

[GitHub] [rocketmq] ztelur commented on a change in pull request #3422: [ISSUE #2978] Implement gRPC protocol for rocketmq

ztelur commented on a change in pull request #3422:
URL: https://github.com/apache/rocketmq/pull/3422#discussion_r739111346



##########
File path: grpc/src/main/java/org/apache/rocketmq/grpc/server/GrpcServer.java
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.rocketmq.grpc.server;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.grpc.BindableService;
+import io.grpc.Server;
+import io.grpc.ServerServiceDefinition;
+import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
+import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
+import io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoopGroup;
+import io.grpc.netty.shaded.io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.grpc.netty.shaded.io.netty.handler.ssl.ClientAuth;
+import io.grpc.netty.shaded.io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+import io.grpc.protobuf.services.ChannelzService;
+import io.netty.handler.ssl.util.SelfSignedCertificate;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.cert.CertificateException;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import javax.net.ssl.SSLException;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+import org.apache.rocketmq.remoting.netty.TlsSystemConfig;
+
+public class GrpcServer {
+    private static final InternalLogger LOGGER = InternalLoggerFactory.getLogger(LoggerName.GRPC_LOGGER_NAME);
+
+    private final GrpcServerConfig grpcServerConfig;
+
+    private final Server server;
+
+    private final ThreadPoolExecutor executor;
+
+    public GrpcServer(GrpcServerConfig grpcServerConfig, BindableService service,
+        boolean useTls) throws CertificateException, SSLException {
+        this.grpcServerConfig = grpcServerConfig;
+        int processorNumber = Runtime.getRuntime()
+            .availableProcessors();
+        executor = new ThreadPoolExecutor(grpcServerConfig.getExecutorCoreThreadNumber(),
+            grpcServerConfig.getExecutorMaxThreadNumber(), 1, TimeUnit.MINUTES,
+            new LinkedBlockingQueue<>(grpcServerConfig.getExecutorQueueLength()),
+            new ThreadFactoryBuilder().setNameFormat("grpc-server-thread-%d")
+                .build(),
+            new ThreadPoolExecutor.DiscardOldestPolicy());

Review comment:
       should use DiscardOldestPolicy? 

##########
File path: broker/src/main/java/org/apache/rocketmq/broker/loadbalance/AssignmentManager.java
##########
@@ -112,14 +116,28 @@ public void updateTopicRouteInfoFromNameServer() {
     public boolean updateTopicRouteInfoFromNameServer(final String topic) {
         try {
             TopicRouteData topicRouteData = this.mQClientAPIImpl.getTopicRouteInfoFromNameServer(topic, 1000 * 3);
+            Map<String, BrokerData> brokerDataMap = new HashMap<>();
+            for (BrokerData brokerData : topicRouteData.getBrokerDatas()) {

Review comment:
       should move it into topicRouteData != null condition branch ? 




-- 
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: dev-unsubscribe@rocketmq.apache.org

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