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 6, 2023
1 parent ad3d4d6 commit 54bf9e7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions syncd/FlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,36 @@ void FlexCounter::removeFlowCounter(
}
}

string FlexCounter::getRifCounterTableKey(string key)
{
return "COUNTERS:" + key;
}

string FlexCounter::getRifRateTableKey(string key)
{
return "RATES:" + key;
}

string FlexCounter::getRifRateInitTableKey(string key)
{
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 +1060,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 54bf9e7

Please sign in to comment.