почему mongoClient пытается подключиться к арбитру - PullRequest
0 голосов
/ 12 февраля 2020

Я использую Spring Boot и mongoClient для подключения к реплике go mon. Вот часть моего кода для создания MongoDbFactory:

val serverAddresses = new ArrayList<ServerAddress>();
for (val address : mongoProperties.getCluster()) {
    serverAddresses.add(new ServerAddress(address.getHost(), address.getPort()));
        }
val clusterSettings = ClusterSettings.builder()
        .mode(ClusterConnectionMode.MULTIPLE)
        .hosts(serverAddresses);
mongoClientSettings.applyToClusterSettings(builder -> builder.applySettings(clusterSettings.build()));

val mongoClient = MongoClients.create(mongoClientSettings.build());
return new SimpleMongoClientDbFactory(mongoClient, mongoProperties.getDatabase());

У меня есть 2 сервера и 1 арбитр в replicaSet, и я даю один адрес реплики mon go на адрес serverAddresses, журнал показывает, что mon go распознал информацию реплики, например:

2020-02-12 11:21:43.946  INFO 7848 --- [.168.0.10:27018] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=192.168.0.10:27018, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 3]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=127121500, setName='replica-mongo', canonicalAddress=192.168.0.10:27018, hosts=[192.168.0.116:27018, 192.168.0.10:27018], passives=[], arbiters=[mongo-arbiter:27017], primary='192.168.0.10:27018', tagSet=TagSet{[]}, electionId=7fffffff0000000000000004, setVersion=8, lastWriteDate=Wed Feb 12 11:21:37 CST 2020, lastUpdateTimeNanos=183088266525100}
2020-02-12 11:21:43.948  INFO 7848 --- [.168.0.10:27018] org.mongodb.driver.cluster               : Discovered cluster type of REPLICA_SET

, и при попытке подключиться к серверу 2 mon go ошибка не возникла, но при попытке подключиться к арбитору выдает предупреждение:

2020-02-12 11:22:43.951  WARN 7848 --- [imer-3-thread-1] org.mongodb.driver.connection            : Exception thrown during connection pool background maintenance task

com.mongodb.MongoSocketException: mongo-arbiter
    at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:50) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.DefaultConnectionPool$UsageTrackingInternalConnectionItemFactory.create(DefaultConnectionPool.java:530) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.DefaultConnectionPool$UsageTrackingInternalConnectionItemFactory.create(DefaultConnectionPool.java:518) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.ConcurrentPool.createNewAndReleasePermitIfFailure(ConcurrentPool.java:181) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.ConcurrentPool.ensureMinSize(ConcurrentPool.java:175) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.DefaultConnectionPool$3.run(DefaultConnectionPool.java:317) ~[mongodb-driver-core-3.11.2.jar:na]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_181]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_181]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_181]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_181]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
Caused by: java.net.UnknownHostException: mongo-arbiter
    at java.net.InetAddress.getAllByName0(InetAddress.java:1280) ~[na:1.8.0_181]
    at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[na:1.8.0_181]
    at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[na:1.8.0_181]
    at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203) ~[mongodb-driver-core-3.11.2.jar:na]
    ... 16 common frames omitted

почему mongoClient пытается подключиться к арбитру? и как мне его остановить?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...