This is an automated email from the ASF dual-hosted git repository. chhsiao pushed a commit to branch 1.7.x in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 17dea045f24c391ce7645a001338ffbc44ec55e6 Author: Chun-Hung Hsiao <[email protected]> AuthorDate: Wed May 22 21:08:09 2019 -0700 Sequentialized all events to master's `/api/v1` subscribers. The master needs to create object approvers before sending an event to its `/api/v1` subscribers. The creation calls `process::collect`, which does not have any ordering guarantee. As a result, events might be reordered, which could be unexpected by subscribers. This patch imposes an order between events by sequentializing the creation of object approvers. The actual creations can still go in parallel, but the returned futures will be completed in the creation order. Review: https://reviews.apache.org/r/70702 --- src/master/master.cpp | 15 +++++++++++++-- src/master/master.hpp | 11 +++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/master/master.cpp b/src/master/master.cpp index 479d56c..0564025 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -12065,9 +12065,8 @@ void Master::Subscribers::send( Shared<Task> sharedTask(task.isSome() ? new Task(task.get()) : nullptr); foreachvalue (const Owned<Subscriber>& subscriber, subscribed) { - ObjectApprovers::create( + subscriber->getApprovers( master->authorizer, - subscriber->principal, {VIEW_ROLE, VIEW_FRAMEWORK, VIEW_TASK, VIEW_EXECUTOR}) .then(defer( master->self(), @@ -12084,6 +12083,18 @@ void Master::Subscribers::send( } +Future<Owned<ObjectApprovers>> Master::Subscribers::Subscriber::getApprovers( + const Option<Authorizer*>& authorizer, + std::initializer_list<authorization::Action> actions) +{ + Future<Owned<ObjectApprovers>> approvers = + ObjectApprovers::create(authorizer, principal, actions); + + return approversSequence.add<Owned<ObjectApprovers>>( + [approvers] { return approvers; }); +} + + void Master::Subscribers::Subscriber::send( const Shared<mesos::master::Event>& event, const Owned<ObjectApprovers>& approvers, diff --git a/src/master/master.hpp b/src/master/master.hpp index 2bfe255..6830e3b 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -58,6 +58,7 @@ #include <process/owned.hpp> #include <process/process.hpp> #include <process/protobuf.hpp> +#include <process/sequence.hpp> #include <process/timer.hpp> #include <process/metrics/counter.hpp> @@ -2134,6 +2135,12 @@ private: Subscriber(const Subscriber&) = delete; Subscriber& operator=(const Subscriber&) = delete; + // Creates object approvers. The futures returned by this method will be + // completed in the calling order. + process::Future<process::Owned<ObjectApprovers>> getApprovers( + const Option<Authorizer*>& authorizer, + std::initializer_list<authorization::Action> actions); + // TODO(greggomann): Refactor this function into multiple event-specific // overloads. See MESOS-8475. void send( @@ -2158,6 +2165,10 @@ private: process::Owned<Heartbeater<mesos::master::Event, v1::master::Event>> heartbeater; const Option<process::http::authentication::Principal> principal; + + // We maintain a sequence to coordinate the creation of object approvers + // in order to sequentialize all events to the subscriber. + process::Sequence approversSequence; }; // Sends the event to all subscribers connected to the 'api/vX' endpoint.
