Skip to content

core: queue API calls while underlying event dispatcher is not ready#428

Merged
junr03 merged 7 commits intomasterfrom
drainqueue
Sep 17, 2019
Merged

core: queue API calls while underlying event dispatcher is not ready#428
junr03 merged 7 commits intomasterfrom
drainqueue

Conversation

@junr03
Copy link
Copy Markdown
Member

@junr03 junr03 commented Sep 11, 2019

Description: this PR adds a drainable queue to the http dispatcher that allows it to queue API calls while the underlying event dispatcher is not ready. It hooks into envoy's lifecycle notifier to flush the queue once envoy fires the post init lifecycle event.
Risk Level: med - changes startup behavior of the engine.
Testing: with example app and lyft alpha app. Will add unit tests in subsequent PR (#449)

Fixes #285

Co-authored-by: Mike Schore mike.schore@gmail.com
Signed-off-by: Jose Nino jnino@lyft.com

Jose Nino added 2 commits September 10, 2019 17:27
fmt
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Sep 11, 2019

This PR requires https://github.com/envoyproxy/envoy/pulls to land before it.


void Dispatcher::post(Event::PostCb callback) {
// If the event_dispatcher is present, dispatch the functor directly to it.
auto event_dispatcher = event_dispatcher_.load();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reading the code we've written through again, I think we could benefit down the road from encapsulating this logic in an EventQueue class. (I think we could also simplify the synchronized state handling as well by doing so.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

EventQueue/CallbackQueue/InitQueue

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Generally LGTM at a high level, though I would recommend simplifying the concurrency logic for now.

Signed-off-by: Mike Schore <mike.schore@gmail.com>
@goaway
Copy link
Copy Markdown
Contributor

goaway commented Sep 16, 2019

So I started to factor out the init_queue_ logic, but it didn't really feel a whole lot simpler. I've decided to simply go with @mattklein123's suggestion for now. I have a slight concern that the increased dual-locking could lead to deadlock scenarios, but I don't think it's particularly likely call pattern.

Ultimately, I'd still much rather work towards a solution where we get an earlier handle on the event_dispatcher_ which will be safer and simpler.

Signed-off-by: Mike Schore <mike.schore@gmail.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Approach LGTM, thanks.


void Dispatcher::ready(Event::Dispatcher& event_dispatcher,
Upstream::ClusterManager& cluster_manager) {
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: there is no point in having these extra braces as you hold the lock for the length of the function. Same below.

Upstream::ClusterManager& cluster_manager)
: event_dispatcher_(event_dispatcher), cluster_manager_(cluster_manager) {}
Dispatcher::Dispatcher() {
event_dispatcher_.store(nullptr);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you have a compile issue here.

Signed-off-by: Mike Schore <mike.schore@gmail.com>
mattklein123
mattklein123 previously approved these changes Sep 17, 2019
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Nice, LGTM

class Dispatcher : public Logger::Loggable<Logger::Id::http> {
public:
Dispatcher(Event::Dispatcher& event_dispatcher, Upstream::ClusterManager& cluster_manager);
Dispatcher() {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: del

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Copy Markdown
Member Author

junr03 commented Sep 17, 2019

tested locally against the unit test suite, and with all 4 demo apps.

@junr03 junr03 merged commit 63459a2 into master Sep 17, 2019
@junr03 junr03 deleted the drainqueue branch September 17, 2019 21:18
rebello95 added a commit that referenced this pull request Sep 18, 2019
As of #428, we now queue API calls while Envoy starts up, so the 1s delay is no longer required. Removing the outdated docstrings.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
rebello95 added a commit that referenced this pull request Sep 19, 2019
As of #428, we now queue API calls while Envoy starts up, so the 1s delay is no longer required. Removing the outdated docstrings.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
jpsim pushed a commit to envoyproxy/envoy that referenced this pull request Nov 28, 2022
As of envoyproxy/envoy-mobile#428, we now queue API calls while Envoy starts up, so the 1s delay is no longer required. Removing the outdated docstrings.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit to envoyproxy/envoy that referenced this pull request Nov 29, 2022
As of envoyproxy/envoy-mobile#428, we now queue API calls while Envoy starts up, so the 1s delay is no longer required. Removing the outdated docstrings.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: JP Simard <jp@jpsim.com>
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.

core: create post-init callback

3 participants