-
Notifications
You must be signed in to change notification settings - Fork 275
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
[PINS] Add ConsumerNotifier for PINS response path #547
Conversation
f863211
to
a90eee0
Compare
Please change the PR title to more descriptive. People in the swss-common context do not know |
common/json.hpp
Outdated
@@ -5394,7 +5394,7 @@ class basic_json | |||
{ | |||
assert(lhs.m_value.array != nullptr); | |||
assert(rhs.m_value.array != nullptr); | |||
return *lhs.m_value.array < *rhs.m_value.array; | |||
return (*lhs.m_value.array) < *rhs.m_value.array; |
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.
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.
This is a fix from upstream: nlohmann/json#590
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.
Addressed in #545
Please give a link to HLD for this change. |
this seems to me to be too big change like for a single PR |
BUILD
Outdated
@@ -0,0 +1,31 @@ | |||
package(default_visibility = ["//visibility:public"]) |
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.
Integrate Bazel build into PR checker (update the build pipeline) to help catch errors for breaking this in the future
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.
Move to separate PR
@qiluo-msft Also, the interface won't change the existing swss-common unit test. They still need to test with the Redis instance. The interface mocking is only helpful for testing codes that use the swss-common libraries. (Such as P4RT, so that P4RT does not need a Redis instance when doing unit test.) |
In modern C++, there is no performance penalty for virtual functions when the compiler can guarantee the runtime type. In our case, the implementation class can be inferred by the compiler, resulting in no additional instructions added by The compiler option involved here is: The function may be inlined or called directly without a vtable lookup. Here's a relevant blog post on the topic of virtual functions: Anyway, I ran an experiment with and without virtual functions, and my implementation class (DBConnector) was NOT final. The result is effectively identical assembly code. With
Without
|
@@ -0,0 +1,32 @@ | |||
#pragma once |
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.
Qi concerned about performance penalty for virtual functions. Can this be done without this interface and virtual functions?
If this is needed for new feature, then it's okay. But we shouldn't incur a performance penalty just for testing.
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.
Update: See comment on main PR conversation regarding virtual functions: #547 (comment)
common/json.hpp
Outdated
@@ -5394,7 +5394,7 @@ class basic_json | |||
{ | |||
assert(lhs.m_value.array != nullptr); | |||
assert(rhs.m_value.array != nullptr); | |||
return *lhs.m_value.array < *rhs.m_value.array; | |||
return (*lhs.m_value.array) < *rhs.m_value.array; |
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.
This is a fix from upstream: nlohmann/json#590
* Add ConsumerNotifier for response path * Introduce interfaces for DBConnector, NotificationConsumer, ConsumerNotifier, NotificationProducer, ProducerStateTable to make it easier to test these classes Submission containing materials of a third party: Copyright Google LLC; Licensed under Apache 2.0 Co-authored-by: Akarsh Gupta <akarshgupta@google.com> Co-authored-by: Ashish Singh <ashishksingh@google.com> Co-authored-by: Jay Hu <jiarenhu@google.com> Co-authored-by: Manali Kumar <manalikumar@google.com> Co-authored-by: Richard Yu <richardyu@google.com> Co-authored-by: Robert J. Halstead <rhalstea@google.com> Co-authored-by: Runming Wu <runmingwu@google.com> Co-authored-by: Srikishen Pondicherry Shanmugam <kishanps@google.com> Co-authored-by: Vivek Ramamoorthy <vivekmoorthy@google.com> Co-authored-by: Yilan Ji <yilanji@google.com> Signed-off-by: Don Newton don@opennetworking.org
a90eee0
to
7bca368
Compare
/azp run |
Commenter does not have sufficient privileges for PR 547 in repo Azure/sonic-swss-common |
@@ -358,4 +358,9 @@ void ProducerStateTable::apply_temp_view() | |||
m_tempViewActive = false; | |||
} | |||
|
|||
std::string ProducerStateTable::get_table_name() const |
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.
This function does not add value, can you remove?
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.
We use this in the P4RT server application.
@rhalstea what do you think?
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.
It's useful at various points in P4RT App to know the table name. Particularly around logging. The function was added here to make it available as part of the interface.
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.
It's already defined in TableBase::getTableName(), and TableBase could be treated as an interface.
@@ -750,6 +751,19 @@ int64_t DBConnector::decr(const string &key) | |||
return r.getContext()->integer; | |||
} | |||
|
|||
#ifndef SWIG | |||
std::unordered_map<std::string, std::string> DBConnector::hgetall( |
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.
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.
@rhalstea what do you think?
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.
The templates didn't work with the virtual interfaces.
Where this is needed in the P4RT App could be updated to the Table class. We can remove this once that happens, but that change may be difficult with the MVP timelines. However, internally we do want it planned for the next push.
return false; | ||
} | ||
} | ||
notification_consumer_->pop(op, data, values); |
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.
This logic is applicable to any Selectable or Select, which contains multiple Selectable. Could you move it to their class?
{ | ||
|
||
// Wrapper class to use swss::NotificationConsumer. | ||
class ConsumerNotifierInterface |
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.
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.
We can, but the other issue these interface classes address is the base class constructors requiring a redis db to be active. If we remove this do you have any objections to having a protected constructor that doesn't initialize a redis connection?
On the proposal of not adding In reply to: 963804275 |
@@ -358,4 +358,9 @@ void ProducerStateTable::apply_temp_view() | |||
m_tempViewActive = false; | |||
} | |||
|
|||
std::string ProducerStateTable::get_table_name() const | |||
{ | |||
return getTableName(); |
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.
@@ -199,11 +200,14 @@ class DBConnector : public RedisContext | |||
ReturnType hgetall(const std::string &key); | |||
|
|||
#ifndef SWIG | |||
std::unordered_map<std::string, std::string> hgetall( |
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.
Qi's suggestion: make this a standalone function in sonic-pins; first parameter is DBConnector; implementation calls the template version.
|
||
bool WaitForNotificationAndPop(std::string &op, std::string &data, std::vector<FieldValueTuple> &values, | ||
int64_t timeout_ms = 60000LL) override; | ||
|
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.
Robert's proposal
protected:
ConsumerNotifier(); // used for testing
Alternative:
- Provide a fake/mock DBConnector as a subclass and use that; need to create a testing only constructor there
/azpw run |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
I've updated sonic-pins to include the fakes/mocks so this pull request shouldn't be needed anymore. |
Hi Robert can you put a comment on the PR and I can close
…On Wed, Nov 17, 2021 at 12:54 PM Robert J. Halstead < ***@***.***> wrote:
@bocon13 <https://github.com/bocon13> @qiluo-msft
<https://github.com/qiluo-msft>
I've updated sonic-pins to include the fakes/mocks so this pull request
shouldn't be needed anymore.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#547 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJ4SJIVC3JODET2RWAURA3UMPT3XANCNFSM5G3O2YUQ>
.
|
Closing PER @rhalstea (Google) |
No description provided.