Skip to content

Commit 4d21a26

Browse files
authored
[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 <[email protected]>
1 parent bc3e044 commit 4d21a26

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

syncd/FlexCounter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FlexCounter::FlexCounter(
2626
SWSS_LOG_ENTER();
2727

2828
m_enable = false;
29+
m_isDiscarded = false;
2930

3031
startFlexCounterThread();
3132
}
@@ -819,6 +820,8 @@ void FlexCounter::removeCounterPlugins()
819820
m_rifPlugins.clear();
820821
m_priorityGroupPlugins.clear();
821822
m_bufferPoolPlugins.clear();
823+
824+
m_isDiscarded = true;
822825
}
823826

824827
void FlexCounter::addCounterPlugin(
@@ -828,6 +831,8 @@ void FlexCounter::addCounterPlugin(
828831

829832
SWSS_LOG_ENTER();
830833

834+
m_isDiscarded = false;
835+
831836
for (auto& fvt: values)
832837
{
833838
auto& field = fvField(fvt);
@@ -901,6 +906,11 @@ bool FlexCounter::isEmpty()
901906
return allIdsEmpty() && allPluginsEmpty();
902907
}
903908

909+
bool FlexCounter::isDiscarded()
910+
{
911+
return isEmpty() && m_isDiscarded;
912+
}
913+
904914
bool FlexCounter::allIdsEmpty() const
905915
{
906916
SWSS_LOG_ENTER();

syncd/FlexCounter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ namespace syncd
4848

4949
bool isEmpty();
5050

51+
bool isDiscarded();
52+
5153
private:
5254

5355
void setPollInterval(
@@ -405,5 +407,7 @@ namespace syncd
405407
std::shared_ptr<sairedis::SaiInterface> m_vendorSai;
406408

407409
std::string m_dbCounters;
410+
411+
bool m_isDiscarded;
408412
};
409413
}

syncd/FlexCounterManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void FlexCounterManager::removeCounterPlugins(
6262

6363
fc->removeCounterPlugins();
6464

65-
if (fc->isEmpty())
65+
if (fc->isDiscarded())
6666
{
6767
removeInstance(instanceId);
6868
}
@@ -91,7 +91,7 @@ void FlexCounterManager::addCounter(
9191

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

94-
if (fc->isEmpty())
94+
if (fc->isDiscarded())
9595
{
9696
removeInstance(instanceId);
9797
}
@@ -107,7 +107,7 @@ void FlexCounterManager::removeCounter(
107107

108108
fc->removeCounter(vid);
109109

110-
if (fc->isEmpty())
110+
if (fc->isDiscarded())
111111
{
112112
removeInstance(instanceId);
113113
}

0 commit comments

Comments
 (0)