Skip to content

Commit

Permalink
[syncd/FlexCounter]:Fix last remove bug (#679)
Browse files Browse the repository at this point in the history
- The bug description
When the last object in FlexCounter was removed, the FlexCounter is also removed from FlexCounterManager. At the next time, when a new observed object is added and a new FlexCounter will be created. But the new FlexCounter cannot get the configuration. Because the configuration message from FlexCounterDB has been consumed at the first time.

- How to fix it
Add a flag to indicate whether the configuration also be removed from the FlexCounterDB. If not, don't delete the FlexCounter from FlexCounterManager even no observed objects in the FlexCounter.

Signed-off-by: Ze Gan <ganze718@gmail.com>
  • Loading branch information
Pterosaur authored Oct 24, 2020
1 parent bc3e044 commit 4d21a26
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions syncd/FlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ FlexCounter::FlexCounter(
SWSS_LOG_ENTER();

m_enable = false;
m_isDiscarded = false;

startFlexCounterThread();
}
Expand Down Expand Up @@ -819,6 +820,8 @@ void FlexCounter::removeCounterPlugins()
m_rifPlugins.clear();
m_priorityGroupPlugins.clear();
m_bufferPoolPlugins.clear();

m_isDiscarded = true;
}

void FlexCounter::addCounterPlugin(
Expand All @@ -828,6 +831,8 @@ void FlexCounter::addCounterPlugin(

SWSS_LOG_ENTER();

m_isDiscarded = false;

for (auto& fvt: values)
{
auto& field = fvField(fvt);
Expand Down Expand Up @@ -901,6 +906,11 @@ bool FlexCounter::isEmpty()
return allIdsEmpty() && allPluginsEmpty();
}

bool FlexCounter::isDiscarded()
{
return isEmpty() && m_isDiscarded;
}

bool FlexCounter::allIdsEmpty() const
{
SWSS_LOG_ENTER();
Expand Down
4 changes: 4 additions & 0 deletions syncd/FlexCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace syncd

bool isEmpty();

bool isDiscarded();

private:

void setPollInterval(
Expand Down Expand Up @@ -405,5 +407,7 @@ namespace syncd
std::shared_ptr<sairedis::SaiInterface> m_vendorSai;

std::string m_dbCounters;

bool m_isDiscarded;
};
}
6 changes: 3 additions & 3 deletions syncd/FlexCounterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void FlexCounterManager::removeCounterPlugins(

fc->removeCounterPlugins();

if (fc->isEmpty())
if (fc->isDiscarded())
{
removeInstance(instanceId);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ void FlexCounterManager::addCounter(

fc->addCounter(vid, rid, values);

if (fc->isEmpty())
if (fc->isDiscarded())
{
removeInstance(instanceId);
}
Expand All @@ -107,7 +107,7 @@ void FlexCounterManager::removeCounter(

fc->removeCounter(vid);

if (fc->isEmpty())
if (fc->isDiscarded())
{
removeInstance(instanceId);
}
Expand Down

0 comments on commit 4d21a26

Please sign in to comment.