首页 > 解决方案 > 发现 Apache 点燃错误的 IP

问题描述

我在测试容器中运行 Apache Ignite 实例,如下所示:

GenericContainer<?> apacheIgniteContainer =new GenericContainer<>("apacheignite/ignite")
                .withExposedPorts(10800, 47100, 47500);

            apacheIgniteContainer.setPortBindings(Arrays.asList("10800:10800", "47100:47100", "47500:47500"));
            apacheIgniteContainer.start();

这是我的配置:

@Bean
public Ignite igniteInstance() {
    return Ignition.start(igniteConfiguration());
}

    private IgniteConfiguration igniteConfiguration() {
    IgniteConfiguration igniteConfiguration = new IgniteConfiguration();

    igniteConfiguration.setFailureDetectionTimeout(DEFAULT_TIMEOUT);
    igniteConfiguration.setDiscoverySpi(tcpDiscoverySpi());
    igniteConfiguration.setClientMode(false);
    igniteConfiguration.setCacheConfiguration(cacheConfiguration());
    igniteConfiguration.setLocalHost(LOCALHOST);

    TcpCommunicationSpi communicationSpi = new TcpCommunicationSpi();
    communicationSpi.setLocalAddress(LOCALHOST);

    igniteConfiguration.setCommunicationSpi(communicationSpi);

    return igniteConfiguration;
}

private TcpDiscoveryVmIpFinder tcpDiscoveryVmIpFinder() {
    TcpDiscoveryVmIpFinder tcpDiscoveryVmIpFinder = new TcpDiscoveryVmIpFinder(true);
    tcpDiscoveryVmIpFinder.setAddresses((Arrays.asList(LOCALHOST)));

    return tcpDiscoveryVmIpFinder;
}

private TcpDiscoverySpi tcpDiscoverySpi() {
    TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();

    tcpDiscoverySpi.setIpFinder(tcpDiscoveryVmIpFinder());
    tcpDiscoverySpi.setLocalAddress(LOCALHOST);
    tcpDiscoverySpi.setLocalPort(10800);

    return tcpDiscoverySpi;
}

private CacheConfiguration cacheConfiguration() {
    CacheConfiguration cacheConfiguration = new CacheConfiguration("exampleCache");
    cacheConfiguration.setIndexedTypes(Long.class, Example.class);

    return cacheConfiguration;
}

问题是我只通过 LOCALHOST 来发现/通信服务,但是每次集成测试开始时都注册了错误的 IP 地址。以下是日志:

07:20:21.376 [exchange-worker-#48] WARN  [] o.a.i.s.c.t.TcpCommunicationSpi - Connect timed out (consider increasing 'failureDetectionTimeout' configuration property) [addr=/172.17.0.5:47100, failureDetectionTimeout=30000]
07:20:40.267 [main] WARN  [] o.a.i.i.p.c.GridCachePartitionExchangeManager - Still waiting for initial partition map exchange [fut=GridDhtPartitionsExchangeFuture [firstDiscoEvt=DiscoveryEvent [evtNode=TcpDiscoveryNode [id=3ad0b9b8-6f30-4e77-9874-e766dd266f15, addrs=[127.0.0.1], sockAddrs=[/127.0.0.1:0], discPort=0, order=2, intOrder=0, lastExchangeTime=1580970000048, loc=true, ver=2.7.6#20190911-sha1:21f7ca41, isClient=true], topVer=2, nodeId8=3ad0b9b8, msg=null, type=NODE_JOINED, tstamp=1580970000227], crd=TcpDiscoveryNode [id=ae6dd269-fbb8-413e-ad2e-7ed9e2ae2495, addrs=[127.0.0.1, 172.17.0.5], sockAddrs=[/172.17.0.5:47500, 624f07442eab/52.18.154.42:47500, /127.0.0.1:47500], discPort=47500, order=1, intOrder=1, lastExchangeTime=1580970000164, loc=false, ver=2.7.6#20190911-sha1:21f7ca41, isClient=false], exchId=GridDhtPartitionExchangeId [topVer=AffinityTopologyVersion [topVer=2, minorTopVer=0], discoEvt=DiscoveryEvent [evtNode=TcpDiscoveryNode [id=3ad0b9b8-6f30-4e77-9874-e766dd266f15, addrs=[127.0.0.1], sockAddrs=[/127.0.0.1:0], discPort=0, order=2, intOrder=0, lastExchangeTime=1580970000048, loc=true, ver=2.7.6#20190911-sha1:21f7ca41, isClient=true], topVer=2, nodeId8=3ad0b9b8, msg=null, type=NODE_JOINED, tstamp=1580970000227], nodeId=3ad0b9b8, evt=NODE_JOINED], added=true, initFut=GridFutureAdapter [ignoreInterrupts=false, state=INIT, res=null, hash=337147080], init=false, lastVer=null, partReleaseFut=null, exchActions=ExchangeActions [startCaches=null, stopCaches=null, startGrps=[], stopGrps=[], resetParts=null, stateChangeRequest=null], affChangeMsg=null, initTs=1580970000258, centralizedAff=false, forceAffReassignment=false, exchangeLocE=null, cacheChangeFailureMsgSent=false, done=false, state=CLIENT, registerCachesFuture=null, partitionsSent=false, partitionsReceived=false, delayedLatestMsg=null, afterLsnrCompleteFut=GridFutureAdapter [ignoreInterrupts=false, state=INIT, res=null, hash=441482912], evtLatch=0, remaining=[ae6dd269-fbb8-413e-ad2e-7ed9e2ae2495], super=GridFutureAdapter [ignoreInterrupts=false, state=INIT, res=null, hash=114452799]]]

...

07:20:42.396 [exchange-worker-#48] WARN  [] o.a.i.s.c.t.TcpCommunicationSpi - Connect timed out (consider increasing 'failureDetectionTimeout' configuration property) [addr=624f07442eab/52.18.154.42:47100, failureDetectionTimeout=30000]
07:20:42.430 [grid-nio-worker-tcp-comm-0-#32] INFO  [] o.a.i.s.c.t.TcpCommunicationSpi - Established outgoing communication connection [locAddr=/127.0.0.1:59666, rmtAddr=/127.0.0.1:47100]

所以起初它尝试连接:172.17.0.5:47100(我不知道这个地址来自哪里)并且它失败了。在此之后,它会尝试连接到正确的 IP(本地主机),然后测试通过。所以我的问题是为什么它尝试连接到第一个 IP (172.17.0.5:47100) - 我什至没有指定它。

标签: javaspringdockerignitetestcontainers

解决方案


每个节点都绑定到以下两个端口:

  • 发现(默认为 47500)
  • 通讯(默认47100)

同样在您的情况下,您似乎决定公开一个 JDBC/ODBC/Thin 客户端端口,即 10800。

如果要使用 localhost 接口工作,则需要在发现和通信中指定。因此,您需要在配置中添加类似这样的内容:

TcpCommunicationSpi communicationSpi = new TcpCommunicationSpi();
communicationSpi.setLocalAddress(LOCALHOST);

igniteCfg.setCommunicationSpi(communicationSpi);

另外,我对您的发现 SPI 配置有以下两个担忧:

  1. DiscoverySPI 尝试连接到端口 10800。这是 JDBC 的端口。它应该匹配其他节点的发现绑定到的端口(默认为 47500)。
  2. 您使用多播 IP 查找器。它可以使您的节点连接到意外节点。考虑使用静态 IP 查找器。

您可以在文档中找到更多信息:https ://www.gridgain.com/docs/latest/developers-guide/clustering/tcp-ip-discovery


推荐阅读