Skip to content

Commit

Permalink
Fixing race condition for rif counters sonic-net#1136
Browse files Browse the repository at this point in the history
Changes for 202205 branch

Signed-off-by: Suman Kumar <suman.kumar@broadcom.com>
  • Loading branch information
sumanbrcm committed Feb 7, 2023
1 parent ad3d4d6 commit 979b623
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions syncd/FlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -1030,6 +1062,7 @@ void FlexCounter::removeRif(
}

m_rifCounterIdsMap.erase(it);
cleanUpRifFromCounterDb(rifVid);

if (m_rifCounterIdsMap.empty())
{
Expand Down
5 changes: 5 additions & 0 deletions syncd/FlexCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 979b623

Please sign in to comment.