@ -78,14 +78,12 @@ public class ZKMasterClient extends AbstractZKClient {
while ( ! checkZKNodeExists ( OSUtils . getHost ( ) , ZKNodeType . MASTER ) ) {
while ( ! checkZKNodeExists ( OSUtils . getHost ( ) , ZKNodeType . MASTER ) ) {
ThreadUtils . sleep ( SLEEP_TIME_MILLIS ) ;
ThreadUtils . sleep ( SLEEP_TIME_MILLIS ) ;
}
}
// startup tolerant
// self tolerant
if ( getActiveMasterNum ( ) = = 1 ) {
if ( getActiveMasterNum ( ) = = 1 ) {
failoverWorker ( null , true ) ;
removeZKNodePath ( null , ZKNodeType . MASTER , true ) ;
failoverMaster ( null ) ;
removeZKNodePath ( null , ZKNodeType . WORKER , true ) ;
}
}
registerListener ( ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( "master start up exception" , e ) ;
logger . error ( "master start up exception" , e ) ;
} finally {
} finally {
@ -131,9 +129,16 @@ public class ZKMasterClient extends AbstractZKClient {
mutex = new InterProcessMutex ( getZkClient ( ) , failoverPath ) ;
mutex = new InterProcessMutex ( getZkClient ( ) , failoverPath ) ;
mutex . acquire ( ) ;
mutex . acquire ( ) ;
String serverHost = getHostByEventDataPath ( path ) ;
String serverHost = null ;
if ( StringUtils . isNotEmpty ( path ) ) {
serverHost = getHostByEventDataPath ( path ) ;
if ( StringUtils . isEmpty ( serverHost ) ) {
logger . error ( "server down error: unknown path: {}" , path ) ;
return ;
}
// handle dead server
// handle dead server
handleDeadServer ( path , zkNodeType , Constants . ADD_ZK_OP ) ;
handleDeadServer ( path , zkNodeType , Constants . ADD_ZK_OP ) ;
}
//failover server
//failover server
if ( failover ) {
if ( failover ) {
failoverServerWhenDown ( serverHost , zkNodeType ) ;
failoverServerWhenDown ( serverHost , zkNodeType ) ;
@ -155,9 +160,6 @@ public class ZKMasterClient extends AbstractZKClient {
* @throws Exception exception
* @throws Exception exception
* /
* /
private void failoverServerWhenDown ( String serverHost , ZKNodeType zkNodeType ) throws Exception {
private void failoverServerWhenDown ( String serverHost , ZKNodeType zkNodeType ) throws Exception {
if ( StringUtils . isEmpty ( serverHost ) ) {
return ;
}
switch ( zkNodeType ) {
switch ( zkNodeType ) {
case MASTER :
case MASTER :
failoverMaster ( serverHost ) ;
failoverMaster ( serverHost ) ;
@ -333,8 +335,11 @@ public class ZKMasterClient extends AbstractZKClient {
List < ProcessInstance > needFailoverProcessInstanceList = processService . queryNeedFailoverProcessInstances ( masterHost ) ;
List < ProcessInstance > needFailoverProcessInstanceList = processService . queryNeedFailoverProcessInstances ( masterHost ) ;
logger . info ( "failover process list size:{} " , needFailoverProcessInstanceList . size ( ) ) ;
//updateProcessInstance host is null and insert into command
//updateProcessInstance host is null and insert into command
for ( ProcessInstance processInstance : needFailoverProcessInstanceList ) {
for ( ProcessInstance processInstance : needFailoverProcessInstanceList ) {
logger . info ( "failover process instance id: {} host:{}" ,
processInstance . getId ( ) , processInstance . getHost ( ) ) ;
if ( Constants . NULL . equals ( processInstance . getHost ( ) ) ) {
if ( Constants . NULL . equals ( processInstance . getHost ( ) ) ) {
continue ;
continue ;
}
}