尝试在 Infinispan 环境中对 JGroups 使用 TCPPING 失败,因为地址为 Transport.getAddress() 为空
Trying to use TCPPING for JGroups in a Infinispan env fail as address is Transport.getAddress() is null
我正在尝试设置复制的 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.access0(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.access0(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.access0(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.start(CorePackageImpl.java:74)
at org.infinispan.topology.CorePackageImpl.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() 方法确实会 return 一些东西(我的主机名和一个数字),但是经过修改,地址确实是空的。
我必须手动设置地址吗?怎么样?
编辑:经过一些搜索,当我使用演示代码时,JGroupsTransport class 中的 receiveClusterView(View) 方法在 TopologyManagementHelper class 中的 executeOnCoordinator(...) 方法之前被调用,这设置了地址。
使用我的 xml 配置文件时,在 executeOnCoordinator() 方法之前未调用 receiveClusterView(view),因此 getAddress() 失败。
Environment :
infinispan-core v12.1.7.Final
jgroups v4.2.12.Final (as dependcy from maven)
adopt-openjdk v15.0.2
macOS Big Sur
你的配置太简单了:)
Infinispan 需要 JGroups Group Membership and Reliable Transmission 才能正常工作。
此外,如果您不想在节点崩溃时丢失数据,故障检测可能会有用。
为了避免不得不提出一个完整有效的 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 嵌入式缓存。
当使用演示代码以编程方式设置缓存时,一切正常,如预期的那样 (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.access0(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.access0(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.access0(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.start(CorePackageImpl.java:74)
at org.infinispan.topology.CorePackageImpl.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() 方法确实会 return 一些东西(我的主机名和一个数字),但是经过修改,地址确实是空的。
我必须手动设置地址吗?怎么样?
编辑:经过一些搜索,当我使用演示代码时,JGroupsTransport class 中的 receiveClusterView(View) 方法在 TopologyManagementHelper class 中的 executeOnCoordinator(...) 方法之前被调用,这设置了地址。
使用我的 xml 配置文件时,在 executeOnCoordinator() 方法之前未调用 receiveClusterView(view),因此 getAddress() 失败。
Environment :
infinispan-core v12.1.7.Final
jgroups v4.2.12.Final (as dependcy from maven)
adopt-openjdk v15.0.2
macOS Big Sur
你的配置太简单了:)
Infinispan 需要 JGroups Group Membership and Reliable Transmission 才能正常工作。
此外,如果您不想在节点崩溃时丢失数据,故障检测可能会有用。
为了避免不得不提出一个完整有效的 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了解更多详情