Skip to content

Conversation

qiluo-msft
Copy link
Contributor

TBD

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft qiluo-msft force-pushed the qiluo/pubsubchannel branch from 349bab8 to e306266 Compare May 29, 2025 23:09
@mssonicbld
Copy link
Collaborator

/azp run

@qiluo-msft qiluo-msft requested a review from Copilot May 29, 2025 23:09
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link

@Copilot Copilot AI left a 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 and SubscriberEventTable 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 class SubscriberEventTable; 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 in test_SubscriberStateTable. You should instantiate a PublisherStateTable (or the appropriate table) before calling set.
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)
Copy link

Copilot AI May 29, 2025

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.

Suggested change
#define REDIS_PUBLISH_MESSAGE_ELEMNTS (3)
#define REDIS_PUBLISH_MESSAGE_ELEMENTS (3)

Copilot uses AI. Check for mistakes.


namespace swss {

class PublisherEventTable : public Table { // public TableBase, public TableEntryEnumerable {
Copy link

Copilot AI May 29, 2025

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

This comment appears to contain commented-out code.
/* 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

This comment appears to contain commented-out code.

// void getKeys(std::vector<std::string> &keys);

// void setBuffered(bool buffered);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

// void setBuffered(bool buffered);

// void flush();

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

// void flush();

// void dump(TableDump &tableDump);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

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

This comment appears to contain commented-out code.
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

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

This comment appears to contain commented-out code.
}
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

This comment appears to contain commented-out code.
// 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

This comment appears to contain commented-out code.
// 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

This comment appears to contain commented-out code.
// 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

This comment appears to contain commented-out code.
Comment on lines +234 to +237
// for (auto &table: eventTables)
// {
// cout << "Event table: " << table << endl;
// }

Check notice

Code scanning / CodeQL

Commented-out code Note test

This comment appears to contain commented-out code.
@bhouse-nexthop
Copy link

Can this effort possibly be used to address sonic-net/sonic-buildimage#22255 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants