Skip to content

Commit ab0e474

Browse files
authored
swss: Fixing race condition for rif counters (sonic-net#2488)
The cleanup code for stale rif counters are now moved to syncd . Earlier as part of fix for issue sonic-net#2193 the cleanup for stale rif counters was added. But it could create a race condition between orchagent removes RIF rate counters from DB and lua script fetching them. So as a fix all such cleanup has been moved to syncd. - What I did Fix for sonic-net#11621 As a past fix which aimed at removing stale rif counters (sonic-net#2199) , there is a chance of race condition and it leads to lua script reporting error. To handle this , the rif counters cleanup code(handled in cleanUpRifFromCounterDb) is now called from syncd ( removeCounter ) to avoid such race condition. - Why I did it The operations in Orchagent and syncd is not synchronous, so while Orchagent deletes the rif counters from Counters Db, the syncd could still access it. In race conditions the lua script trying to fetch rif counters will have errors syslog for such access as it was already deleted by orchagent. The cleanup code is removed from orchagent is added in syncd - it will make sure no such race condition would get hit. - How I verified it Followed the steps in (sonic-net#11621) : Create RIF in SONiC, wait till RIF rates are populated in COUNTERS DB Remove RIF Repeat the steps multiple times and check if any error syslog is seen (No error syslog is seen) Also checked cleanup for rif counters. After RIF creation derived info of oid for RIF from "COUNTERS_RIF_NAME_MAP" 127) "Vlan100" 128) "oid:0x6000000000aa5" Checked all the tabled in COUNTER_DB which has same OID in keys 127.0.0.1:6379[2]> keys 6000000000aa5 1) "RATES:oid:0x6000000000aa5:RIF" 2) "COUNTERS:oid:0x6000000000aa5" 3) "RATES:oid:0x6000000000aa5" 127.0.0.1:6379[2]> Deleted the RIF by removing the ip on the intf. Checked COUNTER_DB again with same OID if there are stale entries or not. No stale entries exist now. 127.0.0.1:6379[2]> keys 6000000000aa5 (empty array) 127.0.0.1:6379[2]> Signed-off-by: Suman Kumar <suman.kumar@broadcom.com>
1 parent 724f914 commit ab0e474

File tree

2 files changed

+0
-39
lines changed

2 files changed

+0
-39
lines changed

orchagent/intfsorch.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,6 @@ bool IntfsOrch::removeRouterIntfs(Port &port)
12771277

12781278
const auto id = sai_serialize_object_id(port.m_rif_id);
12791279
removeRifFromFlexCounter(id, port.m_alias);
1280-
cleanUpRifFromCounterDb(id, port.m_alias);
12811280

12821281
sai_status_t status = sai_router_intfs_api->remove_router_interface(port.m_rif_id);
12831282
if (status != SAI_STATUS_SUCCESS)
@@ -1500,45 +1499,11 @@ void IntfsOrch::removeRifFromFlexCounter(const string &id, const string &name)
15001499
SWSS_LOG_DEBUG("Unregistered interface %s from Flex counter", name.c_str());
15011500
}
15021501

1503-
/*
1504-
TODO A race condition can exist when swss removes the counter from COUNTERS DB
1505-
and at the same time syncd is inserting a new entry in COUNTERS DB. Therefore
1506-
all the rif counters cleanup code should move to syncd
1507-
*/
1508-
void IntfsOrch::cleanUpRifFromCounterDb(const string &id, const string &name)
1509-
{
1510-
SWSS_LOG_ENTER();
1511-
string counter_key = getRifCounterTableKey(id);
1512-
string rate_key = getRifRateTableKey(id);
1513-
string rate_init_key = getRifRateInitTableKey(id);
1514-
m_counter_db->del(counter_key);
1515-
m_counter_db->del(rate_key);
1516-
m_counter_db->del(rate_init_key);
1517-
SWSS_LOG_NOTICE("CleanUp interface %s oid %s from counter db", name.c_str(),id.c_str());
1518-
}
1519-
15201502
string IntfsOrch::getRifFlexCounterTableKey(string key)
15211503
{
15221504
return string(RIF_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key;
15231505
}
15241506

1525-
string IntfsOrch::getRifCounterTableKey(string key)
1526-
{
1527-
return "COUNTERS:" + key;
1528-
}
1529-
1530-
string IntfsOrch::getRifRateTableKey(string key)
1531-
{
1532-
return "RATES:" + key;
1533-
}
1534-
1535-
string IntfsOrch::getRifRateInitTableKey(string key)
1536-
{
1537-
return "RATES:" + key + ":RIF";
1538-
}
1539-
1540-
1541-
15421507
void IntfsOrch::generateInterfaceMap()
15431508
{
15441509
m_updateMapsTimer->start();

orchagent/intfsorch.h

-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ class IntfsOrch : public Orch
9393
unique_ptr<ProducerTable> m_flexCounterGroupTable;
9494

9595
std::string getRifFlexCounterTableKey(std::string s);
96-
std::string getRifCounterTableKey(std::string s);
97-
std::string getRifRateTableKey(std::string s);
98-
std::string getRifRateInitTableKey(std::string s);
99-
void cleanUpRifFromCounterDb(const string &id, const string &name);
10096

10197
bool addRouterIntfs(sai_object_id_t vrf_id, Port &port, string loopbackAction);
10298
bool removeRouterIntfs(Port &port);

0 commit comments

Comments
 (0)