Skip to content

Commit 979b623

Browse files
committed
Fixing race condition for rif counters #1136
Changes for 202205 branch Signed-off-by: Suman Kumar <[email protected]>
1 parent ad3d4d6 commit 979b623

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

syncd/FlexCounter.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,38 @@ void FlexCounter::removeFlowCounter(
10161016
}
10171017
}
10181018

1019+
string FlexCounter::getRifCounterTableKey(string key)
1020+
{
1021+
SWSS_LOG_ENTER();
1022+
return "COUNTERS:" + key;
1023+
}
1024+
1025+
string FlexCounter::getRifRateTableKey(string key)
1026+
{
1027+
SWSS_LOG_ENTER();
1028+
return "RATES:" + key;
1029+
}
1030+
1031+
string FlexCounter::getRifRateInitTableKey(string key)
1032+
{
1033+
SWSS_LOG_ENTER();
1034+
return "RATES:" + key + ":RIF";
1035+
}
1036+
1037+
void FlexCounter::cleanUpRifFromCounterDb(_In_ sai_object_id_t rifId)
1038+
{
1039+
SWSS_LOG_ENTER();
1040+
const auto id = sai_serialize_object_id(rifId);
1041+
swss::DBConnector db(m_dbCounters, 0);
1042+
string counter_key = getRifCounterTableKey(id);
1043+
string rate_key = getRifRateTableKey(id);
1044+
string rate_init_key = getRifRateInitTableKey(id);
1045+
db.del(counter_key);
1046+
db.del(rate_key);
1047+
db.del(rate_init_key);
1048+
SWSS_LOG_NOTICE("CleanUp oid %s from counter db", id.c_str());
1049+
}
1050+
10191051
void FlexCounter::removeRif(
10201052
_In_ sai_object_id_t rifVid)
10211053
{
@@ -1030,6 +1062,7 @@ void FlexCounter::removeRif(
10301062
}
10311063

10321064
m_rifCounterIdsMap.erase(it);
1065+
cleanUpRifFromCounterDb(rifVid);
10331066

10341067
if (m_rifCounterIdsMap.empty())
10351068
{

syncd/FlexCounter.h

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ namespace syncd
5050

5151
bool isDiscarded();
5252

53+
std::string getRifCounterTableKey(std::string s);
54+
std::string getRifRateTableKey(std::string s);
55+
std::string getRifRateInitTableKey(std::string s);
56+
void cleanUpRifFromCounterDb(_In_ sai_object_id_t rifId);
57+
5358
private:
5459

5560
void setPollInterval(

0 commit comments

Comments
 (0)