This is an automated email from the ASF dual-hosted git repository.

chhsiao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 586dba870858129e5f6eaac58b7e1eb118196e26
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 f1ca637..ace05b2 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -13177,9 +13177,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(),
@@ -13196,6 +13195,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 ffa7423..5c229c5 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -50,6 +50,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>
@@ -2265,6 +2266,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(
@@ -2285,6 +2292,10 @@ private:
       StreamingHttpConnection<v1::master::Event> http;
       ResponseHeartbeater<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.

Reply via email to