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

Enhance port_update_event logic to be thread-safe #430

Merged
merged 9 commits into from
Feb 23, 2024

Conversation

longhuan-cisco
Copy link
Contributor

@longhuan-cisco longhuan-cisco commented Feb 7, 2024

Description

  1. Refactor today's subscribe_port_update_event/handle_port_update_event logic to be object oriented, which is also thread-safe.
  2. Add new argument to allow users to decide what tables and fields to subscribe
  3. Record table_name and db_name for each event to avoid ambiguity in certain cases. (e.g. for DEL events from different tables/DBs, user may have different handlings.)

Motivation and Context

Today's port_mapping has a class variable PORT_EVENT , which is not thread-safe: different threads could share this class level global variable PORT_EVENT, and overwriting each other's data.

It's not causing issue in today's code, because today only one thread (cmis_mgr) relying on port_mapping.handle_port_update_event (and PORT_EVENT).
But in the future, it will run into issues if multiple threads (e.g. cmis_mgr, sff_mgr, PM) rely on function port_mapping.handle_port_update_event (where PORT_EVENT is getting used)

This PR is a dependency of #383

How Has This Been Tested?

Verified cmis_mgr/sff_mgr(new thread) to be able to work normally to bring up/down optics without intervention with each other.

Additional Information (Optional)

@longhuan-cisco longhuan-cisco changed the title Enhance port_mapping to be thread-safe Enhance port_update_event logic to be thread-safe Feb 13, 2024
prgeor
prgeor previously approved these changes Feb 16, 2024
@xumia
Copy link
Collaborator

xumia commented Feb 22, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@prgeor prgeor merged commit 9141305 into sonic-net:master Feb 23, 2024
5 checks passed
noaOrMlnx pushed a commit to noaOrMlnx/sonic-platform-daemons that referenced this pull request Mar 14, 2024
* Enhance port_mapping to be multi-thread safe

* Increase cov for handle_port_update_event test in test_xcvrd.py

* Fix comment in test_xcvrd.py

* Migrate to PortChangeObserver class to handle port update events

* Rename port_mapping.py to port_event_helper.py

* Remove unused import statement in port_event_helper.py

* Resolve issue after update branch to latest master
vivekrnv pushed a commit to vivekrnv/sonic-platform-daemons that referenced this pull request Mar 22, 2024
* Enhance port_mapping to be multi-thread safe

* Increase cov for handle_port_update_event test in test_xcvrd.py

* Fix comment in test_xcvrd.py

* Migrate to PortChangeObserver class to handle port update events

* Rename port_mapping.py to port_event_helper.py

* Remove unused import statement in port_event_helper.py

* Resolve issue after update branch to latest master
yuazhe pushed a commit to yuazhe/sonic-platform-daemons that referenced this pull request Jul 2, 2024
* Enhance port_mapping to be multi-thread safe

* Increase cov for handle_port_update_event test in test_xcvrd.py

* Fix comment in test_xcvrd.py

* Migrate to PortChangeObserver class to handle port update events

* Rename port_mapping.py to port_event_helper.py

* Remove unused import statement in port_event_helper.py

* Resolve issue after update branch to latest master
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