Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TableBase] Make channel name from both table name and database ID #568

Merged
merged 8 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/consumerstatetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ConsumerStateTable::ConsumerStateTable(DBConnector *db, const std::string &table
watch.checkStatusOK();
multi();
enqueue(std::string("SCARD ") + getKeySetName(), REDIS_REPLY_INTEGER);
subscribe(m_db, getChannelName());
subscribe(m_db, getChannelName(m_db->getDbId()));
bool succ = exec();
if (succ) break;
}
Expand Down
2 changes: 1 addition & 1 deletion common/consumertable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ConsumerTable::ConsumerTable(DBConnector *db, const string &tableName, int popBa
watch.checkStatusOK();
multi();
enqueue(string("LLEN ") + getKeyValueOpQueueTableName(), REDIS_REPLY_INTEGER);
subscribe(m_db, getChannelName());
subscribe(m_db, getChannelName(m_db->getDbId()));
enqueue(string("LLEN ") + getKeyValueOpQueueTableName(), REDIS_REPLY_INTEGER);
bool succ = exec();
if (succ) break;
Expand Down
2 changes: 1 addition & 1 deletion common/notificationconsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ swss::NotificationConsumer::NotificationConsumer(swss::DBConnector *db, const st
POP_BATCH_SIZE(popBatchSize),
m_db(db),
m_subscribe(NULL),
m_channel(channel)
m_channel(channel + "@" + std::to_string(db->getDbId()))
{
SWSS_LOG_ENTER();

Expand Down
2 changes: 1 addition & 1 deletion common/notificationproducer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "notificationproducer.h"

swss::NotificationProducer::NotificationProducer(swss::DBConnector *db, const std::string &channel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotificationProducer

Do you need to change NotificationConsumer accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Hold on the change of channel name tagged dbId for Notification Producer/Consumer. Some lua scripts like pfc_restore.lua, pfe_detect are using redis PUBLISH command directly with hardcode channel name.

m_db(db), m_channel(channel)
m_db(db), m_channel(channel + "@" + std::to_string(db->getDbId()))
{
}

Expand Down
6 changes: 3 additions & 3 deletions common/producerstatetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void ProducerStateTable::set(const string &key, const vector<FieldValueTuple> &v
args.emplace_back("EVALSHA");
args.emplace_back(m_shaSet);
args.emplace_back(to_string(values.size() + 2));
args.emplace_back(getChannelName());
args.emplace_back(getChannelName(m_pipe->getDbId()));
args.emplace_back(getKeySetName());

args.insert(args.end(), values.size(), getStateHashPrefix() + getKeyName(key));
Expand Down Expand Up @@ -133,7 +133,7 @@ void ProducerStateTable::del(const string &key, const string &op /*= DEL_COMMAND
args.emplace_back("EVALSHA");
args.emplace_back(m_shaDel);
args.emplace_back("4");
args.emplace_back(getChannelName());
args.emplace_back(getChannelName(m_pipe->getDbId()));
args.emplace_back(getKeySetName());
args.emplace_back(getStateHashPrefix() + getKeyName(key));
args.emplace_back(getDelKeySetName());
Expand Down Expand Up @@ -307,7 +307,7 @@ void ProducerStateTable::apply_temp_view()
args.emplace_back("EVALSHA");
args.emplace_back(m_shaApplyView);
args.emplace_back(to_string(m_tempViewState.size() + 3));
args.emplace_back(getChannelName());
args.emplace_back(getChannelName(m_pipe->getDbId()));
args.emplace_back(getKeySetName());
args.emplace_back(getDelKeySetName());

Expand Down
2 changes: 1 addition & 1 deletion common/producertable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ProducerTable::enqueueDbChange(const string &key, const string &value, cons
"EVALSHA %s 2 %s %s %s %s %s %s",
m_shaEnque.c_str(),
getKeyValueOpQueueTableName().c_str(),
getChannelName().c_str(),
getChannelName(m_pipe->getDbId()).c_str(),
key.c_str(),
value.c_str(),
op.c_str(),
Expand Down
12 changes: 12 additions & 0 deletions common/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ class TableBase {
}

std::string getChannelName() { return m_tableName + "_CHANNEL"; }

/* Return tagged channel name */
std::string getChannelName(const std::string &tag)
{
return m_tableName + "_CHANNEL" + "@" + tag;
}

/* Return tagged channel name, most likely tag number could be dbId */
std::string getChannelName(int tag)
{
return getChannelName(std::to_string(tag));
}
private:
static const std::string TABLE_NAME_SEPARATOR_COLON;
static const std::string TABLE_NAME_SEPARATOR_VBAR;
Expand Down