Merge "Fixed host-swact failed"

This commit is contained in:
Zuul 2019-02-06 22:26:49 +00:00 committed by Gerrit Code Review
commit beda852ec8
11 changed files with 110 additions and 8 deletions

View File

@ -810,14 +810,37 @@ static SmErrorT sm_ensure_leader_scheduler()
{
char controller_domain[] = "controller";
char reason_text[SM_LOG_REASON_TEXT_MAX_CHAR] = "Loss of heartbeat";
SmServiceDomainT* domain;
SmErrorT error = sm_service_domain_fsm_set_state(
controller_domain,
SM_SERVICE_DOMAIN_STATE_LEADER,
reason_text );
if(SM_OKAY != error)
domain = sm_service_domain_table_read( controller_domain );
if( NULL == domain )
{
DPRINTFE("Failed to ensure leader scheduler. Error %s", sm_error_str(error));
DPRINTFE( "Failed to read service domain (%s), error=%s.",
controller_domain, sm_error_str(SM_NOT_FOUND) );
return( SM_NOT_FOUND );
}
if(0 == strncmp(domain->leader, _host_name, sizeof(domain->leader)))
{
//Already leader. Nothing to do
return SM_OKAY;
}
SmServiceDomainEventT event = SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER;
void* event_data[] = {
_host_name //new leader
};
SmErrorT error = sm_service_domain_fsm_event_handler(
controller_domain,
event,
event_data, reason_text );
if( SM_OKAY != error )
{
DPRINTFE( "Service domain (%s) failed to handle event (%s), error=%s.",
controller_domain, sm_service_domain_event_str(event),
sm_error_str( error ) );
return( error );
}
return error;
}

View File

@ -58,6 +58,7 @@ SmErrorT sm_service_domain_backup_state_event_handler( SmServiceDomainT* domain,
char* neighbor_name = NULL;
char leader[SM_NODE_NAME_MAX_CHAR];
char hostname[SM_NODE_NAME_MAX_CHAR];
const char* new_leader;
int generation = 0;
char reason_text[SM_LOG_REASON_TEXT_MAX_CHAR] = "";
SmServiceDomainStateT state = SM_SERVICE_DOMAIN_STATE_NIL;
@ -188,6 +189,34 @@ SmErrorT sm_service_domain_backup_state_event_handler( SmServiceDomainT* domain,
// Ignore.
break;
case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
new_leader = (const char*) event_data[0];
error = sm_node_api_get_hostname(hostname);
if(SM_OKAY != error )
{
DPRINTFE("Failed to get hostname. Error %s", sm_error_str(error));
return SM_FAILED;
}
if(0 != strncmp(hostname, new_leader, SM_NODE_NAME_MAX_CHAR))
{
//Ignore
}else
{
strncpy(domain->leader, new_leader, SM_NODE_NAME_MAX_CHAR);
state = SM_SERVICE_DOMAIN_STATE_LEADER;
error = sm_service_domain_fsm_set_state( domain->name, state,
"leader change");
if( SM_OKAY != error )
{
DPRINTFE( "Set state (%s) of service domain (%s) failed, "
"error=%s.", sm_service_domain_state_str( state ),
domain->name, sm_error_str( error ) );
return( error );
}
}
break;
default:
DPRINTFD( "Service Domain (%s) ignoring event (%s).",
domain->name,

View File

@ -340,6 +340,13 @@ SmErrorT sm_service_domain_fsm_set_state( char service_domain_name[],
snprintf( _reason_text, sizeof(_reason_text), "%s", reason_text );
}
error = sm_service_domain_table_persist( domain );
if( SM_OKAY != error )
{
DPRINTFE( "Failed to persist service domain (%s), error=%s.",
domain->name, sm_error_str( error ) );
}
return( SM_OKAY );
STATE_CHANGE_ERROR:

View File

@ -198,6 +198,10 @@ SmErrorT sm_service_domain_initial_state_event_handler(
// Ignore.
break;
case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
DPRINTFE("Received unexpected %s event", sm_service_domain_event_str(event));
break;
default:
DPRINTFD( "Service Domain (%s) ignoring event (%s).",
domain->name, sm_service_domain_event_str( event ) );

View File

@ -57,6 +57,7 @@ SmErrorT sm_service_domain_leader_state_event_handler( SmServiceDomainT* domain,
char* neighbor_name = NULL;
char* leader_name = NULL;
char hostname[SM_NODE_NAME_MAX_CHAR];
const char* new_leader;
int generation = 0;
int priority = 0;
SmServiceDomainStateT state = SM_SERVICE_DOMAIN_STATE_NIL;
@ -189,6 +190,34 @@ SmErrorT sm_service_domain_leader_state_event_handler( SmServiceDomainT* domain,
// Ignore.
break;
case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
new_leader = (const char*) event_data[0];
error = sm_node_api_get_hostname(hostname);
if(SM_OKAY != error )
{
DPRINTFE("Failed to get hostname. Error %s", sm_error_str(error));
return SM_FAILED;
}
if(0 == strncmp(hostname, new_leader, SM_NODE_NAME_MAX_CHAR))
{
//Ignore
}else
{
strncpy(domain->leader, new_leader, SM_NODE_NAME_MAX_CHAR);
state = SM_SERVICE_DOMAIN_STATE_BACKUP;
error = sm_service_domain_fsm_set_state( domain->name, state,
"leader change");
if( SM_OKAY != error )
{
DPRINTFE( "Set state (%s) of service domain (%s) failed, "
"error=%s.", sm_service_domain_state_str( state ),
domain->name, sm_error_str( error ) );
return( error );
}
}
break;
default:
DPRINTFD( "Service Domain (%s) ignoring event (%s).",
domain->name, sm_service_domain_event_str( event ) );

View File

@ -98,6 +98,10 @@ SmErrorT sm_service_domain_other_state_event_handler( SmServiceDomainT* domain,
// Ignore.
break;
case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
DPRINTFE("Received unexpected %s event", sm_service_domain_event_str(event));
break;
default:
DPRINTFD( "Service Domain (%s) ignoring event (%s).",
domain->name, sm_service_domain_event_str( event ) );

View File

@ -287,6 +287,10 @@ SmErrorT sm_service_domain_waiting_state_event_handler(
}
break;
case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
DPRINTFE("Received unexpected %s event", sm_service_domain_event_str(event));
break;
default:
DPRINTFD( "Service Domain (%s) ignoring event (%s).",
domain->name, sm_service_domain_event_str( event ) );

View File

@ -1,2 +1,2 @@
SRC_DIR=$PKG_BASE
TIS_PATCH_VER=19
TIS_PATCH_VER=20

View File

@ -151,6 +151,7 @@ _sm_service_domain_event_mappings[SM_SERVICE_DOMAIN_EVENT_MAX] =
{ SM_SERVICE_DOMAIN_EVENT_INTERFACE_ENABLED, "interface-enabled" },
{ SM_SERVICE_DOMAIN_EVENT_INTERFACE_DISABLED, "interface-disabled" },
{ SM_SERVICE_DOMAIN_EVENT_WAIT_EXPIRED, "wait-expired" },
{ SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER, "change-leader" },
};
static SmValueStrMappingT

View File

@ -267,6 +267,7 @@ typedef enum
SM_SERVICE_DOMAIN_EVENT_INTERFACE_ENABLED,
SM_SERVICE_DOMAIN_EVENT_INTERFACE_DISABLED,
SM_SERVICE_DOMAIN_EVENT_WAIT_EXPIRED,
SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER,
SM_SERVICE_DOMAIN_EVENT_MAX
} SmServiceDomainEventT;

View File

@ -2,4 +2,4 @@ SRC_DIR=`pwd`
COPY_LIST="$PKG_BASE/LICENSE"
TAR_NAME=sm-db
VERSION=1.0.0
TIS_PATCH_VER=27
TIS_PATCH_VER=28