Skip to content

Commit 2f2a2dd

Browse files
marian-pritsaklguohan
authored andcommitted
[flex_counter]: Fix cleanup flow (sonic-net#285)
Remove objects from flex counter bu key, not when iterating over values because on DEL op there are no values, only key. Fix logic in removeQueue. Signed-off-by: marian-pritsak <[email protected]>
1 parent 36752e1 commit 2f2a2dd

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

syncd/syncd.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,28 +2528,29 @@ void processFlexCounterEvent(
25282528
sai_object_id_t rid = translate_vid_to_rid(vid);
25292529
sai_object_type_t objectType = sai_object_type_query(rid);
25302530

2531+
if (op == DEL_COMMAND)
2532+
{
2533+
if (objectType == SAI_OBJECT_TYPE_PORT)
2534+
{
2535+
FlexCounter::removePort(vid, pollInterval);
2536+
}
2537+
else if (objectType == SAI_OBJECT_TYPE_QUEUE)
2538+
{
2539+
FlexCounter::removeQueue(vid, pollInterval);
2540+
}
2541+
else
2542+
{
2543+
SWSS_LOG_ERROR("Object type for removal not supported");
2544+
}
2545+
}
2546+
25312547
const auto values = kfvFieldsValues(kco);
25322548
for (const auto& valuePair : values)
25332549
{
25342550
const auto field = fvField(valuePair);
25352551
const auto value = fvValue(valuePair);
25362552

2537-
if (op == DEL_COMMAND)
2538-
{
2539-
if (objectType == SAI_OBJECT_TYPE_PORT)
2540-
{
2541-
FlexCounter::removePort(vid, pollInterval);
2542-
}
2543-
else if (objectType == SAI_OBJECT_TYPE_QUEUE)
2544-
{
2545-
FlexCounter::removeQueue(vid, pollInterval);
2546-
}
2547-
else
2548-
{
2549-
SWSS_LOG_ERROR("Object type for removal not supported");
2550-
}
2551-
}
2552-
else if (op == SET_COMMAND)
2553+
if (op == SET_COMMAND)
25532554
{
25542555
auto idStrings = swss::tokenize(value, ',');
25552556

syncd/syncd_flex_counter.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,33 +218,28 @@ void FlexCounter::removeQueue(
218218
{
219219
SWSS_LOG_ENTER();
220220

221+
bool found = false;
221222
FlexCounter &fc = getInstance(pollInterval);
222223

223224
auto counterIter = fc.m_queueCounterIdsMap.find(queueVid);
224-
if (counterIter == fc.m_queueCounterIdsMap.end())
225+
if (counterIter != fc.m_queueCounterIdsMap.end())
225226
{
226-
SWSS_LOG_ERROR("Trying to remove nonexisting queue counter Ids 0x%lx", queueVid);
227-
if (fc.m_queueCounterIdsMap.empty() && fc.m_portCounterIdsMap.empty() && fc.m_queueAttrIdsMap.empty())
228-
{
229-
removeInstance(pollInterval);
230-
}
231-
return;
227+
fc.m_queueCounterIdsMap.erase(counterIter);
228+
found = true;
232229
}
233230

234-
fc.m_queueCounterIdsMap.erase(counterIter);
235-
236231
auto attrIter = fc.m_queueAttrIdsMap.find(queueVid);
237-
if (attrIter == fc.m_queueAttrIdsMap.end())
232+
if (attrIter != fc.m_queueAttrIdsMap.end())
238233
{
239-
SWSS_LOG_ERROR("Trying to remove nonexisting queue attr Ids 0x%lx", queueVid);
240-
if (fc.m_queueCounterIdsMap.empty() && fc.m_portCounterIdsMap.empty() && fc.m_queueAttrIdsMap.empty())
241-
{
242-
removeInstance(pollInterval);
243-
}
244-
return;
234+
fc.m_queueAttrIdsMap.erase(attrIter);
235+
found = true;
245236
}
246237

247-
fc.m_queueAttrIdsMap.erase(attrIter);
238+
if (!found)
239+
{
240+
SWSS_LOG_ERROR("Trying to remove nonexisting queue from flex counter 0x%lx", queueVid);
241+
return;
242+
}
248243

249244
// Remove flex counter if counter IDs map is empty
250245
if (fc.m_queueCounterIdsMap.empty() && fc.m_portCounterIdsMap.empty() && fc.m_queueAttrIdsMap.empty())

0 commit comments

Comments
 (0)