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

Publish events for select operation and getresponse failure #1142

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

zbud-msft
Copy link

@zbud-msft zbud-msft commented Oct 31, 2022

Why I did it

Add event_publish code to publish events when select operation fails or getresponse fails

@zbud-msft zbud-msft marked this pull request as draft October 31, 2022 05:53
@zbud-msft zbud-msft marked this pull request as ready for review November 1, 2022 00:28
@renukamanavalan
Copy link
Contributor

Request @kcudnik for review

@qiluo-msft qiluo-msft requested a review from liuh-80 November 6, 2022 04:54

using namespace sairedis;

event_handle_t g_events_handle;
Copy link
Contributor

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.

Copy link
Contributor

@liuh-80 liuh-80 Nov 9, 2022

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.

Copy link
Collaborator

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

@@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The 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:

https://github.com/sonic-net/sonic-swss-common/blob/bcf48b26361f94e10a0eafc2c49c0bf0f440b2d5/common/events.cpp#L28

so suggest improve the events.cpp code first before this PR merge.
Or you can add lock here.

{ "operation_result", swss::Select::resultToString(result) },
{ "command", command }};

event_publish(g_events_handle, "select-operation-failure", &m_event_params);
Copy link
Contributor

Choose a reason for hiding this comment

The 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:
https://github.com/sonic-net/sonic-swss-common/blob/bcf48b26361f94e10a0eafc2c49c0bf0f440b2d5/common/events.cpp#L150

@zbud-msft zbud-msft marked this pull request as draft November 9, 2022 18:13
Copy link
Collaborator

@kcudnik kcudnik left a comment

Choose a reason for hiding this comment

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

address global objects


using namespace sairedis;

event_handle_t g_events_handle;
Copy link
Collaborator

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

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.

4 participants