From 2265f548386929b7827d1079efd453128f1ec1f9 Mon Sep 17 00:00:00 2001 From: Shi Su <67605788+shi-su@users.noreply.github.com> Date: Thu, 29 Oct 2020 09:48:22 -0700 Subject: [PATCH] [neighorch] Remove pending DEL operation after SET operation for the same key (#1485) * Remove del operation if set is successfully done in neighorch * using reverse iterator to travel backwards --- orchagent/neighorch.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/orchagent/neighorch.cpp b/orchagent/neighorch.cpp index 5ba5ec4e27c8..24141008268f 100644 --- a/orchagent/neighorch.cpp +++ b/orchagent/neighorch.cpp @@ -354,13 +354,31 @@ void NeighOrch::doTask(Consumer &consumer) if (m_syncdNeighbors.find(neighbor_entry) == m_syncdNeighbors.end() || m_syncdNeighbors[neighbor_entry] != mac_address) { if (addNeighbor(neighbor_entry, mac_address)) + { it = consumer.m_toSync.erase(it); + } else + { it++; + continue; + } } else + { /* Duplicate entry */ it = consumer.m_toSync.erase(it); + } + + /* Remove remaining DEL operation in m_toSync for the same neighbor. + * Since DEL operation is supposed to be executed before SET for the same neighbor + * A remaining DEL after the SET operation means the DEL operation failed previously and should not be executed anymore + */ + auto rit = make_reverse_iterator(it); + while (rit != consumer.m_toSync.rend() && rit->first == key && kfvOp(rit->second) == DEL_COMMAND) + { + consumer.m_toSync.erase(next(rit).base()); + SWSS_LOG_NOTICE("Removed pending neighbor DEL operation for %s after SET operation", key.c_str()); + } } else if (op == DEL_COMMAND) {