2016-09-15 3 views
0

jedisのsrcコードMasterListener方法の実行:jedis MasterListener initPool何回

 j.subscribe(new JedisPubSub() { 
     @Override 
     public void onMessage(String channel, String message) { 
      log.fine("Sentinel " + host + ":" + port + " published: " + message + "."); 

      String[] switchMasterMsg = message.split(" "); 

      if (switchMasterMsg.length > 3) { 

      if (masterName.equals(switchMasterMsg[0])) { 
       initPool(toHostAndPort(Arrays.asList(switchMasterMsg[3], switchMasterMsg[4]))); 
      } else { 
       log.fine("Ignoring message on +switch-master for master name " 
        + switchMasterMsg[0] + ", our master name is " + masterName); 
      } 

      } else { 
      log.severe("Invalid message received on Sentinel " + host + ":" + port 
       + " on channel +switch-master: " + message); 
      } 
     } 
     }, "+switch-master"); 

3人の歩哨をそこに持っている場合は、その3つのMasterListener.Whenのフェイルオーバーが発生し、jedisクライアントは各MasterListenerについて3回initPoolます作成しました。

質問は、なぜinitPoolは一度だけではないのですか? sentinel客観的なオフラインマスター、その後、jedisクライアントは、再initPoolにメッセージを受け取りますか?

答えて

0

私は接続プールの作成を複数回防止するために、この行に "if(!master.equals(currentHostMaster)){{"同期が必要だと思います。

public class JedisSentinelPool extends JedisPoolAbstract { 
    private volatile HostAndPort currentHostMaster; 
    private void initPool(HostAndPort master) { 
    if (!master.equals(currentHostMaster)) { 
     currentHostMaster = master; 
     if (factory == null) { 

}