Skip to content

Commit

Permalink
Add refillToSync() into ConsumerBase to support warmboot.
Browse files Browse the repository at this point in the history
  • Loading branch information
mint570 committed Jul 24, 2023
1 parent d54c767 commit c4973ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
25 changes: 17 additions & 8 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ size_t ConsumerBase::addToSync(const std::deque<KeyOpFieldsValuesTuple> &entries
}

// TODO: Table should be const
size_t Consumer::refillToSync(Table* table)
size_t ConsumerBase::refillToSync(Table* table)
{
std::deque<KeyOpFieldsValuesTuple> entries;
vector<string> keys;
Expand All @@ -172,9 +172,10 @@ size_t Consumer::refillToSync(Table* table)
return addToSync(entries);
}

size_t Consumer::refillToSync()
size_t ConsumerBase::refillToSync()
{
auto subTable = dynamic_cast<SubscriberStateTable *>(getSelectable());
auto consumertable = dynamic_cast<ConsumerTableBase *>(getSelectable());
if (subTable != NULL)
{
size_t update_size = 0;
Expand All @@ -188,14 +189,22 @@ size_t Consumer::refillToSync()
} while (update_size != 0);
return total_size;
}
else
else if (consumertable != NULL)
{
// consumerTable is either ConsumerStateTable or ConsumerTable
auto db = getDbConnector();
auto db = consumertable->getDbConnector();
string tableName = getTableName();
auto table = Table(db, tableName);
return refillToSync(&table);
}
else
{
// The consumerTable should be ZmqConsumerStateTable.
DBConnector db("APPL_DB", 0);
string tableName = getTableName();
auto table = Table(&db, tableName);
return refillToSync(&table);
}
}

string ConsumerBase::dumpTuple(const KeyOpFieldsValuesTuple &tuple)
Expand Down Expand Up @@ -246,7 +255,7 @@ void Consumer::drain()

size_t Orch::addExistingData(const string& tableName)
{
auto consumer = dynamic_cast<Consumer *>(getExecutor(tableName));
auto consumer = dynamic_cast<ConsumerBase *>(getExecutor(tableName));
if (consumer == NULL)
{
SWSS_LOG_ERROR("No consumer %s in Orch", tableName.c_str());
Expand All @@ -260,7 +269,7 @@ size_t Orch::addExistingData(const string& tableName)
size_t Orch::addExistingData(Table *table)
{
string tableName = table->getTableName();
Consumer* consumer = dynamic_cast<Consumer *>(getExecutor(tableName));
ConsumerBase* consumer = dynamic_cast<ConsumerBase *>(getExecutor(tableName));
if (consumer == NULL)
{
SWSS_LOG_ERROR("No consumer %s in Orch", tableName.c_str());
Expand All @@ -278,7 +287,7 @@ bool Orch::bake()
{
string executorName = it.first;
auto executor = it.second;
auto consumer = dynamic_cast<Consumer *>(executor.get());
auto consumer = dynamic_cast<ConsumerBase *>(executor.get());
if (consumer == NULL)
{
continue;
Expand Down Expand Up @@ -530,7 +539,7 @@ void Orch::dumpPendingTasks(vector<string> &ts)
{
for (auto &it : m_consumerMap)
{
Consumer* consumer = dynamic_cast<Consumer *>(it.second.get());
ConsumerBase* consumer = dynamic_cast<ConsumerBase *>(it.second.get());
if (consumer == NULL)
{
SWSS_LOG_DEBUG("Executor is not a Consumer");
Expand Down
5 changes: 3 additions & 2 deletions orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ class ConsumerBase : public Executor {

// Returns: the number of entries added to m_toSync
size_t addToSync(const std::deque<swss::KeyOpFieldsValuesTuple> &entries);

size_t refillToSync();
size_t refillToSync(swss::Table* table);
};

class Consumer : public ConsumerBase {
Expand Down Expand Up @@ -192,8 +195,6 @@ class Consumer : public ConsumerBase {
return getDbConnector()->getDbName();
}

size_t refillToSync();
size_t refillToSync(swss::Table* table);
void execute() override;
void drain() override;
};
Expand Down

0 comments on commit c4973ea

Please sign in to comment.