-
Notifications
You must be signed in to change notification settings - Fork 287
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
Publish events for select operation and getresponse failure #1142
base: master
Are you sure you want to change the base?
Changes from all commits
4ac150f
3f9993d
bf3b16e
6930f14
e710bf0
f594359
6770dfa
4d80abf
e51175f
f1c9400
ecd6c2d
0d9e2c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,12 @@ | |
|
||
#include "swss/logger.h" | ||
#include "swss/select.h" | ||
#include "swss/events.h" | ||
|
||
using namespace sairedis; | ||
|
||
event_handle_t g_events_handle; | ||
|
||
RedisChannel::RedisChannel( | ||
_In_ const std::string& dbAsic, | ||
_In_ Channel::Callback callback): | ||
|
@@ -32,6 +35,9 @@ RedisChannel::RedisChannel( | |
SWSS_LOG_NOTICE("creating notification thread"); | ||
|
||
m_notificationThread = std::make_shared<std::thread>(&RedisChannel::notificationThreadFunction, this); | ||
|
||
g_events_handle = events_init_publisher("sonic-events-swss"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Channel will be use by multi-thread, however the implementation of events_init_publisher()/events_deinit_publisher() are no thread safe, because it access a std::map: so suggest improve the events.cpp code first before this PR merge. |
||
|
||
} | ||
|
||
RedisChannel::~RedisChannel() | ||
|
@@ -48,6 +54,8 @@ RedisChannel::~RedisChannel() | |
m_notificationThread->join(); | ||
|
||
SWSS_LOG_NOTICE("join ntf thread end"); | ||
|
||
events_deinit_publisher(g_events_handle); | ||
} | ||
|
||
std::shared_ptr<swss::DBConnector> RedisChannel::getDbConnector() const | ||
|
@@ -177,6 +185,13 @@ sai_status_t RedisChannel::wait( | |
} | ||
|
||
SWSS_LOG_ERROR("SELECT operation result: %s on %s", swss::Select::resultToString(result).c_str(), command.c_str()); | ||
|
||
m_event_params = { | ||
{ "operation_result", swss::Select::resultToString(result) }, | ||
{ "command", command }}; | ||
|
||
event_publish(g_events_handle, "select-operation-failure", &m_event_params); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As my understand the requirement want to send this event to subscriptor, so e_event_params not necessary to be a data member. Also UT should receive event send here and check, not necessary to check parameters. And if we decide use a global publisher, zmq send is not thread safe, we need add lock here or improve the event code first: |
||
|
||
break; | ||
} | ||
|
||
|
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.
If we decide use a global event publisher, then this should not be init/de-init in class level.
Because this is a global variable, but in dtor of RedisChannel the global variable will be deleted. Then when one RedisChannel instance deleted, all other instance will break when send event.
Please check the source code of deinit:
https://github.com/sonic-net/sonic-swss-common/blob/bcf48b26361f94e10a0eafc2c49c0bf0f440b2d5/common/events.cpp
Also if we decide use a global publisher, we need improve the event message, so receiver can identify which instance send the message.
And if every RedisChannel instance need have it's own event publisher, this should move to class member.
Because the thread safe issue I suggest we not use a global publisher, however it's depends on the requirement.
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.
According to offline sync, I suggest not necessary use global or class level event publisher, we can just use a publisher on stack to save resource, because we only need send failed event.
However even we using a publisher on stack, the thread safe issue still need fix, best solution is to add lock in events API.
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.
please dont use global objects