2017-05-10 193 views
0

我正在使用3.8.1,我注意到在成員退出後,客戶端周圍的重新連接行爲存在一些問題。儘管設置了重新連接嘗試,但是在記錄了關於無法獲得羣集連接的重複警告之後,客戶端經常斷開連接 - 儘管始終存在至少一個倖存的成員。Hazelcast在成員重新啓動後終止客戶端連接

那麼爲什麼斷開連接發生?我相信,如果至少有一個成員存在,則不應斷開任何客戶的連接。 爲什麼客戶在會員反彈後反覆登錄併發出警告?

測試: 我有2位成員加入。 我有3個客戶端通過tcp連接到兩個成員。 客戶端配置爲重新連接1000次。 客戶端1循環並簡單地將一個隨機值放入同一個密鑰。 客戶端2 & 3是此地圖的監聽者並記錄更新。

步驟: 啓動成員1,成員2. 啓動客戶端2,3(偵聽器)。 開始客戶端1(作家)。 此時一切正常。日誌中沒有警告。

退回成員1,等待它開始。 反射構件2. 反射構件1

並非總是如此,但很多時候,客戶反映這樣的:

Put 29: d16b0acd-d0d6-4722-b511-7fd975774f8c 
May 10, 2017 11:41:10 AM com.hazelcast.client.spi.impl.ClusterListenerSupport 
WARNING: hz.client_0 [dev] [3.8.1] Unable to get alive cluster connection, try in 0 ms later, attempt 4 of 1000. 
May 10, 2017 11:41:10 AM com.hazelcast.client.spi.impl.ClusterListenerSupport 
INFO: hz.client_0 [dev] [3.8.1] Trying to connect to [127.0.0.1]:5701 as owner member 
Put 30: f91ec949-19bd-4039-95d3-28c7abd0f241 
May 10, 2017 11:41:15 AM com.hazelcast.client.spi.impl.ClusterListenerSupport 
INFO: hz.client_0 [dev] [3.8.1] Trying to connect to [127.0.0.1]:5702 as owner member 
Put 31: 2af9fb36-d501-4b0b-9fc8-6b36d467a929 
May 10, 2017 11:41:20 AM com.hazelcast.client.spi.impl.ClusterListenerSupport 
INFO: hz.client_0 [dev] [3.8.1] Trying to connect to [127.0.0.1]:5701 as owner member 
Put 32: f08bd6ca-a79f-44f4-9064-42e47953c37a 

的客戶端仍然可以工作,而且還要聽事件,但一段時間後,他們經常斷開連接:

May 10, 2017 11:25:04 AM com.hazelcast.core.LifecycleService 
INFO: hz.client_0 [dev] [3.8.1] HazelcastClient 3.8.1 (20170411 - f1e9264) is SHUTTING_DOWN 
May 10, 2017 11:25:04 AM com.hazelcast.client.connection.ClientConnectionManager 
INFO: hz.client_0 [dev] [3.8.1] Removed connection to endpoint: [localhost]:5701, connection: ClientConnection{alive=false, connectionId=5, socketChannel=DefaultSocketChannelWrapper{socketChannel=java.nio.channels.SocketChannel[closed]}, remoteEndpoint=[localhost]:5701, lastReadTime=2017-05-10 11:25:04.021, lastWriteTime=2017-05-10 11:25:04.084, closedTime=2017-05-10 11:25:04.084, lastHeartbeatRequested=2017-05-10 11:25:03.834, lastHeartbeatReceived=2017-05-10 11:25:03.834, connected server version=3.8.1} 
May 10, 2017 11:25:04 AM com.hazelcast.client.connection.ClientConnectionManager 
INFO: hz.client_0 [dev] [3.8.1] Removed connection to endpoint: [localhost]:5702, connection: ClientConnection{alive=false, connectionId=6, socketChannel=DefaultSocketChannelWrapper{socketChannel=java.nio.channels.SocketChannel[closed]}, remoteEndpoint=[localhost]:5702, lastReadTime=2017-05-10 11:24:59.513, lastWriteTime=2017-05-10 11:25:04.084, closedTime=2017-05-10 11:25:04.084, lastHeartbeatRequested=2017-05-10 11:17:43.840, lastHeartbeatReceived=2017-05-10 11:17:43.840, connected server version=3.8.1} 
May 10, 2017 11:25:04 AM com.hazelcast.core.LifecycleService 
INFO: hz.client_0 [dev] [3.8.1] HazelcastClient 3.8.1 (20170411 - f1e9264) is SHUTDOWN 

客戶端斷開:

INFO: hz.client_0 [dev] [3.8.1] Removed connection to endpoint: [localhost]:5701, connection: ClientConnection{alive=false, connectionId=8, socketChannel=DefaultSocketChannelWrapper{socketChannel=java.nio.channels.SocketChannel[closed]}, remoteEndpoint=[localhost]:5701, lastReadTime=2017-05-10 11:45:31.791, lastWriteTime=2017-05-10 11:45:31.791, closedTime=2017-05-10 11:45:31.791, lastHeartbeatRequested=2017-05-10 11:45:23.604, lastHeartbeatReceived=2017-05-10 11:45:23.605, connected server version=3.8.1} 
May 10, 2017 11:45:31 AM com.hazelcast.core.LifecycleService 
INFO: hz.client_0 [dev] [3.8.1] HazelcastClient 3.8.1 (20170411 - f1e9264) is CLIENT_DISCONNECTED 

成員報告:

May 10, 2017 11:47:32 AM com.hazelcast.client.impl.protocol.task.AuthenticationMessageTask 
WARNING: [localhost]:5701 [dev] [3.8.1] Member having uuid 8847c2e3-2fcb-428f-a827-d0e24f5624a1 is not part of the cluster. Client Authentication rejected. 
May 10, 2017 11:47:32 AM com.hazelcast.client.impl.protocol.task.AuthenticationMessageTask 
WARNING: [localhost]:5701 [dev] [3.8.1] Received auth from Connection[id=222, /127.0.0.1:5701->/127.0.0.1:53883, endpoint=null, alive=true, type=NONE] with principal ClientPrincipal{uuid='f1e5d928-23b2-4fdf-bd3f-9db1778a5a8c', ownerUuid='8847c2e3-2fcb-428f-a827-d0e24f5624a1'} , authentication failed 

主要成員:

public class HzNodeTest { 
    private HazelcastInstance service; 

    @Before 
    public void setUp() throws Exception { 
     Config config = new Config(); 
     JoinConfig join = config.getNetworkConfig().setPort(5701).getJoin(); 
     join.getMulticastConfig().setEnabled(false); 
     join.getAwsConfig().setEnabled(false); 
     join.getTcpIpConfig().addMember("localhost:5701").addMember("localhost:5702").setEnabled(true); 
     service = Hazelcast.newHazelcastInstance(config); 
    } 

    @After 
    public void tearDown() throws Exception { 
     service.shutdown(); 
    } 

    @Test 
    public void testStart() throws InterruptedException { 
     Thread.sleep(1000000000); 
    } 
} 

Secondary member: 
public class HzNodeSecondaryTest { 
    private HazelcastInstance service; 

    @Before 
    public void setUp() throws Exception { 
     Config config = new Config(); 
     JoinConfig join = config.getNetworkConfig().setPort(5702).getJoin(); 
     join.getMulticastConfig().setEnabled(false); 
     join.getAwsConfig().setEnabled(false); 
     join.getTcpIpConfig().addMember("localhost:5701").addMember("localhost:5702").setEnabled(true); 
     service = Hazelcast.newHazelcastInstance(config); 
    } 

    @After 
    public void tearDown() throws Exception { 
     service.shutdown(); 
    } 

    @Test 
    public void testStart() throws InterruptedException { 
     Thread.sleep(1000000000); 
    } 
} 

Listener: 

public class HzListenerTest { 
    private HazelcastInstance service; 
    private AtomicLong counter = new AtomicLong(); 

    @Before 
    public void setUp() throws Exception { 
     ClientConfig clientConfig = new ClientConfig(); 
     clientConfig.getNetworkConfig().addAddress("localhost:5701").addAddress("localhost:5702").setConnectionAttemptLimit(1000); 
     service = HazelcastClient.newHazelcastClient(clientConfig); 
    } 

    @After 
    public void tearDown() throws Exception { 
     service.shutdown(); 
    } 

    @Test 
    public void testListen() throws InterruptedException { 
     service.getMap("TEST").addEntryListener(new Listener(), true); 

     Thread.sleep(1000000); 
    } 

    private class Listener implements EntryAddedListener, EntryUpdatedListener, EntryRemovedListener, 
      EntryEvictedListener { 

     @Override 
     public void entryAdded(EntryEvent event) { 
      System.out.println("onAdded " + counter.getAndIncrement() + ": " + event); 
     } 

     @Override 
     public void entryEvicted(EntryEvent event) { 
      System.out.println("onEvicted " + counter.getAndIncrement() + ": " + event); 
     } 

     @Override 
     public void entryRemoved(EntryEvent event) { 
      System.out.println("onRemoved " + counter.getAndIncrement() + ": " + event); 
     } 

     @Override 
     public void entryUpdated(EntryEvent event) { 
      System.out.println("onUpdated " + counter.getAndIncrement() + ": "+ event); 
     } 
    } 
} 

Updater: 

public class HzUpdaterTest { 
    private HazelcastInstance service; 

    @Before 
    public void setUp() throws Exception { 
     ClientConfig clientConfig = new ClientConfig(); 
     clientConfig.getNetworkConfig().addAddress("localhost:5701").addAddress("localhost:5702").setConnectionAttemptLimit(1000); 
     service = HazelcastClient.newHazelcastClient(clientConfig); 
     service.getMap("TEST").put("1", UUID.randomUUID().toString()); 
    } 

    @After 
    public void tearDown() throws Exception { 
     service.shutdown(); 
    } 

    @Test 
    public void testSpin() { 
     for (int i = 0; i < 10000; i++) { 
      try { 
       String value = UUID.randomUUID().toString(); 
       service.getMap("TEST").put("1", value); 
       System.out.println("Put " + i + ": " + value); 
       Thread.sleep(5000); 
      } catch (Exception ex) { 
       System.out.println(ex); 
      } 
     } 
    } 
} 

回答

0

每當Hazelcast客戶端連接到集羣中,第一個成員客戶端可以建立連接(這是當CLIENT_CONNECTED被解僱)成爲該客戶的所有者成員。客戶端從所有者成員獲取羣集信息和其他成員的地址。之後,客戶端會根據需要知道所有成員並直接連接到它們。

當您關閉的成員碰巧是該客戶的所有者成員時,CLIENT_DISCONNECTED事件將被解僱。但在很短的時間內(在相同的時間內),客戶應重新建立與其餘成員的連接。

0

在日誌中我看到

Unable to get alive cluster connection, try in 0 ms later, attempt 4 of 1000.

可能可以嘗試財產

<propertyname="hazelcast.invalidation.reconciliation.interval.seconds">5</property>

相關問題