Browse Source

Fixed host-swact failed

Adding new domain event SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER
to handle an on demand switching of service scheduler leader.

Closes-Bug: 1812108

Change-Id: I6796d8efcb1ef0c7fa835ed34028c8e6a2b5dcae
Signed-off-by: Bin Qian <bin.qian@windriver.com>
Bin Qian 2 months ago
parent
commit
1066d26e9e

+ 1
- 1
service-mgmt/sm-1.0.0/centos/build_srpm.data View File

@@ -2,4 +2,4 @@ SRC_DIR=$PKG_BASE
2 2
 COPY_LIST="$PKG_BASE/LICENSE"
3 3
 TAR_NAME=sm
4 4
 VERSION=1.0.0
5
-TIS_PATCH_VER=28
5
+TIS_PATCH_VER=29

+ 28
- 5
service-mgmt/sm-1.0.0/src/sm_failover.c View File

@@ -810,14 +810,37 @@ static SmErrorT sm_ensure_leader_scheduler()
810 810
 {
811 811
     char controller_domain[] = "controller";
812 812
     char reason_text[SM_LOG_REASON_TEXT_MAX_CHAR] = "Loss of heartbeat";
813
+    SmServiceDomainT* domain;
813 814
 
814
-    SmErrorT error = sm_service_domain_fsm_set_state(
815
+    domain = sm_service_domain_table_read( controller_domain );
816
+    if( NULL == domain )
817
+    {
818
+        DPRINTFE( "Failed to read service domain (%s), error=%s.",
819
+                  controller_domain, sm_error_str(SM_NOT_FOUND) );
820
+        return( SM_NOT_FOUND );
821
+    }
822
+
823
+    if(0 == strncmp(domain->leader, _host_name, sizeof(domain->leader)))
824
+    {
825
+        //Already leader. Nothing to do
826
+        return SM_OKAY;
827
+    }
828
+
829
+    SmServiceDomainEventT event = SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER;
830
+    void* event_data[] = {
831
+        _host_name //new leader
832
+    };
833
+    SmErrorT error = sm_service_domain_fsm_event_handler(
815 834
         controller_domain,
816
-        SM_SERVICE_DOMAIN_STATE_LEADER,
817
-        reason_text );
818
-    if(SM_OKAY != error)
835
+        event,
836
+        event_data, reason_text );
837
+
838
+    if( SM_OKAY != error )
819 839
     {
820
-        DPRINTFE("Failed to ensure leader scheduler. Error %s", sm_error_str(error));
840
+        DPRINTFE( "Service domain (%s) failed to handle event (%s), error=%s.",
841
+                  controller_domain, sm_service_domain_event_str(event),
842
+                  sm_error_str( error ) );
843
+        return( error );
821 844
     }
822 845
     return error;
823 846
 }

+ 29
- 0
service-mgmt/sm-1.0.0/src/sm_service_domain_backup_state.c View File

@@ -58,6 +58,7 @@ SmErrorT sm_service_domain_backup_state_event_handler( SmServiceDomainT* domain,
58 58
     char* neighbor_name = NULL;
59 59
     char leader[SM_NODE_NAME_MAX_CHAR];
60 60
     char hostname[SM_NODE_NAME_MAX_CHAR];
61
+    const char* new_leader;
61 62
     int generation = 0;    
62 63
     char reason_text[SM_LOG_REASON_TEXT_MAX_CHAR] = "";
63 64
     SmServiceDomainStateT state = SM_SERVICE_DOMAIN_STATE_NIL;
@@ -188,6 +189,34 @@ SmErrorT sm_service_domain_backup_state_event_handler( SmServiceDomainT* domain,
188 189
             // Ignore.
189 190
         break;
190 191
 
192
+        case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
193
+            new_leader = (const char*) event_data[0];
194
+            error = sm_node_api_get_hostname(hostname);
195
+            if(SM_OKAY != error )
196
+            {
197
+                DPRINTFE("Failed to get hostname. Error %s", sm_error_str(error));
198
+                return SM_FAILED;
199
+            }
200
+
201
+            if(0 != strncmp(hostname, new_leader, SM_NODE_NAME_MAX_CHAR))
202
+            {
203
+                //Ignore
204
+            }else
205
+            {
206
+                strncpy(domain->leader, new_leader, SM_NODE_NAME_MAX_CHAR);
207
+                state = SM_SERVICE_DOMAIN_STATE_LEADER;
208
+                error = sm_service_domain_fsm_set_state( domain->name, state,
209
+                                                         "leader change");
210
+                if( SM_OKAY != error )
211
+                {
212
+                    DPRINTFE( "Set state (%s) of service domain (%s) failed, "
213
+                              "error=%s.", sm_service_domain_state_str( state ),
214
+                              domain->name, sm_error_str( error ) );
215
+                    return( error );
216
+                }
217
+            }
218
+        break;
219
+
191 220
         default:
192 221
             DPRINTFD( "Service Domain (%s) ignoring event (%s).", 
193 222
                       domain->name,

+ 7
- 0
service-mgmt/sm-1.0.0/src/sm_service_domain_fsm.c View File

@@ -340,6 +340,13 @@ SmErrorT sm_service_domain_fsm_set_state( char service_domain_name[],
340 340
         snprintf( _reason_text, sizeof(_reason_text), "%s", reason_text );
341 341
     }
342 342
 
343
+    error = sm_service_domain_table_persist( domain );
344
+    if( SM_OKAY != error )
345
+    {
346
+        DPRINTFE( "Failed to persist service domain (%s), error=%s.",
347
+                  domain->name, sm_error_str( error ) );
348
+    }
349
+
343 350
     return( SM_OKAY );
344 351
 
345 352
 STATE_CHANGE_ERROR:

+ 4
- 0
service-mgmt/sm-1.0.0/src/sm_service_domain_initial_state.c View File

@@ -198,6 +198,10 @@ SmErrorT sm_service_domain_initial_state_event_handler(
198 198
             // Ignore.
199 199
         break;
200 200
 
201
+        case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
202
+            DPRINTFE("Received unexpected %s event", sm_service_domain_event_str(event));
203
+        break;
204
+
201 205
         default:
202 206
             DPRINTFD( "Service Domain (%s) ignoring event (%s).", 
203 207
                       domain->name, sm_service_domain_event_str( event ) );

+ 29
- 0
service-mgmt/sm-1.0.0/src/sm_service_domain_leader_state.c View File

@@ -57,6 +57,7 @@ SmErrorT sm_service_domain_leader_state_event_handler( SmServiceDomainT* domain,
57 57
     char* neighbor_name = NULL;
58 58
     char* leader_name = NULL;
59 59
     char hostname[SM_NODE_NAME_MAX_CHAR];
60
+    const char* new_leader;
60 61
     int generation = 0;
61 62
     int priority = 0;
62 63
     SmServiceDomainStateT state = SM_SERVICE_DOMAIN_STATE_NIL;
@@ -189,6 +190,34 @@ SmErrorT sm_service_domain_leader_state_event_handler( SmServiceDomainT* domain,
189 190
             // Ignore.
190 191
         break;
191 192
 
193
+        case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
194
+            new_leader = (const char*) event_data[0];
195
+            error = sm_node_api_get_hostname(hostname);
196
+            if(SM_OKAY != error )
197
+            {
198
+                DPRINTFE("Failed to get hostname. Error %s", sm_error_str(error));
199
+                return SM_FAILED;
200
+            }
201
+
202
+            if(0 == strncmp(hostname, new_leader, SM_NODE_NAME_MAX_CHAR))
203
+            {
204
+                //Ignore
205
+            }else
206
+            {
207
+                strncpy(domain->leader, new_leader, SM_NODE_NAME_MAX_CHAR);
208
+                state = SM_SERVICE_DOMAIN_STATE_BACKUP;
209
+                error = sm_service_domain_fsm_set_state( domain->name, state,
210
+                                                         "leader change");
211
+                if( SM_OKAY != error )
212
+                {
213
+                    DPRINTFE( "Set state (%s) of service domain (%s) failed, "
214
+                              "error=%s.", sm_service_domain_state_str( state ),
215
+                              domain->name, sm_error_str( error ) );
216
+                    return( error );
217
+                }
218
+            }
219
+        break;
220
+
192 221
         default:
193 222
             DPRINTFD( "Service Domain (%s) ignoring event (%s).", 
194 223
                       domain->name, sm_service_domain_event_str( event ) );

+ 4
- 0
service-mgmt/sm-1.0.0/src/sm_service_domain_other_state.c View File

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

+ 4
- 0
service-mgmt/sm-1.0.0/src/sm_service_domain_waiting_state.c View File

@@ -287,6 +287,10 @@ SmErrorT sm_service_domain_waiting_state_event_handler(
287 287
             }
288 288
         break;
289 289
 
290
+        case SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER:
291
+            DPRINTFE("Received unexpected %s event", sm_service_domain_event_str(event));
292
+        break;
293
+
290 294
         default:
291 295
             DPRINTFD( "Service Domain (%s) ignoring event (%s).", 
292 296
                       domain->name, sm_service_domain_event_str( event ) );

+ 1
- 1
service-mgmt/sm-common-1.0.0/centos/build_srpm.data View File

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

+ 1
- 0
service-mgmt/sm-common-1.0.0/src/sm_types.c View File

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

+ 1
- 0
service-mgmt/sm-common-1.0.0/src/sm_types.h View File

@@ -267,6 +267,7 @@ typedef enum
267 267
     SM_SERVICE_DOMAIN_EVENT_INTERFACE_ENABLED,
268 268
     SM_SERVICE_DOMAIN_EVENT_INTERFACE_DISABLED,
269 269
     SM_SERVICE_DOMAIN_EVENT_WAIT_EXPIRED,
270
+    SM_SERVICE_DOMAIN_EVENT_CHANGING_LEADER,
270 271
     SM_SERVICE_DOMAIN_EVENT_MAX
271 272
 } SmServiceDomainEventT;
272 273
 

+ 1
- 1
service-mgmt/sm-db-1.0.0/centos/build_srpm.data View File

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

Loading…
Cancel
Save