Skip to content

Commit

Permalink
[warm restart assist] assume vector values could be reordered (sonic-…
Browse files Browse the repository at this point in the history
…net#921)

When comparing 2 vectors, assume their elements could be re-ordered.

Signed-off-by: Ying Xie <ying.xie@microsoft.com>
  • Loading branch information
yxieca authored Jun 3, 2019
1 parent 4194e2e commit f3d0279
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion warmrestart/warmRestartAssist.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <string>
#include <algorithm>
#include "logger.h"
#include "schema.h"
#include "warm_restart.h"
Expand Down Expand Up @@ -173,7 +174,7 @@ void AppRestartAssist::insertToMap(string key, vector<FieldValueTuple> fvVector,
else if (found != appTableCacheMap.end())
{
// check only the original vector range (exclude cache-state field/value)
if(!equal(fvVector.begin(), fvVector.end(), found->second.begin()))
if(! contains(found->second, fvVector))
{
SWSS_LOG_NOTICE("%s, found key: %s, new value ", m_appTableName.c_str(), key.c_str());

Expand Down Expand Up @@ -280,3 +281,18 @@ bool AppRestartAssist::checkReconcileTimer(Selectable *s)
}
return false;
}

// check if left vector contains all elements of right vector
bool AppRestartAssist::contains(const std::vector<FieldValueTuple>& left,
const std::vector<FieldValueTuple>& right)
{
for (auto const& rv : right)
{
if (std::find(left.begin(), left.end(), rv) == left.end())
{
return false;
}
}

return true;
}
2 changes: 2 additions & 0 deletions warmrestart/warmRestartAssist.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class AppRestartAssist
std::string joinVectorString(const std::vector<FieldValueTuple> &fv);
void setCacheEntryState(std::vector<FieldValueTuple> &fvVector, cache_state_t state);
cache_state_t getCacheEntryState(const std::vector<FieldValueTuple> &fvVector);
bool contains(const std::vector<FieldValueTuple>& left,
const std::vector<FieldValueTuple>& right);
};

}
Expand Down

0 comments on commit f3d0279

Please sign in to comment.