From dc621c936c885344cf9b05580116eb3edb69feef Mon Sep 17 00:00:00 2001 From: Suman Kumar <73022268+sumanbrcm@users.noreply.github.com> Date: Fri, 13 May 2022 01:25:04 +0530 Subject: [PATCH] Stale rif counter db removal (fix for #2193)_ (#2199) To handle this , whenever RIF is deleted (removeRouterIntfs) , we ensure that these COUNTER_DB tables are deleted(handled in cleanUpRifFromCounterDb) . --- orchagent/intfsorch.cpp | 30 ++++++++++++++++++++++++++++++ orchagent/intfsorch.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 587e04e140f9..bcb5f6a52bbb 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -1204,6 +1204,7 @@ bool IntfsOrch::removeRouterIntfs(Port &port) const auto id = sai_serialize_object_id(port.m_rif_id); removeRifFromFlexCounter(id, port.m_alias); + cleanUpRifFromCounterDb(id, port.m_alias); sai_status_t status = sai_router_intfs_api->remove_router_interface(port.m_rif_id); if (status != SAI_STATUS_SUCCESS) @@ -1426,11 +1427,40 @@ void IntfsOrch::removeRifFromFlexCounter(const string &id, const string &name) SWSS_LOG_DEBUG("Unregistered interface %s from Flex counter", name.c_str()); } +void IntfsOrch::cleanUpRifFromCounterDb(const string &id, const string &name) +{ + SWSS_LOG_ENTER(); + string counter_key = getRifCounterTableKey(id); + string rate_key = getRifRateTableKey(id); + string rate_init_key = getRifRateInitTableKey(id); + m_counter_db->del(counter_key); + m_counter_db->del(rate_key); + m_counter_db->del(rate_init_key); + SWSS_LOG_NOTICE("CleanUp interface %s oid %s from counter db", name.c_str(),id.c_str()); +} + string IntfsOrch::getRifFlexCounterTableKey(string key) { return string(RIF_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key; } +string IntfsOrch::getRifCounterTableKey(string key) +{ + return "COUNTERS:" + key; +} + +string IntfsOrch::getRifRateTableKey(string key) +{ + return "RATES:" + key; +} + +string IntfsOrch::getRifRateInitTableKey(string key) +{ + return "RATES:" + key + ":RIF"; +} + + + void IntfsOrch::generateInterfaceMap() { m_updateMapsTimer->start(); diff --git a/orchagent/intfsorch.h b/orchagent/intfsorch.h index 5605abf13381..341675bac150 100644 --- a/orchagent/intfsorch.h +++ b/orchagent/intfsorch.h @@ -90,6 +90,10 @@ class IntfsOrch : public Orch unique_ptr m_flexCounterGroupTable; std::string getRifFlexCounterTableKey(std::string s); + std::string getRifCounterTableKey(std::string s); + std::string getRifRateTableKey(std::string s); + std::string getRifRateInitTableKey(std::string s); + void cleanUpRifFromCounterDb(const string &id, const string &name); bool addRouterIntfs(sai_object_id_t vrf_id, Port &port); bool removeRouterIntfs(Port &port);