From 786b77f42aed3b9a3f3bb9cb54ba7115f0d8ac8f Mon Sep 17 00:00:00 2001 From: Jipan Yang Date: Fri, 29 Mar 2019 12:24:56 -0700 Subject: [PATCH] Handle FDB meta data together with FDB data in fdborch to avoid race condition Signed-off-by: Jipan Yang --- lib/inc/sairedis.h | 7 ++++++ lib/src/sai_redis_notifications.cpp | 34 +++++++++++++++-------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/inc/sairedis.h b/lib/inc/sairedis.h index e70a03ad7..4c03be06a 100644 --- a/lib/inc/sairedis.h +++ b/lib/inc/sairedis.h @@ -106,6 +106,13 @@ typedef enum _sai_redis_switch_attr_t } sai_redis_switch_attr_t; + + +void handle_meta_fdb_event( + _In_ uint32_t count, + _In_ sai_fdb_event_notification_data_t *fdbevent); + + /* * Those bulk APIs are provided as static functions since current SAI 0.9.4 * doesn't support bulk API. Also note that SDK don't support bulk route API diff --git a/lib/src/sai_redis_notifications.cpp b/lib/src/sai_redis_notifications.cpp index 22d2b20bd..b0ee3b6a1 100644 --- a/lib/src/sai_redis_notifications.cpp +++ b/lib/src/sai_redis_notifications.cpp @@ -102,27 +102,29 @@ void handle_fdb_event( SWSS_LOG_DEBUG("data: %s", data.c_str()); - uint32_t count; - sai_fdb_event_notification_data_t *fdbevent = NULL; - - sai_deserialize_fdb_event_ntf(data, count, &fdbevent); - - { - std::lock_guard lock(g_apimutex); - - // NOTE: this meta api must be under mutex since - // it will access meta DB and notification comes - // from different thread - - meta_sai_on_fdb_event(count, fdbevent); - } - if (sn.on_fdb_event != NULL) { + uint32_t count; + sai_fdb_event_notification_data_t *fdbevent = NULL; + + sai_deserialize_fdb_event_ntf(data, count, &fdbevent); sn.on_fdb_event(count, fdbevent); + sai_deserialize_free_fdb_event_ntf(count, fdbevent); } +} + +void handle_meta_fdb_event( + _In_ uint32_t count, + _In_ sai_fdb_event_notification_data_t *fdbevent) +{ + SWSS_LOG_ENTER(); + + std::lock_guard lock(g_apimutex); + // NOTE: this meta api must be under mutex since + // it will access meta DB and notification comes + // from different thread - sai_deserialize_free_fdb_event_ntf(count, fdbevent); + meta_sai_on_fdb_event(count, fdbevent); } void handle_port_state_change(