static long writeToZooKeeperAfterFailover ( Configuration startupConf , Configuration confg ) throws IOException { AvatarZooKeeperClient zk = null ; // Register client port address. String address = startupConf . get ( NameNode . DFS_NAMENODE_RPC_ADDRESS_KEY ) ; String realAddress = confg . get ( NameNode . DFS_NAMENODE_RPC_ADDRESS_KEY ) ; int maxTries = startupConf . getInt ( "dfs.avatarnode.zk.retries" , 3 ) ; for ( int i = 0 ; i < maxTries ; i ++ ) { try { zk = new AvatarZooKeeperClient ( confg , null , false ) ; LOG . info ( "Failover: Registering to ZK as primary" ) ; final boolean toOverwrite = true ; zk . registerPrimary ( address , realAddress , toOverwrite ) ; registerClientProtocolAddress ( zk , startupConf , confg , toOverwrite ) ; registerDnProtocolAddress ( zk , startupConf , confg , toOverwrite ) ; registerHttpAddress ( zk , startupConf , confg , toOverwrite ) ; LOG . info ( "Failover: Writting session id to ZK" ) ; return writeSessionIdToZK ( startupConf , zk ) ; } catch ( Exception e ) { LOG . error ( "Got Exception registering the new primary " + "with ZooKeeper. Will retry..." , e ) ; } finally { shutdownZkClient ( zk ) ; } } throw new IOException ( "Cannot connect to zk" ) ; }
Performs some operations after failover such as writing a new session id and registering to zookeeper as the new primary .