Skip to content

Commit

Permalink
Detect duplicated executorName and throw (sonic-net#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiluo-msft authored Aug 14, 2018
1 parent c9ed2c4 commit b47df72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 8 additions & 9 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
#include <iostream>
#include <unordered_map>
#include <map>
#include <memory>
#include <thread>
#include <chrono>
#include <getopt.h>
Expand Down Expand Up @@ -251,16 +252,16 @@ int main(int argc, char **argv)
DBConnector config_db(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector state_db(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);

OrchDaemon *orchDaemon = new OrchDaemon(&appl_db, &config_db, &state_db);
if (!orchDaemon->init())
{
SWSS_LOG_ERROR("Failed to initialize orchstration daemon");
delete orchDaemon;
exit(EXIT_FAILURE);
}
auto orchDaemon = make_shared<OrchDaemon>(&appl_db, &config_db, &state_db);

try
{
if (!orchDaemon->init())
{
SWSS_LOG_ERROR("Failed to initialize orchstration daemon");
exit(EXIT_FAILURE);
}

SWSS_LOG_NOTICE("Notify syncd APPLY_VIEW");

attr.id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD;
Expand All @@ -270,7 +271,6 @@ int main(int argc, char **argv)
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to notify syncd APPLY_VIEW %d", status);
delete orchDaemon;
exit(EXIT_FAILURE);
}

Expand All @@ -285,6 +285,5 @@ int main(int argc, char **argv)
SWSS_LOG_ERROR("Failed due to exception: %s", e.what());
}

delete orchDaemon;
return 0;
}
8 changes: 7 additions & 1 deletion orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,15 @@ void Orch::addConsumer(DBConnector *db, string tableName, int pri)

void Orch::addExecutor(string executorName, Executor* executor)
{
m_consumerMap.emplace(std::piecewise_construct,
auto inserted = m_consumerMap.emplace(std::piecewise_construct,
std::forward_as_tuple(executorName),
std::forward_as_tuple(executor));

// If there is duplication of executorName in m_consumerMap, logic error
if (!inserted.second)
{
SWSS_LOG_THROW("Duplicated executorName in m_consumerMap: %s", executorName.c_str());
}
}

Executor *Orch::getExecutor(string executorName)
Expand Down

0 comments on commit b47df72

Please sign in to comment.