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

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

commit dece081d33c8a6d4e1b56589ec5d4e16013d6643
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 f1ab034..06a89bc 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -12792,9 +12792,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(),
@@ -12811,6 +12810,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 94891af..ed83167 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -49,6 +49,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>
@@ -2140,6 +2141,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(
@@ -2160,6 +2167,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