diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 8d204dbf2d5..92194a257bc 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -126,7 +126,8 @@ void syncd_apply_view() if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to notify syncd APPLY_VIEW %d", status); - exit(EXIT_FAILURE); + notifyAbort(); + abort(); } } @@ -486,6 +487,9 @@ int main(int argc, char **argv) DBConnector config_db("CONFIG_DB", 0); DBConnector state_db("STATE_DB", 0); + /* Clears the ORCH_ABORT_STATUS flag in STATE_DB */ + state_db.del(ORCH_ABRT); + // Get switch_type getCfgSwitchType(&config_db, gMySwitchType); @@ -634,7 +638,8 @@ int main(int argc, char **argv) if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to get MAC address from switch, rv:%d", status); - exit(EXIT_FAILURE); + notifyAbort(); + abort(); } else { @@ -649,7 +654,8 @@ int main(int argc, char **argv) if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Fail to get switch virtual router ID %d", status); - exit(EXIT_FAILURE); + notifyAbort(); + abort(); } gVirtualRouterId = attr.value.oid; @@ -691,7 +697,8 @@ int main(int argc, char **argv) if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to create underlay router interface %d", status); - exit(EXIT_FAILURE); + notifyAbort(); + abort(); } SWSS_LOG_NOTICE("Created underlay router interface ID %" PRIx64, gUnderlayIfId); diff --git a/orchagent/orch.cpp b/orchagent/orch.cpp index 8a4049583ab..ed12b48564c 100644 --- a/orchagent/orch.cpp +++ b/orchagent/orch.cpp @@ -23,6 +23,14 @@ extern ofstream gRecordOfs; extern bool gLogRotate; extern string gRecordFile; +void notifyAbort(){ + /* + * This function sets the ORCH_ABORT_STATUS flag in STATE_DB and aborts itself + */ + swss::DBConnector m_db("STATE_DB", 0); + m_db.set(ORCH_ABRT, "1"); +} + Orch::Orch(DBConnector *db, const string tableName, int pri) { addConsumer(db, tableName, pri); @@ -887,6 +895,7 @@ task_process_status Orch::handleSaiCreateStatus(sai_api_t api, sai_status_t stat default: SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + notifyAbort(); abort(); } break; @@ -905,6 +914,7 @@ task_process_status Orch::handleSaiCreateStatus(sai_api_t api, sai_status_t stat default: SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + notifyAbort(); abort(); } default: @@ -916,6 +926,7 @@ task_process_status Orch::handleSaiCreateStatus(sai_api_t api, sai_status_t stat default: SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + notifyAbort(); abort(); } } @@ -957,11 +968,13 @@ task_process_status Orch::handleSaiSetStatus(sai_api_t api, sai_status_t status, default: SWSS_LOG_ERROR("Encountered failure in set operation, exiting orchagent, SAI API: %s, status: %s", sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + notifyAbort(); abort(); } default: SWSS_LOG_ERROR("Encountered failure in set operation, exiting orchagent, SAI API: %s, status: %s", sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + notifyAbort(); abort(); } @@ -990,6 +1003,7 @@ task_process_status Orch::handleSaiRemoveStatus(sai_api_t api, sai_status_t stat default: SWSS_LOG_ERROR("Encountered failure in remove operation, exiting orchagent, SAI API: %s, status: %s", sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + notifyAbort(); abort(); } return task_need_retry; diff --git a/orchagent/orch.h b/orchagent/orch.h index 7e803bbd93d..9ae794bc5bd 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -45,6 +45,7 @@ const char state_db_key_delimiter = '|'; #define CONFIGDB_KEY_SEPARATOR "|" #define DEFAULT_KEY_SEPARATOR ":" #define VLAN_SUB_INTERFACE_SEPARATOR "." +#define ORCH_ABRT "ORCH_ABRT_STATUS" const int default_orch_pri = 0; @@ -58,6 +59,9 @@ typedef enum task_duplicated } task_process_status; + +void notifyAbort(); + typedef struct { // m_objsDependingOnMe stores names (without table name) of all objects depending on the current obj diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index d1b418882cf..5f0db7e7543 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -675,6 +675,7 @@ void OrchDaemon::flush() if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to flush redis pipeline %d", status); + notifyAbort(); abort(); } }