mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [1/2] mesos git commit: Ensured JAVA HTTP adapter propagates a subscription error.
Date Fri, 01 Sep 2017 09:16:22 GMT
Repository: mesos
Updated Branches:
  refs/heads/1.3.x aed3eb955 -> a613c6f7f


Ensured JAVA HTTP adapter propagates a subscription error.

Prior to this patch, if an error occurred during subscription /
registration to the master, it was not propagated back to the
scheduler if the HTTP adapter was used. This happened because
the HTTP adapter does not call `scheduler.connected` until after
successful registration and hence the scheduler does not try to
send the `SUBSCRIBE` call, without which the adapter does not
send any events to the scheduler.

A fix is to call `scheduler.connected` if an error occurred
before the scheduler had subscribed.

Review: https://reviews.apache.org/r/61579


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2caff403
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2caff403
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2caff403

Branch: refs/heads/1.3.x
Commit: 2caff4036264301de767203f8ac8fd7ebf4017ee
Parents: aed3eb9
Author: Alexander Rukletsov <alexr@apache.org>
Authored: Thu Aug 10 22:34:38 2017 +0200
Committer: Alexander Rukletsov <alexr@apache.org>
Committed: Fri Sep 1 10:59:19 2017 +0200

----------------------------------------------------------------------
 .../org_apache_mesos_v1_scheduler_V0Mesos.cpp   | 84 ++++++++++++--------
 1 file changed, 53 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2caff403/src/java/jni/org_apache_mesos_v1_scheduler_V0Mesos.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_v1_scheduler_V0Mesos.cpp b/src/java/jni/org_apache_mesos_v1_scheduler_V0Mesos.cpp
index 1f58fbf..e487f1e 100644
--- a/src/java/jni/org_apache_mesos_v1_scheduler_V0Mesos.cpp
+++ b/src/java/jni/org_apache_mesos_v1_scheduler_V0Mesos.cpp
@@ -189,6 +189,8 @@ protected:
 
   void __received(const Event& event);
 
+  void connect();
+
   void heartbeat();
 
   void disconnect();
@@ -355,35 +357,7 @@ void V0ToV1AdapterProcess::registered(
     const FrameworkID& _frameworkId,
     const MasterInfo& masterInfo)
 {
-  jvm->AttachCurrentThread(JNIENV_CAST(&env), NULL);
-
-  jclass clazz = env->GetObjectClass(jmesos);
-
-  jfieldID scheduler =
-    env->GetFieldID(clazz, "scheduler",
-                    "Lorg/apache/mesos/v1/scheduler/Scheduler;");
-
-  jobject jscheduler = env->GetObjectField(jmesos, scheduler);
-
-  clazz = env->GetObjectClass(jscheduler);
-
-  // scheduler.connected(mesos);
-  jmethodID connected =
-    env->GetMethodID(clazz, "connected",
-                     "(Lorg/apache/mesos/v1/scheduler/Mesos;)V");
-
-  env->ExceptionClear();
-
-  env->CallVoidMethod(jscheduler, connected, jmesos);
-
-  if (env->ExceptionCheck()) {
-    env->ExceptionDescribe();
-    env->ExceptionClear();
-    jvm->DetachCurrentThread();
-    ABORT("Exception thrown during `connected` call");
-  }
-
-  jvm->DetachCurrentThread();
+  connect();
 
   // We need this copy to populate the fields in `Event::Subscribed` upon
   // receiving a `reregistered()` callback later.
@@ -554,6 +528,18 @@ void V0ToV1AdapterProcess::error(const string& message)
 
   event.mutable_error()->set_message(message);
 
+  // There might be an error during the communication with the master or
+  // implicit registration happening on driver initialization. Since
+  // `Scheduler.connect` is called upon a successful registration only, the
+  // scheduler will never try to subscribe and hence will never receive the
+  // error. This workaround satisfies the invariant of the v1 interface that
+  // a scheduler can receive an event only after successfully connecting with
+  // the master.
+  if (!subscribeCall) {
+    LOG(INFO) << "Implicitly connecting the scheduler to send an error";
+    connect();
+  }
+
   received(event);
 }
 
@@ -579,7 +565,8 @@ void V0ToV1AdapterProcess::send(SchedulerDriver* driver, const Call&
_call)
 
       // The driver subscribes implicitly with the master upon initialization.
       // For compatibility with the v1 interface, send the already enqueued
-      // subscribed event upon receiving the subscribe request.
+      // subscribed event (or subscription error) upon receiving the subscribe
+      // request.
       _received();
       break;
     }
@@ -699,7 +686,8 @@ void V0ToV1AdapterProcess::send(SchedulerDriver* driver, const Call&
_call)
 void V0ToV1AdapterProcess::received(const Event& event)
 {
   // For compatibility with the v1 interface, we only start sending events
-  // once the scheduler has sent the subscribe call.
+  // once the scheduler has sent the subscribe call. An exception to this
+  // is an error event, which can be sent before the subscribe call.
   if (!subscribeCall) {
     pending.push(event);
     return;
@@ -759,6 +747,40 @@ void V0ToV1AdapterProcess::__received(const Event& event)
 }
 
 
+void V0ToV1AdapterProcess::connect()
+{
+  jvm->AttachCurrentThread(JNIENV_CAST(&env), NULL);
+
+  jclass clazz = env->GetObjectClass(jmesos);
+
+  jfieldID scheduler =
+    env->GetFieldID(clazz, "scheduler",
+                    "Lorg/apache/mesos/v1/scheduler/Scheduler;");
+
+  jobject jscheduler = env->GetObjectField(jmesos, scheduler);
+
+  clazz = env->GetObjectClass(jscheduler);
+
+  // scheduler.connected(mesos);
+  jmethodID connected =
+    env->GetMethodID(clazz, "connected",
+                     "(Lorg/apache/mesos/v1/scheduler/Mesos;)V");
+
+  env->ExceptionClear();
+
+  env->CallVoidMethod(jscheduler, connected, jmesos);
+
+  if (env->ExceptionCheck()) {
+    env->ExceptionDescribe();
+    env->ExceptionClear();
+    jvm->DetachCurrentThread();
+    ABORT("Exception thrown during `connected` call");
+  }
+
+  jvm->DetachCurrentThread();
+}
+
+
 void V0ToV1AdapterProcess::heartbeat()
 {
   // It is possible that we were unable to cancel this timer upon a


Mime
View raw message