-
Notifications
You must be signed in to change notification settings - Fork 311
Add PublisherEventTable/SubscriberEventTable classes #1020
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
base: master
Are you sure you want to change the base?
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Qi Luo <[email protected]>
Signed-off-by: Qi Luo <[email protected]>
349bab8
to
e306266
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds event-driven pub/sub tables and integrates them into tests and Python bindings
- Introduces
PublisherEventTable
andSubscriberEventTable
for 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
SubscribeEventTable
doesn’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
t
intest_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) |
Copilot
AI
May 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot uses AI. Check for mistakes.
common/publishereventtable.h
Outdated
|
||
namespace swss { | ||
|
||
class PublisherEventTable : public Table { // public TableBase, public TableEntryEnumerable { |
Copilot
AI
May 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Outdated comment // public TableBase, public TableEntryEnumerable
; update or remove it to reflect that this class now inherits directly from Table
.
Copilot uses AI. Check for mistakes.
|
||
/* 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 <[email protected]>
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Co-authored-by: Copilot <[email protected]>
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Co-authored-by: Copilot <[email protected]>
/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 <[email protected]>
/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