From 4d21a264d5956501bf69ad3a89ea2ebccd369654 Mon Sep 17 00:00:00 2001 From: Ze Gan Date: Sun, 25 Oct 2020 03:42:08 +0800 Subject: [PATCH] [syncd/FlexCounter]:Fix last remove bug (#679) - 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 --- syncd/FlexCounter.cpp | 10 ++++++++++ syncd/FlexCounter.h | 4 ++++ syncd/FlexCounterManager.cpp | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index 0cbd1f95ff36..313fd046833d 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -26,6 +26,7 @@ FlexCounter::FlexCounter( SWSS_LOG_ENTER(); m_enable = false; + m_isDiscarded = false; startFlexCounterThread(); } @@ -819,6 +820,8 @@ void FlexCounter::removeCounterPlugins() m_rifPlugins.clear(); m_priorityGroupPlugins.clear(); m_bufferPoolPlugins.clear(); + + m_isDiscarded = true; } void FlexCounter::addCounterPlugin( @@ -828,6 +831,8 @@ void FlexCounter::addCounterPlugin( SWSS_LOG_ENTER(); + m_isDiscarded = false; + for (auto& fvt: values) { auto& field = fvField(fvt); @@ -901,6 +906,11 @@ bool FlexCounter::isEmpty() return allIdsEmpty() && allPluginsEmpty(); } +bool FlexCounter::isDiscarded() +{ + return isEmpty() && m_isDiscarded; +} + bool FlexCounter::allIdsEmpty() const { SWSS_LOG_ENTER(); diff --git a/syncd/FlexCounter.h b/syncd/FlexCounter.h index d5d256c9af83..3134b19a1af1 100644 --- a/syncd/FlexCounter.h +++ b/syncd/FlexCounter.h @@ -48,6 +48,8 @@ namespace syncd bool isEmpty(); + bool isDiscarded(); + private: void setPollInterval( @@ -405,5 +407,7 @@ namespace syncd std::shared_ptr m_vendorSai; std::string m_dbCounters; + + bool m_isDiscarded; }; } diff --git a/syncd/FlexCounterManager.cpp b/syncd/FlexCounterManager.cpp index cf9e8752d308..134ebc9db1cb 100644 --- a/syncd/FlexCounterManager.cpp +++ b/syncd/FlexCounterManager.cpp @@ -62,7 +62,7 @@ void FlexCounterManager::removeCounterPlugins( fc->removeCounterPlugins(); - if (fc->isEmpty()) + if (fc->isDiscarded()) { removeInstance(instanceId); } @@ -91,7 +91,7 @@ void FlexCounterManager::addCounter( fc->addCounter(vid, rid, values); - if (fc->isEmpty()) + if (fc->isDiscarded()) { removeInstance(instanceId); } @@ -107,7 +107,7 @@ void FlexCounterManager::removeCounter( fc->removeCounter(vid); - if (fc->isEmpty()) + if (fc->isDiscarded()) { removeInstance(instanceId); }