-
Notifications
You must be signed in to change notification settings - Fork 543
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
[orchagent]: Fix bug that Executor does not get correct priority saved in m_selectable #957
base: master
Are you sure you want to change the base?
Conversation
pull request in sonic-swss-common |
@@ -81,6 +81,7 @@ class Executor : public Selectable | |||
|
|||
// Decorating Selectable | |||
int getFd() override { return m_selectable->getFd(); } | |||
int getPri() const override { return m_selectable->getPri(); } |
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.
before we hade this method how everything worked?
What getPri it was used?
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.
1 . This bug only found in class Executor used for orch. It worked well because most orch is not sensitive to priority, namely the process order of TABLE .
pull request in sonic-swss-common sonic-net/sonic-swss-common#290
My next pull request will show how priority influence the aclorch . aclorch works well in such condition: ACL_TABLE is processed firstly , ACL_RULE is processed secondly.
Class Executor is special, it's derived class of selectable , but it contains a Selectable pointer m_selecrtable that makes sense in function Select::select(). Priority of Executor's base class is always 0. Thinking below condition, Pointer Selectable * s point to an Executor object, s->getPri() will return priority derived from Selectable rather than priority of m_selectable.
2、 getPri was used by Select::(std::set<Selectable *, Select::cmp> m_ready) .
when event happends, Select::poll_descriptors will insert Selectable pointer into m_ready, Select::cmp use priority to decide the process order of Selectable pointer. Selectable pointer with higher priority will be processed earlier。
int Select::poll_descriptors(Selectable **c, unsigned int timeout)
{
......
for (int i = 0; i < ret; ++i)
{
int fd = events[i].data.fd;
Selectable* sel = m_objects[fd];
sel->readData();
m_ready.insert(sel); //insert Selectable* sel to be processed
}
......
if (!m_ready.empty())
{
auto sel = *m_ready.begin(); // sel with highest priority
*c = sel;
m_ready.erase(sel);
......
}
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.
In this case I'd suggest to fix the design of Executor, which at the same time using inheritance and composition which is not correct. Should we disable inheritance and use compassion everywhere?
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.
You are right, the design of Executor looks strange, but I think it's designed for two reasons:
1、 Executor is a container of pointer Selectable and the pointer is initialized by derived class pointer of Selectable, such as SubscriberStateTable, SubscriberStateTable. In this way, Executor can process event of derived class pointer of Selectable , such as readData from subscribe table
2、 Executor need to work as a selectable, so that it can be handled by Select::select()。Executor need to be selected by Select::select so that Executor::execute() can be exec to process doTask of orch
This may be a elegant and simple design that meets the requirements mentioned above.
So I think we can do it in two steps:
Firstly, fix the bug of priority under current design
Secondly, discuss whether it is necessary to modify the design of class Executor. After all, class Executor is wildly used in orchagent, it's better to be cautious.
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.
@qiluo-msft please check
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.
retest this please,there will be no mirror since Selectable:getPri() has been modified to be virtual in sonic-swss-common
retest this please |
3 similar comments
retest this please |
retest this please |
retest this please |
@lguohan The vs test is always falling for this change.
|
1、The current design use Decorator Pattern, In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class. Executor corresponds Decorator, Selectable corresponds Component, SubscribeTable corresponds ConcreteComponent. 2、 Initial Executor with priority of SubscribeTable is not a good idea. In this way, there will be two priority that is equal, namely Executor.priority == SubscribeTable.priority. This is pretty strange. |
@jihaix Can you please fix the vs test? We can't merge the code which breaks the tests. |
Okay, I'll fix the vs test soon |
check #1022 please |
could you merge these two pull requests into one? |
These pull requests are the same. I don't see any differences. |
* [filter-fdb] Check VLAN Presence When Filter FDB FTOS fast conversion script generates bogus vlan that does not exist. This PR uses config_db in order to verify that provided vlans exist in the switch configuration. signed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com> * review comments making lgtm happy Added two more test cases * Update existing test case and adding new one * adding support for filter ou based on vlan ip network
1、What I did
changes in sonic-swss-common: make member function
Select::getPri()
to be virtualchanges in sonic-swss: override
getPri()
in class Executor to return priority of m_selectables2、Why I do it
Select:cmp
using priority got by functiongetPri()
to sort order of event. But class Select's member functiongetPri()
is not virtual,so that class Executor can't not override getPri() to return priority saved in m_selectable. Class Executor is just a container of pointer m_selectable with typeSelect *
. We should get priority saved in m_selectable rather than 0, which is default structed by Executor's base class Select. Thinking of below situation , pointerSelect * s
point to object of type Executor,s -> getPri()
will always return priority of 03、How I verified it
Debug & Test, show priority of Executor Object