From 979b623256c8f5311683a9c8d20f52160f6013df Mon Sep 17 00:00:00 2001 From: Suman Kumar Date: Mon, 6 Feb 2023 05:38:15 -0800 Subject: [PATCH] Fixing race condition for rif counters #1136 Changes for 202205 branch Signed-off-by: Suman Kumar --- syncd/FlexCounter.cpp | 33 +++++++++++++++++++++++++++++++++ syncd/FlexCounter.h | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index ac94260f4..47165ddd5 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -1016,6 +1016,38 @@ void FlexCounter::removeFlowCounter( } } +string FlexCounter::getRifCounterTableKey(string key) +{ + SWSS_LOG_ENTER(); + return "COUNTERS:" + key; +} + +string FlexCounter::getRifRateTableKey(string key) +{ + SWSS_LOG_ENTER(); + return "RATES:" + key; +} + +string FlexCounter::getRifRateInitTableKey(string key) +{ + SWSS_LOG_ENTER(); + return "RATES:" + key + ":RIF"; +} + +void FlexCounter::cleanUpRifFromCounterDb(_In_ sai_object_id_t rifId) +{ + SWSS_LOG_ENTER(); + const auto id = sai_serialize_object_id(rifId); + swss::DBConnector db(m_dbCounters, 0); + string counter_key = getRifCounterTableKey(id); + string rate_key = getRifRateTableKey(id); + string rate_init_key = getRifRateInitTableKey(id); + db.del(counter_key); + db.del(rate_key); + db.del(rate_init_key); + SWSS_LOG_NOTICE("CleanUp oid %s from counter db", id.c_str()); +} + void FlexCounter::removeRif( _In_ sai_object_id_t rifVid) { @@ -1030,6 +1062,7 @@ void FlexCounter::removeRif( } m_rifCounterIdsMap.erase(it); + cleanUpRifFromCounterDb(rifVid); if (m_rifCounterIdsMap.empty()) { diff --git a/syncd/FlexCounter.h b/syncd/FlexCounter.h index cfc79b660..ef4bd414a 100644 --- a/syncd/FlexCounter.h +++ b/syncd/FlexCounter.h @@ -50,6 +50,11 @@ namespace syncd bool isDiscarded(); + std::string getRifCounterTableKey(std::string s); + std::string getRifRateTableKey(std::string s); + std::string getRifRateInitTableKey(std::string s); + void cleanUpRifFromCounterDb(_In_ sai_object_id_t rifId); + private: void setPollInterval(