Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements IgniteDiscovery
/** Ssl message pattern for StreamCorruptedException. */
private static Pattern sslMsgPattern = Pattern.compile("invalid stream header: 150\\d0\\d00");

/** Number of resolved IP finder addresses that triggers a warning about potentially slow node join. */
static final int ADDRS_WARN_THRESHOLD = 20;

/** Local address. */
protected String locAddr;

Expand Down Expand Up @@ -1964,6 +1967,13 @@ protected Collection<InetSocketAddress> resolvedAddresses() throws IgniteSpiExce
}
}

if (res.size() > ADDRS_WARN_THRESHOLD)
LT.warn(log, "Long list of addresses resolved from IP finder: connecting to an unavailable address " +
"usually blocks until socket timeout instead of failing fast (on Windows OS this may look like " +
"the node hangs for a while), so every unreachable address in the list slows down node join or " +
"reconnection. Make sure that all addresses are correct and reachable, consider reducing the " +
"address list or increasing 'joinTimeout' to bound the wait [addrsCnt=" + res.size() + "]");

if (!res.isEmpty() && !skipAddrsRandomization)
Collections.shuffle(res);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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.ignite.spi.discovery.tcp;

import java.util.ArrayList;
import java.util.List;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
import org.apache.ignite.testframework.GridStringLogger;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;

/**
* Tests that a warning is printed when the IP finder has a long list of addresses (see IGNITE-1025).
*/
public class TcpDiscoveryLongAddressListWarnSelfTest extends GridCommonAbstractTest {
/** Base port for unavailable addresses. */
private static final int UNAVAILABLE_PORT = 49_152;

/** */
private GridStringLogger strLog;

/** */
private int addrCnt;

/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

List<String> addrs = new ArrayList<>(addrCnt);

for (int i = 0; i < addrCnt; i++)
addrs.add("127.0.0.1:" + (UNAVAILABLE_PORT + i));

TcpDiscoverySpi spi = new TcpDiscoverySpi()
.setIpFinder(new TcpDiscoveryVmIpFinder(true).setAddresses(addrs))
.setJoinTimeout(1_000);

cfg.setDiscoverySpi(spi);
cfg.setGridLogger(strLog);

return cfg;
}

/**
* @throws Exception If failed.
*/
@Test
public void testWarnOnLongAddressList() throws Exception {
strLog = new GridStringLogger();

addrCnt = TcpDiscoverySpi.ADDRS_WARN_THRESHOLD + 1;

startGrid(0);

String log = strLog.toString();

assertTrue("Warning must be printed to log: " + log,
log.contains("Long list of addresses resolved from IP finder"));

stopAllGrids();
}

/**
* @throws Exception If failed.
*/
@Test
public void testNoWarnOnShortAddressList() throws Exception {
strLog = new GridStringLogger();

addrCnt = 3;

startGrid(0);

String log = strLog.toString();

assertFalse("Warning must not be printed to log: " + log,
log.contains("Long list of addresses resolved from IP finder"));

stopAllGrids();
}
}
Loading