-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[orchagent] orchagent: Adding capablility of working with several tables
* Modified Orch classes to be able to hold several ConsumerTable classes Signed-off-by: Hrachya Mughnetsyan [email protected]
- Loading branch information
Hrachya Mughnetsyan
authored and
Shuotian Cheng
committed
Apr 19, 2016
1 parent
36b7791
commit 2a4cc2a
Showing
11 changed files
with
148 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,108 @@ | ||
#include "orch.h" | ||
|
||
#include "logger.h" | ||
|
||
using namespace swss; | ||
|
||
Orch::Orch(DBConnector *db, string tableName) : | ||
m_db(db), m_name(tableName) | ||
m_db(db) | ||
{ | ||
m_consumer = new ConsumerTable(m_db, tableName); | ||
Consumer consumer(new ConsumerTable(m_db, tableName)); | ||
m_consumerMap.insert(ConsumerMapPair(tableName, consumer)); | ||
} | ||
|
||
Orch::Orch(DBConnector *db, vector<string> &tableNames) : | ||
m_db(db) | ||
{ | ||
for( auto it = tableNames.begin(); it != tableNames.end(); it++) { | ||
Consumer consumer(new ConsumerTable(m_db, *it)); | ||
m_consumerMap.insert(ConsumerMapPair(*it, consumer)); | ||
} | ||
} | ||
|
||
Orch::~Orch() | ||
{ | ||
delete(m_db); | ||
delete(m_consumer); | ||
for(auto it : m_consumerMap) { | ||
delete it.second.m_consumer; | ||
} | ||
} | ||
|
||
void Orch::execute() | ||
std::vector<Selectable*> Orch::getConsumers() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
KeyOpFieldsValuesTuple t; | ||
m_consumer->pop(t); | ||
std::vector<Selectable*> consumers; | ||
for(auto it : m_consumerMap) { | ||
consumers.push_back(it.second.m_consumer); | ||
} | ||
return consumers; | ||
} | ||
|
||
bool Orch::hasConsumer(ConsumerTable *consumer) const | ||
{ | ||
for(auto it : m_consumerMap) { | ||
if(it.second.m_consumer == consumer) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool Orch::execute(string tableName) | ||
{ | ||
auto consumer_it = m_consumerMap.find(tableName); | ||
if(consumer_it == m_consumerMap.end()) { | ||
SWSS_LOG_ERROR("Unrecognized tableName:%s\n", tableName.c_str()); | ||
return false; | ||
} | ||
Consumer& consumer = consumer_it->second; | ||
|
||
KeyOpFieldsValuesTuple new_data; | ||
consumer.m_consumer->pop(new_data); | ||
|
||
string key = kfvKey(t); | ||
string op = kfvOp(t); | ||
string key = kfvKey(new_data); | ||
string op = kfvOp(new_data); | ||
|
||
#ifdef DEBUG | ||
string debug = "Orch : " + m_name + " key : " + kfvKey(t) + " op : " + kfvOp(t); | ||
for (auto i = kfvFieldsValues(t).begin(); i != kfvFieldsValues(t).end(); i++) | ||
string debug = "Table : " + consumer.m_consumer.getTableName() + " key : " + kfvKey(new_data) + " op : " + kfvOp(new_data); | ||
for (auto i = kfvFieldsValues(new_data).begin(); i != kfvFieldsValues(new_data).end(); i++) | ||
debug += " " + fvField(*i) + " : " + fvValue(*i); | ||
SWSS_LOG_DEBUG("%s\n", debug.c_str()); | ||
#endif | ||
|
||
/* If a new task comes or if a DEL task comes, we directly put it into m_toSync map */ | ||
if ( m_toSync.find(key) == m_toSync.end() || op == DEL_COMMAND) | ||
/* If a new task comes or if a DEL task comes, we directly put it into consumer.m_toSync map */ | ||
if ( consumer.m_toSync.find(key) == consumer.m_toSync.end() || op == DEL_COMMAND) | ||
{ | ||
m_toSync[key] = t; | ||
consumer.m_toSync[key] = new_data; | ||
} | ||
/* If an old task is still there, we combine the old task with new task */ | ||
else | ||
{ | ||
KeyOpFieldsValuesTuple u = m_toSync[key]; | ||
KeyOpFieldsValuesTuple existing_data = consumer.m_toSync[key]; | ||
|
||
auto tt = kfvFieldsValues(t); | ||
auto uu = kfvFieldsValues(u); | ||
auto new_values = kfvFieldsValues(new_data); | ||
auto existing_values = kfvFieldsValues(existing_data); | ||
|
||
|
||
for (auto it = tt.begin(); it != tt.end(); it++) | ||
for (auto it = new_values.begin(); it != new_values.end(); it++) | ||
{ | ||
string field = fvField(*it); | ||
string value = fvValue(*it); | ||
|
||
auto iu = uu.begin(); | ||
while (iu != uu.end()) | ||
auto iu = existing_values.begin(); | ||
while (iu != existing_values.end()) | ||
{ | ||
string ofield = fvField(*iu); | ||
if (field == ofield) | ||
iu = uu.erase(iu); | ||
iu = existing_values.erase(iu); | ||
else | ||
iu++; | ||
} | ||
uu.push_back(FieldValueTuple(field, value)); | ||
existing_values.push_back(FieldValueTuple(field, value)); | ||
} | ||
m_toSync[key] = KeyOpFieldsValuesTuple(key, op, uu); | ||
consumer.m_toSync[key] = KeyOpFieldsValuesTuple(key, op, existing_values); | ||
} | ||
|
||
doTask(); | ||
doTask(consumer); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.