-
Notifications
You must be signed in to change notification settings - Fork 732
[orchagent]: Add ZmqRouteServer for concurrent route updates #4564
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
Open
venkit-nexthop
wants to merge
12
commits into
sonic-net:master
Choose a base branch
from
venkit-nexthop:orchagent-zmq-route-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6dbebca
[orchagent]: Add ZmqRouteServer for concurrent route updates
venkit-nexthop 3c479bf
Merge upstream master; switch ZmqRouteConsumer to staging-map design
venkit-nexthop d4f0e5f
Merge branch 'master' into orchagent-zmq-route-server
venkit-nexthop 1dd27dd
Merge branch 'sonic-net:master' into orchagent-zmq-route-server
venkit-nexthop 69fdc76
[orchagent]: Address ZmqRouteConsumer review comments
venkit-nexthop 69cadcb
[orchagent]: Sync p4orch RouteOrch test double with ZmqRouteServer ctor
venkit-nexthop 068a580
[orchagent]: Update ZmqRouteConsumerExecuteEmpty for the route state …
venkit-nexthop a471180
[orchagent]: Narrow the ingress lock and tidy the route consumer
venkit-nexthop e46feeb
Merge branch 'sonic-net:master' into orchagent-zmq-route-server
venkit-nexthop d6aedb4
Merge branch 'sonic-net:master' into orchagent-zmq-route-server
venkit-nexthop a1e4a56
[orchagent]: Cover ingress staging semantics in the route consumer tests
venkit-nexthop 81d467c
[orchagent]: Qualify ZmqRoute* types with swss:: and log vrf in creat…
venkit-nexthop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
venkit-nexthop marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| #include "zmqrouteorch.h" | ||
|
|
||
| using namespace swss; | ||
| using namespace std; | ||
|
|
||
| extern int gBatchSize; | ||
| extern size_t gMaxBulkSize; | ||
|
|
||
| ZmqRouteConsumer::ZmqRouteConsumer(swss::ZmqRouteConsumerStateTable *select, Orch *orch, const std::string &name) | ||
| : ConsumerBase(select, orch, name) | ||
| { | ||
| // mqPollThread delivers bursts of tuples through this callback. Stage them | ||
| // in the plain m_ingress map under m_ingressMutex rather than merging into | ||
| // m_toSync here; the merge into m_toSync happens on the orch main thread in | ||
| // execute(). The eventfd is fired once the staged batch reaches | ||
| // gMaxBulkSize (so the main loop has a real batch to drain); otherwise | ||
| // mqPollThread fires it once per burst after the burst quiesces. | ||
| select->setIngressCallback( | ||
| [this, select](const std::vector<std::shared_ptr<KeyOpFieldsValuesTuple>> &kcos) { | ||
| std::lock_guard<std::mutex> lk(m_ingressMutex); | ||
| for (const auto &kco : kcos) | ||
| { | ||
| // Plain last-writer-wins staging by key. The SyncMap merge into | ||
| // m_toSync is applied later by execute()'s addToSync(). | ||
| m_ingress[kfvKey(*kco)] = *kco; | ||
| } | ||
| if (m_ingress.size() >= gMaxBulkSize) | ||
| { | ||
| select->notifyPending(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| void ZmqRouteConsumer::execute() | ||
| { | ||
| SWSS_LOG_ENTER(); | ||
|
|
||
| std::deque<KeyOpFieldsValuesTuple> entries; | ||
| { | ||
| // Move the staged tuples out of m_ingress under the lock, mirroring | ||
| // ZmqConsumer::execute()'s pops() + addToSync(entries). The lock is | ||
| // dropped before addToSync() below: m_toSync is owned by this (main) | ||
| // thread alone, so the merge needs no lock, and releasing early keeps | ||
| // mqPollThread free to stage the next burst while the merge runs. | ||
| std::lock_guard<std::mutex> lk(m_ingressMutex); | ||
| for (auto &kv : m_ingress) | ||
| { | ||
| entries.push_back(std::move(kv.second)); | ||
| } | ||
| m_ingress.clear(); | ||
| } | ||
| addToSync(entries); | ||
|
|
||
| // m_toSync is mutated only by this (main) thread, so drain() — which reads | ||
| // m_toSync and hands it to doTask — does not need to hold m_ingressMutex. | ||
| // Releasing the lock before drain() also keeps mqPollThread free to stage | ||
| // further tuples into m_ingress while doTask is running. | ||
| drain(); | ||
| } | ||
|
|
||
| void ZmqRouteConsumer::drain() | ||
| { | ||
| // TODO: doTask() currently walks the whole of m_toSync in one go. Per the | ||
| // route programming HLD -- doc/orchagent/orchagent_route_redesign.md | ||
| // sections 7.4 and 7.5 (sonic-net/SONiC#2328) -- this becomes a yieldable | ||
| // walk bounded by a time quantum, so the main loop returns to execute() | ||
| // and keeps draining m_ingress (and hence the ZMQ socket) instead of | ||
| // stalling ingress behind one large batch. | ||
| if (!m_toSync.empty()) | ||
| (static_cast<ZmqRouteOrch*>(m_orch))->doTask(*this); | ||
| } | ||
|
|
||
|
|
||
| ZmqRouteOrch::ZmqRouteOrch(DBConnector *db, const vector<string> &tableNames, swss::ZmqRouteServer *zmqServer) | ||
| : Orch() | ||
| { | ||
| for (const auto& it : tableNames) | ||
| { | ||
| addConsumer(db, it, default_orch_pri, zmqServer); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| ZmqRouteOrch::ZmqRouteOrch(DBConnector *db, const vector<table_name_with_pri_t> &tableNames_with_pri, swss::ZmqRouteServer *zmqServer) | ||
| { | ||
| for (const auto& it : tableNames_with_pri) | ||
| { | ||
| addConsumer(db, it.first, it.second, zmqServer); | ||
| } | ||
| } | ||
|
|
||
| void ZmqRouteOrch::addConsumer(DBConnector *db, string tableName, int pri, swss::ZmqRouteServer *zmqServer) | ||
| { | ||
| if (db->getDbId() == APPL_DB || db->getDbId() == DPU_APPL_DB) | ||
| { | ||
| if (zmqServer != nullptr) | ||
| { | ||
| SWSS_LOG_DEBUG("ZmqRouteConsumer initialize for: %s", tableName.c_str()); | ||
| addExecutor( | ||
| new ZmqRouteConsumer( | ||
| new swss::ZmqRouteConsumerStateTable( | ||
| db, tableName, *zmqServer, pri, /* dbPersistence= */false), | ||
| this, tableName)); | ||
| } | ||
| else | ||
| { | ||
| SWSS_LOG_DEBUG("Consumer initialize for: %s", tableName.c_str()); | ||
| addExecutor(new Consumer(new ConsumerStateTable(db, tableName, gBatchSize, pri), this, tableName)); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| SWSS_LOG_WARN("ZmqRouteOrch does not support create consumer for db: %d, table: %s", db->getDbId(), tableName.c_str()); | ||
| } | ||
| } | ||
|
|
||
| void ZmqRouteOrch::doTask(Consumer &consumer) | ||
| { | ||
| // When ZMQ disabled, forward data from Consumer | ||
| doTask(static_cast<ConsumerBase &>(consumer)); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.