You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/05/12 12:10:50 UTC

[shardingsphere] branch master updated: Fix sonar issue CDCClient (#25621)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e1842ec042  Fix sonar issue CDCClient (#25621)
6e1842ec042 is described below

commit 6e1842ec042658f5e2242d7e72551dd539486e32
Author: Xinze Guo <10...@users.noreply.github.com>
AuthorDate: Fri May 12 20:10:43 2023 +0800

     Fix sonar issue CDCClient (#25621)
    
    * Fix sonar issue CDCClient
---
 .../shardingsphere/data/pipeline/cdc/client/CDCClient.java  | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/kernel/data-pipeline/cdc/client/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/client/CDCClient.java b/kernel/data-pipeline/cdc/client/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/client/CDCClient.java
index 0ba54235744..83e1aebd33d 100644
--- a/kernel/data-pipeline/cdc/client/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/client/CDCClient.java
+++ b/kernel/data-pipeline/cdc/client/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/client/CDCClient.java
@@ -28,6 +28,7 @@ import io.netty.handler.codec.protobuf.ProtobufDecoder;
 import io.netty.handler.codec.protobuf.ProtobufEncoder;
 import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
 import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.data.pipeline.cdc.client.handler.CDCRequestHandler;
 import org.apache.shardingsphere.data.pipeline.cdc.client.handler.LoginRequestHandler;
@@ -35,7 +36,6 @@ import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.StartCDCClie
 import org.apache.shardingsphere.data.pipeline.cdc.protocol.response.CDCResponse;
 import org.apache.shardingsphere.data.pipeline.cdc.protocol.response.DataRecordResult.Record;
 
-import java.net.ConnectException;
 import java.util.List;
 import java.util.function.Consumer;
 
@@ -77,6 +77,7 @@ public final class CDCClient {
         startInternal(parameter.getAddress(), parameter.getPort());
     }
     
+    @SneakyThrows(InterruptedException.class)
     private void startInternal(final String address, final int port) {
         Bootstrap bootstrap = new Bootstrap();
         NioEventLoopGroup group = new NioEventLoopGroup();
@@ -96,17 +97,9 @@ public final class CDCClient {
                         channel.pipeline().addLast(new CDCRequestHandler(parameter, consumer));
                     }
                 });
-        ChannelFuture future = bootstrap.connect(address, port);
-        future.addListener(f -> {
-            if (!f.isSuccess() && f.cause() instanceof ConnectException) {
-                log.error("CDC connect failed", f.cause());
-                future.channel().close();
-            }
-        });
         try {
+            ChannelFuture future = bootstrap.connect(address, port).sync();
             future.channel().closeFuture().sync();
-        } catch (final InterruptedException ex) {
-            log.warn("CDC client interrupted", ex);
         } finally {
             group.shutdownGracefully();
         }