Add PublisherEventTable/SubscriberEventTable classes#1020
Add PublisherEventTable/SubscriberEventTable classes#1020qiluo-msft wants to merge 19 commits intosonic-net:masterfrom
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>
349bab8 to
e306266
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull Request Overview
Adds event-driven pub/sub tables and integrates them into tests and Python bindings
- Introduces
PublisherEventTableandSubscriberEventTablefor JSON-based Redis pub/sub - Exposes new classes in SWIG (
swsscommon.i) for Python support - Adds C++ and Python unit tests and updates build scripts to compile new sources
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| common/publishereventtable.h/.cpp | Implements PublisherEventTable with JSON message building and publish |
| common/subscribereventtable.h/.cpp | Implements SubscriberEventTable buffering, parsing, and pops APIs |
| pyext/swsscommon.i | Adds SWIG bindings for the new event table classes |
| tests/test_redis_ut.py | Adds Python tests for state and event table pub/sub behavior |
| tests/redis_subscriber_state_ut.cpp | Adds C++ tests for SubscriberEventTable |
| common/Makefile.am | Includes new source files in the build |
Comments suppressed due to low confidence (4)
tests/redis_subscriber_state_ut.cpp:227
- Test suite name
SubscribeEventTabledoesn’t match the classSubscriberEventTable; rename for consistency.
TEST(SubscribeEventTable, set)
common/subscribereventtable.cpp:127
- No existing unit tests cover the
pops()batch API; consider adding tests for multiple queued events to verify correct behavior.
void SubscriberEventTable::pops(deque<KeyOpFieldsValuesTuple> &vkco, const string& /*prefix*/)
tests/test_redis_ut.py:90
- Undefined variable
tintest_SubscriberStateTable. You should instantiate aPublisherStateTable(or the appropriate table) before callingset.
t.set("aaa", fvs)
pyext/swsscommon.i:301
- [nitpick] Duplicate
%include "publishereventtable.h"; remove the redundant inclusion to clean up the bindings file.
%include "publishereventtable.h"
| namespace swss { | ||
|
|
||
| // TODO: reuse | ||
| #define REDIS_PUBLISH_MESSAGE_ELEMNTS (3) |
There was a problem hiding this comment.
Typo in macro name REDIS_PUBLISH_MESSAGE_ELEMNTS; consider renaming to REDIS_PUBLISH_MESSAGE_ELEMENTS.
| #define REDIS_PUBLISH_MESSAGE_ELEMNTS (3) | |
| #define REDIS_PUBLISH_MESSAGE_ELEMENTS (3) |
common/publishereventtable.h
Outdated
|
|
||
| namespace swss { | ||
|
|
||
| class PublisherEventTable : public Table { // public TableBase, public TableEntryEnumerable { |
There was a problem hiding this comment.
[nitpick] Outdated comment // public TableBase, public TableEntryEnumerable; update or remove it to reflect that this class now inherits directly from Table.
|
|
||
| /* Read a value from the DB directly */ | ||
| /* Returns false if the key doesn't exists */ | ||
| // virtual bool get(const std::string &key, std::vector<FieldValueTuple> &ovalues); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| /* Returns false if the key doesn't exists */ | ||
| // virtual bool get(const std::string &key, std::vector<FieldValueTuple> &ovalues); | ||
|
|
||
| // void getKeys(std::vector<std::string> &keys); |
Check notice
Code scanning / CodeQL
Commented-out code Note
|
|
||
| // void getKeys(std::vector<std::string> &keys); | ||
|
|
||
| // void setBuffered(bool buffered); |
Check notice
Code scanning / CodeQL
Commented-out code Note
|
|
||
| // void setBuffered(bool buffered); | ||
|
|
||
| // void flush(); |
Check notice
Code scanning / CodeQL
Commented-out code Note
|
|
||
| // void flush(); | ||
|
|
||
| // void dump(TableDump &tableDump); |
Check notice
Code scanning / CodeQL
Commented-out code Note
|
|
||
| if (reply->type != REDIS_REPLY_ARRAY) | ||
| { | ||
| // SWSS_LOG_ERROR("expected ARRAY redis reply on channel %s, got: %d", m_channel.c_str(), reply->type); |
Check notice
Code scanning / CodeQL
Commented-out code Note
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
confliction in one redis instance across multiple databases
Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| for (auto& eventTable: it.value()["event_tables"]) | ||
| { | ||
| eventTables.emplace(eventTable); | ||
| // printf("Event table: %s %s\n", dbName.c_str(), eventTable.get<string>().c_str()); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| } | ||
| else | ||
| { | ||
| // printf("Warning: event_tables not found for database %s, using empty set\n", dbName.c_str()); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| // inst_entry.size(), db_entry.size(), separator_entry.size(), db_entry["CONFIG_DB"].eventTables.size()); | ||
| m_inst_info.emplace(empty_key, std::move(inst_entry)); | ||
| m_db_info.emplace(empty_key, std::move(db_entry)); | ||
| // printf("m_db_info %lu\n", m_db_info[empty_key]["CONFIG_DB"].eventTables.size()); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| // printf("SonicDBConfig::getEventTables: dbName=%s, netns=%s, containerName=%s, %lu\n", | ||
| // dbName.c_str(), netns.c_str(), containerName.c_str(), m_db_info[key][dbName].eventTables.size()); | ||
| auto ret = getEventTables(dbName, key); | ||
| // printf("SonicDBConfig::getEventTables: %lu\n", ret.size()); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| // printf("SonicDBConfig::getEventTables2: dbName=%s, %lu\n", | ||
| // dbName.c_str(), m_db_info[key][dbName].eventTables.size()); | ||
| auto ret = getDbInfo(dbName, key).eventTables; | ||
| // printf("SonicDBConfig::getEventTables2: %lu\n", ret.size()); |
Check notice
Code scanning / CodeQL
Commented-out code Note
| // for (auto &table: eventTables) | ||
| // { | ||
| // cout << "Event table: " << table << endl; | ||
| // } |
Check notice
Code scanning / CodeQL
Commented-out code Note test
|
Can this effort possibly be used to address sonic-net/sonic-buildimage#22255 ? |
TBD