Skip to content

Commit f3d0279

Browse files
authored
[warm restart assist] assume vector values could be reordered (sonic-net#921)
When comparing 2 vectors, assume their elements could be re-ordered. Signed-off-by: Ying Xie <[email protected]>
1 parent 4194e2e commit f3d0279

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

warmrestart/warmRestartAssist.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <string>
2+
#include <algorithm>
23
#include "logger.h"
34
#include "schema.h"
45
#include "warm_restart.h"
@@ -173,7 +174,7 @@ void AppRestartAssist::insertToMap(string key, vector<FieldValueTuple> fvVector,
173174
else if (found != appTableCacheMap.end())
174175
{
175176
// check only the original vector range (exclude cache-state field/value)
176-
if(!equal(fvVector.begin(), fvVector.end(), found->second.begin()))
177+
if(! contains(found->second, fvVector))
177178
{
178179
SWSS_LOG_NOTICE("%s, found key: %s, new value ", m_appTableName.c_str(), key.c_str());
179180

@@ -280,3 +281,18 @@ bool AppRestartAssist::checkReconcileTimer(Selectable *s)
280281
}
281282
return false;
282283
}
284+
285+
// check if left vector contains all elements of right vector
286+
bool AppRestartAssist::contains(const std::vector<FieldValueTuple>& left,
287+
const std::vector<FieldValueTuple>& right)
288+
{
289+
for (auto const& rv : right)
290+
{
291+
if (std::find(left.begin(), left.end(), rv) == left.end())
292+
{
293+
return false;
294+
}
295+
}
296+
297+
return true;
298+
}

warmrestart/warmRestartAssist.h

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ class AppRestartAssist
115115
std::string joinVectorString(const std::vector<FieldValueTuple> &fv);
116116
void setCacheEntryState(std::vector<FieldValueTuple> &fvVector, cache_state_t state);
117117
cache_state_t getCacheEntryState(const std::vector<FieldValueTuple> &fvVector);
118+
bool contains(const std::vector<FieldValueTuple>& left,
119+
const std::vector<FieldValueTuple>& right);
118120
};
119121

120122
}

0 commit comments

Comments
 (0)