【发布时间】:2019-10-01 14:41:27
【问题描述】:
我正在使用 hazelcast 3.11 并测试以下网络情况。
A
/ \
B C
其中A和B双向连接,A和C双向连接,B和C断开。通常所有节点都已连接,因此我使用 TcpIp 配置以编程方式为每个节点配置每个 IP。
当我介绍网络故障时,节点 B 怀疑节点 C,因为它没有发送任何心跳,然后立即怀疑节点 A 的原因是“显式怀疑”。
节点 C 怀疑节点 B,因为它没有发送任何心跳。它与节点 A 位于同一个集群中。 “明确怀疑” Hazelcast 创建 2 个完全连接的分区而不是 1 个不完全连接的分区的方式?有没有办法将 Hazelcast 配置为出现这种类型的网络故障并保持 A 连接到 A 和 C?
附带说明一下,我只对使用 ReplicatedMap 和分布式事件 API 感兴趣。
编辑:以下代码在名为 A、B 和 C 的 3 台服务器上运行一次。它们分别运行一次 hazelcast 实例。
public HazelcastInstance getHazelcastInstance() {
Config config = new Config();
config
.getGroupConfig( )
.setName( localFacility.getName() )
.setPassword( clusterPassword );
NetworkConfig networkConfig = config.getNetworkConfig();
//Disable multicast
JoinConfig joinConfig = networkConfig.getJoin();
joinConfig
.getMulticastConfig()
.setEnabled( false );
// Interface config
InterfacesConfig interfaceConfig = networkConfig.getInterfaces();
IntraFacilityProperties intrafacilityProperties = facilityPropertiesUtil.getCurrentIntrafacilityProperties();
String primaryHostname = intrafacilityProperties.getHostname();
String secondaryHostname = intrafacilityProperties.getBackupHostname();
try {
InetAddress primaryIp = InetAddress.getByName( primaryHostname );
InetAddress secondaryIp = InetAddress.getByName( secondaryHostname );
// Specify which network interfaces to use based on the configured hostnames
interfaceConfig
.setEnabled( true )
.addInterface( primaryIp.getHostAddress() )
.addInterface( secondaryIp.getHostAddress() );
} catch ( UnknownHostException e ) {
if ( logger.isErrorEnabled() ) {
logger.error( "Caught UnknownHostException", e );
}
throw new HazelcastInstantiationException( e.getMessage() );
}
//Enable the tcp ip config.
TcpIpConfig ipConfig = joinConfig.getTcpIpConfig();
ipConfig.setEnabled( true );
try{
// Loops through all servers regardless of which server this is.
for( IntraFacilityProperties member : facilityPropertiesUtil.getIntraFacilityProperties() ) {
ipConfig.addMember( InetAddress.getByName( member.getHostname() ).getHostAddress() );
ipConfig.addMember( InetAddress.getByName( member.getBackupHostname() ).getHostAddress() );
}
} catch( UnknownHostException e ) {
if ( logger.isErrorEnabled() ) {
logger.error( "Caught UnknownHostException", e );
}
throw new HazelcastInstantiationException( e.getMessage() );
}
ReplicatedMapConfig repMapCfg = new ReplicatedMapConfig();
repMapCfg.setName( "default" )
.setMergePolicyConfig( new MergePolicyConfig()
.setPolicy( "LatestAccessMergePolicy" ) );
config.addReplicatedMapConfig( repMapCfg );
config.setProperty( "hazelcast.heartbeat.failuredetector.type", "deadline" );
config.setProperty( "hazelcast.heartbeat.interval.seconds", hzHeartbeatInterval );
config.setProperty( "hazelcast.max.no.heartbeat.seconds", hzHeartbeatTimeout );
config.setProperty( "hazelcast.merge.first.run.delay.seconds", hzMergeFirstDelay );
config.setProperty( "hazelcast.merge.next.run.delay.seconds", hzMergeNextDelay );
return Hazelcast.newHazelcastInstance( config );
}
【问题讨论】:
标签: hazelcast