尝试在 Infinispan 环境中对 JGroups 使用 TCPPING 失败,因为地址为 Transport.getAddress() 为空
Posted
技术标签:
【中文标题】尝试在 Infinispan 环境中对 JGroups 使用 TCPPING 失败,因为地址为 Transport.getAddress() 为空【英文标题】:Trying to use TCPPING for JGroups in a Infinispan env fail as address is Transport.getAddress() is null 【发布时间】:2021-11-14 23:52:21 【问题描述】:我正在尝试设置一个复制的 Infinispan 嵌入式缓存。
使用演示代码以编程方式设置缓存时,一切正常(https://github.com/infinispan/infinispan-simple-tutorials/tree/main/infinispan-embedded/cache-replicated)
现在,我想将其配置为使用已定义的初始主机列表。
所以,我将代码稍微更改为:
public class TestGenerate
public static void main(String[] args) throws InterruptedException
// Setup up a clustered cache manager
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
GlobalConfiguration globalConfiguration = global.transport().defaultTransport().addProperty("configurationFile", "jgroups.xml").build();
// Initialize the cache manager
DefaultCacheManager cacheManager = new DefaultCacheManager(globalConfiguration);
// Create a replicated synchronous configuration
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.REPL_SYNC);
Configuration cacheConfig = builder.build();
// Create a cache
Cache<String, String> cache = cacheManager.administration()
.withFlags(CacheContainerAdmin.AdminFlag.VOLATILE)
.getOrCreateCache("cache", cacheConfig);
// Store the current node address in some random keys
for(int i=0; i < 10; i++)
cache.put(UUID.randomUUID().toString(), cacheManager.getNodeAddress());
// Display the current cache contents for the whole cluster
System.out.println("--------------- whole cluster");
cache.entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue()));
// Display the current cache contents for this node
System.out.println("--------------- this node");
cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP)
.entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue()));
Thread.currentThread().join();
我的 JGroups 配置文件非常小:
<config xmlns="urn:org:jgroups"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
<TCP bind_port="7950" />
<TCPPING initial_hosts="192.168.42.100[7950],192.165.10.52[7950]"/>
</config>
问题是缓存没有启动:
sept. 21, 2021 1:49:01 PM org.infinispan.factories.GlobalComponentRegistry preStart
INFO: ISPN000128: Infinispan version: Infinispan 'Taedonggang' 12.1.7.Final
sept. 21, 2021 1:49:01 PM org.infinispan.marshall.core.impl.DelegatingUserMarshaller start
INFO: ISPN000556: Starting user marshaller 'org.infinispan.commons.marshall.ImmutableProtoStreamMarshaller'
sept. 21, 2021 1:49:01 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport start
INFO: ISPN000078: Starting JGroups channel ISPN
sept. 21, 2021 1:49:02 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport startJGroupsChannelIfNeeded
INFO: ISPN000079: Channel ISPN local address is null, physical addresses are [192.168.42.100:7950]
sept. 21, 2021 1:49:02 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport stop
INFO: ISPN000080: Disconnecting JGroups channel ISPN
Exception in thread "main" org.infinispan.manager.EmbeddedCacheManagerStartupException: org.infinispan.commons.CacheConfigurationException: Error starting component org.infinispan.topology.ClusterTopologyManager
at org.infinispan.manager.DefaultCacheManager.internalStart(DefaultCacheManager.java:755)
at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:718)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:296)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:219)
at TestGenerate.main(TestGenerate.java:43)
Caused by: org.infinispan.commons.CacheConfigurationException: Error starting component org.infinispan.topology.ClusterTopologyManager
at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:572)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.access$700(BasicComponentRegistryImpl.java:30)
at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:787)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.startDependencies(BasicComponentRegistryImpl.java:622)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:586)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:564)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.access$700(BasicComponentRegistryImpl.java:30)
at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:787)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.startDependencies(BasicComponentRegistryImpl.java:622)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:586)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:564)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.access$700(BasicComponentRegistryImpl.java:30)
at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:787)
at org.infinispan.factories.AbstractComponentRegistry.internalStart(AbstractComponentRegistry.java:354)
at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:250)
at org.infinispan.manager.DefaultCacheManager.internalStart(DefaultCacheManager.java:750)
... 4 more
Caused by: java.lang.NullPointerException: Cannot invoke "Object.equals(Object)" because the return value of "org.infinispan.remoting.transport.Transport.getAddress()" is null
at org.infinispan.topology.TopologyManagementHelper.executeOnCoordinator(TopologyManagementHelper.java:83)
at org.infinispan.topology.ClusterTopologyManagerImpl.fetchRebalancingStatusFromCoordinator(ClusterTopologyManagerImpl.java:162)
at org.infinispan.topology.ClusterTopologyManagerImpl.start(ClusterTopologyManagerImpl.java:153)
at org.infinispan.topology.CorePackageImpl$3.start(CorePackageImpl.java:74)
at org.infinispan.topology.CorePackageImpl$3.start(CorePackageImpl.java:58)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.invokeStart(BasicComponentRegistryImpl.java:604)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:595)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:564)
... 19 more
如果我使用演示代码,getAddress() 方法确实会返回一些东西(我的主机名和一个数字),但经过修改,地址确实为空。
我必须手动设置地址吗?怎么样?
编辑:经过一番搜索,当我使用演示代码时,JGroupsTransport 类中的 receiveClusterView(View) 方法在 TopologyManagementHelper 类中的 executeOnCoordinator(...) 方法之前被调用,这设置了地址。
使用我的xml配置文件时,在executeOnCoordinator()方法之前没有调用receiveClusterView(view),因此getAddress()失败。
环境:
infinispan-core v12.1.7.Final
jgroups v4.2.12.Final(作为 maven 的依赖项)
采用-openjdk v15.0.2
macOS 大苏尔
【问题讨论】:
【参考方案1】:你的配置太简约了:)
Infinispan 需要 JGroups Group Membership 和 Reliable Transmission 才能正常工作。
此外,如果您不想在节点崩溃时丢失数据,故障检测可能会很有用。
【讨论】:
非常感谢您的回复。是否有可能找到示例配置文件? Infinispan 提供了一些默认的 JGroups 配置。在这里查看它们:github.com/infinispan/infinispan/tree/main/core/src/main/…。此外,infinispan.org/docs/stable/titles/embedding/… 展示了如何使用它们或在需要时自定义它们。 非常感谢,我确实尝试了其中一个文件,但由于某些 xml 字段无效,它失败了,也许我当时没有使用正确的版本。 最后一个问题,我们可以在同一个配置文件中混合使用UDP和TCP模式吗? 不,每个配置只有一个传输。【参考方案2】:为了避免必须提供完整有效的 JGroups 堆栈,我将在提供的堆栈之一之上使用继承
<infinispan>
<jgroups>
<!-- Creates a custom JGroups stack named "my-stack". -->
<!-- Inherits properties from the default TCP stack. -->
<stack name="my-stack" extends="tcp">
<!-- Uses TCPPING as the discovery mechanism instead of MPING -->
<TCPPING initial_hosts="192.168.42.100[7950],192.165.10.52[7950]"
stack.combine="REPLACE"
stack.position="MPING" />
</stack>
</jgroups>
<cache-container name="default" statistics="true">
<!-- Uses "my-stack" for cluster transport. -->
<transport cluster="$infinispan.cluster.name"
stack="my-stack"
node-name="$infinispan.node.name:"/>
</cache-container>
</infinispan>
更多详情请参考https://infinispan.org/docs/stable/titles/embedding/embedding.html#jgroups-default_cluster-transport
【讨论】:
非常有趣,你知道我如何在不使用配置文件的情况下执行相同的操作吗?我以编程方式设置了嵌入式 infinispan。 不,该功能是 Infinispan 配置解析器的一部分,而不是 JGroups 的一部分。您必须提供基于默认配置的“完整”配置:github.com/infinispan/infinispan/tree/main/core/src/main/… 我明白了。感谢您的建议。以上是关于尝试在 Infinispan 环境中对 JGroups 使用 TCPPING 失败,因为地址为 Transport.getAddress() 为空的主要内容,如果未能解决你的问题,请参考以下文章
Infinispan - ISPN000476:等待请求响应超时
在 Wildfly 8.2 上重新部署后从 Infinispan 缓存读取时发生 ClassCastException
如何在 Wildfly Standalone-full-ha 中使用复制的 Infinispan 缓存