wgzhao / Addax

Addax is a versatile open-source ETL tool that can seamlessly transfer data between various RDBMS and NoSQL databases, making it an ideal solution for data migration.
https://wgzhao.github.io/Addax/
Apache License 2.0
1.2k stars 304 forks source link

[Bug]: MongoDBReader连接复制集类型mongo报错连接超时 #1036

Closed TongWenbin closed 6 months ago

TongWenbin commented 6 months ago

What happened?

连接分片集群模式的mongodb时正常,但连接复制集模式的mongodb时报超时。 网络没有问题, 集群自身没有问题, 可以通过Navicat等工具正常连接使用,也可以用java代码正常使用,目前只在DataX中不可用

Version

4.0.2

OS Type

Linux (Default)

Java JDK Version

Oracle JDK 1.8.0

Relevant log output

[INFO] 2024-05-16 20:31:44.252 [TaskLogInfo- - [taskAppId=TASK-8797420463360_8-4164148-18272042]-getOutputLogService]  -  -> 2024-05-16 20:31:43.266 [        main] INFO  PerfTrace            - PerfTrace traceId=job_-1, isEnable=false, priority=0
    2024-05-16 20:31:43.267 [        main] INFO  JobContainer         - Addax jobContainer starts job.
    2024-05-16 20:31:43.268 [        main] INFO  JobContainer         - Set jobId = 0
    2024-05-16 20:31:43.419 [       job-0] INFO  cluster              - Cluster created with settings {hosts=[7.215.190.37:8635], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
    2024-05-16 20:31:43.419 [       job-0] INFO  cluster              - Adding discovered server 7.215.190.37:8635 to client view of cluster
    2024-05-16 20:31:43.599 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  connection           - Opened connection [connectionId{localValue:1, serverValue:9921995}] to 7.215.190.37:8635
    2024-05-16 20:31:43.637 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  cluster              - Monitor thread successfully connected to server with description ServerDescription{address=7.215.190.37:8635, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 0]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=34618649, setName='replica', canonicalAddress=192.168.21.82:8635, hosts=[192.168.20.154:8635, 192.168.21.82:8635, 192.168.32.56:8635, 192.168.38.178:8635], passives=[], arbiters=[], primary='192.168.21.82:8635', tagSet=TagSet{[]}, electionId=7fffffff0000000000000003, setVersion=108055, lastWriteDate=Thu May 16 20:31:43 CST 2024, lastUpdateTimeNanos=199484528738046}
    2024-05-16 20:31:43.638 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  cluster              - Discovered cluster type of REPLICA_SET
    2024-05-16 20:31:43.639 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  cluster              - Adding discovered server 192.168.20.154:8635 to client view of cluster
    2024-05-16 20:31:43.639 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  cluster              - Adding discovered server 192.168.21.82:8635 to client view of cluster
    2024-05-16 20:31:43.640 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  cluster              - Adding discovered server 192.168.32.56:8635 to client view of cluster
    2024-05-16 20:31:43.641 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  cluster              - Adding discovered server 192.168.38.178:8635 to client view of cluster
    2024-05-16 20:31:43.642 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  cluster              - Server 7.215.190.37:8635 is no longer a member of the replica set.  Removing from client view of cluster.
    2024-05-16 20:31:43.643 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-7.215.190.37:8635] INFO  cluster              - Canonical address 192.168.21.82:8635 does not match server address.  Removing 7.215.190.37:8635 from client view of cluster
    2024-05-16 20:31:44.084 [       job-0] INFO  JobContainer         - Addax Reader.Job [mongodbreader] do prepare work .
    2024-05-16 20:31:44.084 [       job-0] INFO  JobContainer         - Addax Writer.Job [hdfswriter] do prepare work .
    2024-05-16 20:31:44.220 [       job-0] INFO  JobContainer         - Job set Channel-Number to 1 channels.
    2024-05-16 20:31:44.239 [       job-0] INFO  cluster              - No server chosen by com.mongodb.client.internal.MongoClientDelegate$1@625e134e from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=192.168.38.178:8635, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=192.168.21.82:8635, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=192.168.20.154:8635, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=192.168.32.56:8635, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
[INFO] 2024-05-16 20:32:04.255 [TaskLogInfo- - [taskAppId=TASK-8797420463360_8-4164148-18272042]-getOutputLogService]  -  -> 2024-05-16 20:32:03.650 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-192.168.32.56:8635] INFO  cluster              - Exception in monitor thread while connecting to server 192.168.32.56:8635
    com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
        at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: java.net.SocketTimeoutException: connect timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:607)
        at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
        at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
        ... 3 common frames omitted
    2024-05-16 20:32:03.660 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-192.168.20.154:8635] INFO  cluster              - Exception in monitor thread while connecting to server 192.168.20.154:8635
    com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
        at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: java.net.SocketTimeoutException: connect timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:607)
        at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
        at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
        ... 3 common frames omitted
    2024-05-16 20:32:03.661 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-192.168.21.82:8635] INFO  cluster              - Exception in monitor thread while connecting to server 192.168.21.82:8635
    com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
        at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: java.net.SocketTimeoutException: connect timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:607)
        at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
        at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
        ... 3 common frames omitted
    2024-05-16 20:32:03.663 [cluster-ClusterId{value='6645fcaf9896617c63d5d90c', description='null'}-192.168.38.178:8635] INFO  cluster              - Exception in monitor thread while connecting to server 192.168.38.178:8635
    com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
        at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: java.net.SocketTimeoutException: connect timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:607)
        at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
        at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
        ... 3 common frames omitted
[INFO] 2024-05-16 20:32:14.257 [TaskLogInfo- - [taskAppId=TASK-8797420463360_8-4164148-18272042]-getOutputLogService]  -  -> 2024-05-16 20:32:14.244 [       job-0] INFO  StandAloneJobContainerCommunicator - Total 0 records, 0 bytes | Speed 0B/s, 0 records/s | Error 0 records, 0 bytes |  All Task WaitWriterTime 0.000s |  All Task WaitReaderTime 0.000s | Percentage 0.00%
    2024-05-16 20:32:14.246 [       job-0] ERROR Engine               - Code:[Framework-02], Description:[Addax 引擎运行过程出错,具体原因请参看Addax 运行结束时的错误诊断信息  .].  - Code:[Framework-02], Description:[Addax 引擎运行过程出错,具体原因请参看Addax 运行结束时的错误诊断信息  .].  - com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@625e134e. Client view of cluster state is {type=REPLICA_SET, servers=[{address=192.168.38.178:8635, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=192.168.21.82:8635, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=192.168.20.154:8635, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=192.168.32.56:8635, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
        at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:408)
        at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:123)
        at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(AbstractMultiServerCluster.java:54)
        at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:157)
        at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:105)
        at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:287)
        at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:191)
        at com.mongodb.client.internal.FindIterableImpl.first(FindIterableImpl.java:211)
        at com.wgzhao.addax.plugin.reader.mongodbreader.util.CollectionSplitUtil.isPrimaryIdObjectId(CollectionSplitUtil.java:79)
        at com.wgzhao.addax.plugin.reader.mongodbreader.util.CollectionSplitUtil.doSplit(CollectionSplitUtil.java:62)
        at com.wgzhao.addax.plugin.reader.mongodbreader.MongoDBReader$Job.split(MongoDBReader.java:74)
        at com.wgzhao.addax.core.job.JobContainer.doReaderSplit(JobContainer.java:739)
        at com.wgzhao.addax.core.job.JobContainer.split(JobContainer.java:420)
        at com.wgzhao.addax.core.job.JobContainer.start(JobContainer.java:136)
        at com.wgzhao.addax.core.Engine.start(Engine.java:79)
        at com.wgzhao.addax.core.Engine.entry(Engine.java:137)
        at com.wgzhao.addax.core.Engine.main(Engine.java:175)
     - com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@625e134e. Client view of cluster state is {type=REPLICA_SET, servers=[{address=192.168.38.178:8635, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=192.168.21.82:8635, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=192.168.20.154:8635, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=192.168.32.56:8635, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
        at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:408)
        at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:123)
        at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(AbstractMultiServerCluster.java:54)
        at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:157)
        at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:105)
        at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:287)
        at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:191)
        at com.mongodb.client.internal.FindIterableImpl.first(FindIterableImpl.java:211)
        at com.wgzhao.addax.plugin.reader.mongodbreader.util.CollectionSplitUtil.isPrimaryIdObjectId(CollectionSplitUtil.java:79)
        at com.wgzhao.addax.plugin.reader.mongodbreader.util.CollectionSplitUtil.doSplit(CollectionSplitUtil.java:62)
        at com.wgzhao.addax.plugin.reader.mongodbreader.MongoDBReader$Job.split(MongoDBReader.java:74)
        at com.wgzhao.addax.core.job.JobContainer.doReaderSplit(JobContainer.java:739)
        at com.wgzhao.addax.core.job.JobContainer.split(JobContainer.java:420)
        at com.wgzhao.addax.core.job.JobContainer.start(JobContainer.java:136)
        at com.wgzhao.addax.core.Engine.start(Engine.java:79)
        at com.wgzhao.addax.core.Engine.entry(Engine.java:137)
        at com.wgzhao.addax.core.Engine.main(Engine.java:175)

[INFO] 2024-05-16 20:32:14.577 [TaskLogInfo- - [taskAppId=TASK-8797420463360_8-4164148-18272042]]  - process has exited, execute path:/tmp/dolphinscheduler/exec/process/8243737687296/8797420463360_8/4164148/18272042, processId:103993 ,exitStatusCode:1 ,processWaitForStatus:true ,processExitValue:1
[INFO] 2024-05-16 20:32:15.258 [TaskLogInfo- - [taskAppId=TASK-8797420463360_8-4164148-18272042]-getOutputLogService]  -  -> ==================== DEPRECATED WARNING ========================
    addax.py is deprecated, It's going to be removed in future release.
    As a replacement, you can use addax.sh to run job
    ==================== DEPRECATED WARNING ========================
TongWenbin commented 6 months ago

DataX配置如下,部分信息已去掉

{
    "job": {
        "setting": {
            "speed": {
                "channel": 1
            }
        },
        "content": [{
            "reader": {
                "name": "mongodbreader",
                "parameter": {
                    "address": ["7.215.190.37:8635"],
                    "userName": "XXXXXXXXXX",
                    "userPassword": "XXXXXXXXXXXXX",
                    "dbName": "XXXXXXXXXXXXX",
                    "collectionName": "XXXXXXXXXXXX",
                    "column": [{
                        "name": "_id",
                        "type": "string"
                    },{
                        "name": "DETAIL.name",
                        "type": "document.string"

                    },{
                        "name": "DETAIL.spaceId",
                        "type": "document.string"
                    }
                    ]
                }
            },
          "writer": {
                "name": "hdfswriter"
               XXXXXXXXXXXXXXXXXXXXXX
                }
            },
            "transformer": [
            {
            "name": "dx_groovy",
            "parameter": 
                    {
                 "code": 
                 "for(int i=0;i<record.getColumnNumber();i++){
                            if(record.getColumn(i).getByteSize()!=0){
                                Column column = record.getColumn(i); 
                                def str = column.asString(); 
                                def newStr=null; 
                                newStr=str.replaceAll(\"[\\r\\n\\t]\",\"\"); 
                                record.setColumn(i, new StringColumn(newStr)); 
                            };
                         };
                         return record;",
                 "extraPackage":[]
                    }
            }
          ]
        }]
    }
}
wgzhao commented 6 months ago

下载 mongodbreader-4.1.5-SNAPSHOT.zip,将后缀 .zip 改成 .jar,然后替换 $ADDAX_HOME/plugin/reader/mongodbreader/mongodbreader-<version>.jar 文件后,再试试看是否能解决这个问题。

目前在我本地可以复现你的问题,并已解决,但针对非集群的情况还要更多的测试,确保不会影响其他部署模式的 MongoDB 集群。