You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2015/07/17 00:33:42 UTC
[1/2] mesos git commit: Fixed a bug in master to properly handle
resubscription.
Repository: mesos
Updated Branches:
refs/heads/master f9a0d23a7 -> bfe6c07b7
Fixed a bug in master to properly handle resubscription.
Review: https://reviews.apache.org/r/36518
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/bfe6c07b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/bfe6c07b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/bfe6c07b
Branch: refs/heads/master
Commit: bfe6c07b79550bb3d1f2ab6f5344d740e6eb6f60
Parents: fc85cc5
Author: Vinod Kone <vi...@gmail.com>
Authored: Wed Jul 15 11:38:20 2015 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Thu Jul 16 15:33:11 2015 -0700
----------------------------------------------------------------------
src/master/master.cpp | 14 +++++++-
src/tests/scheduler_tests.cpp | 67 ++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/bfe6c07b/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index b877676..082758e 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -1742,6 +1742,18 @@ void Master::registerFramework(
{
++metrics->messages_register_framework;
+ // A framework with a valid id should re-register instead of
+ // register with the master.
+ // TODO(vinod): Add "!=" operator for FrameworkID.
+ if (frameworkInfo.has_id() && !(frameworkInfo.id() == "")) {
+ LOG(ERROR) << "Framework '" << frameworkInfo.name() << "' at " << from
+ << " registering with an id!";
+ FrameworkErrorMessage message;
+ message.set_message("Framework registering with a framework id");
+ send(from, message);
+ return;
+ }
+
if (authenticating.contains(from)) {
// TODO(vinod): Consider dropping this request and fix the tests
// to deal with the drop. Currently there is a race between master
@@ -2097,7 +2109,7 @@ void Master::subscribe(
// TODO(vinod): Instead of calling '(re-)registerFramework()' from
// here refactor those methods to call 'subscribe()'.
- if (frameworkInfo.has_id() || frameworkInfo.id() == "") {
+ if (!frameworkInfo.has_id() || frameworkInfo.id() == "") {
registerFramework(from, frameworkInfo);
} else {
reregisterFramework(from, frameworkInfo, subscribe.force());
http://git-wip-us.apache.org/repos/asf/mesos/blob/bfe6c07b/src/tests/scheduler_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/scheduler_tests.cpp b/src/tests/scheduler_tests.cpp
index 6e83e64..2ce280a 100644
--- a/src/tests/scheduler_tests.cpp
+++ b/src/tests/scheduler_tests.cpp
@@ -107,6 +107,73 @@ ACTION_P(Enqueue, queue)
}
+// This test verifies that when a scheduler resubscribes it receives
+// SUBSCRIBED event with the previously assigned framework id.
+TEST_F(SchedulerTest, Subscribe)
+{
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Callbacks callbacks;
+
+ Future<Nothing> connected;
+ EXPECT_CALL(callbacks, connected())
+ .WillOnce(FutureSatisfy(&connected));
+
+ scheduler::Mesos mesos(
+ master.get(),
+ DEFAULT_CREDENTIAL,
+ lambda::bind(&Callbacks::connected, lambda::ref(callbacks)),
+ lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)),
+ lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1));
+
+ AWAIT_READY(connected);
+
+ Queue<Event> events;
+
+ EXPECT_CALL(callbacks, received(_))
+ .WillRepeatedly(Enqueue(&events));
+
+ {
+ Call call;
+ call.set_type(Call::SUBSCRIBE);
+
+ Call::Subscribe* subscribe = call.mutable_subscribe();
+ subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
+ subscribe->set_force(true);
+
+ mesos.send(call);
+ }
+
+ Future<Event> event = events.get();
+ AWAIT_READY(event);
+ EXPECT_EQ(Event::SUBSCRIBED, event.get().type());
+
+ FrameworkID id(event.get().subscribed().framework_id());
+
+ // Resubscribe with the same framework id.
+ {
+ Call call;
+ call.mutable_framework_id()->CopyFrom(id);
+ call.set_type(Call::SUBSCRIBE);
+
+ Call::Subscribe* subscribe = call.mutable_subscribe();
+ subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
+ subscribe->mutable_framework_info()->mutable_id()->CopyFrom(id);
+ subscribe->set_force(true);
+
+ mesos.send(call);
+ }
+
+ event = events.get();
+ AWAIT_READY(event);
+ EXPECT_EQ(Event::SUBSCRIBED, event.get().type());
+ EXPECT_EQ(id, event.get().subscribed().framework_id());
+
+ Shutdown();
+}
+
+
TEST_F(SchedulerTest, TaskRunning)
{
Try<PID<Master>> master = StartMaster();
[2/2] mesos git commit: Made Subscribe.force optional in the Call
protobuf.
Posted by vi...@apache.org.
Made Subscribe.force optional in the Call protobuf.
Review: https://reviews.apache.org/r/36560
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fc85cc51
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fc85cc51
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fc85cc51
Branch: refs/heads/master
Commit: fc85cc512b7767fc2e3921b15cf6602c0c68593e
Parents: f9a0d23
Author: Vinod Kone <vi...@gmail.com>
Authored: Thu Jul 16 14:21:48 2015 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Thu Jul 16 15:33:11 2015 -0700
----------------------------------------------------------------------
include/mesos/scheduler/scheduler.proto | 26 ++++++++++++++------------
src/examples/event_call_framework.cpp | 5 ++++-
src/tests/scheduler_tests.cpp | 8 --------
3 files changed, 18 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/fc85cc51/include/mesos/scheduler/scheduler.proto
----------------------------------------------------------------------
diff --git a/include/mesos/scheduler/scheduler.proto b/include/mesos/scheduler/scheduler.proto
index a027da2..e2ca8e5 100644
--- a/include/mesos/scheduler/scheduler.proto
+++ b/include/mesos/scheduler/scheduler.proto
@@ -172,18 +172,20 @@ message Call {
// 'framework_info.id'.
required FrameworkInfo framework_info = 1;
- // 'force' tells the master what to do in case an instance of the
- // scheduler attempts to subscribe when another instance of it
- // is already connected (e.g., split brain due to network
- // partition). If 'force' is true, the newly subscribing scheduler
- // instance is allowed and the old connected scheduler instance
- // is disconnected. If false, the newly subscribing scheduler
- // instance is disallowed subscription in favor of the already
- // connected scheduler instance. It is recommended to set this to
- // true only when a scheduler instance is (just) elected but not
- // when it is retrying subscription (disconnection or master
- // failover; see sched/sched.cpp for an example).
- required bool force = 2;
+ // 'force' field is only relevant when 'framework_info.id' is set.
+ // It tells the master what to do in case an instance of the
+ // scheduler attempts to subscribe when another instance of it is
+ // already connected (e.g., split brain due to network partition).
+ // If 'force' is true, this scheduler instance is allowed and the
+ // old connected scheduler instance is disconnected. If false,
+ // this scheduler instance is disallowed subscription in favor of
+ // the already connected scheduler instance.
+ //
+ // It is recommended to set this to true only when a newly elected
+ // scheduler instance is attempting to subscribe but not when a
+ // scheduler is retrying subscription (e.g., disconnection or
+ // master failover; see sched/sched.cpp for an example).
+ optional bool force = 2;
}
// Accepts an offer, performing the specified operations
http://git-wip-us.apache.org/repos/asf/mesos/blob/fc85cc51/src/examples/event_call_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/event_call_framework.cpp b/src/examples/event_call_framework.cpp
index 17fdcac..8054068 100644
--- a/src/examples/event_call_framework.cpp
+++ b/src/examples/event_call_framework.cpp
@@ -306,7 +306,10 @@ private:
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(framework);
- subscribe->set_force(true);
+
+ if (framework.has_id()) {
+ subscribe->set_force(true);
+ }
mesos.send(call);
http://git-wip-us.apache.org/repos/asf/mesos/blob/fc85cc51/src/tests/scheduler_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/scheduler_tests.cpp b/src/tests/scheduler_tests.cpp
index 946fa82..6e83e64 100644
--- a/src/tests/scheduler_tests.cpp
+++ b/src/tests/scheduler_tests.cpp
@@ -145,7 +145,6 @@ TEST_F(SchedulerTest, TaskRunning)
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
- subscribe->set_force(true);
mesos.send(call);
}
@@ -252,7 +251,6 @@ TEST_F(SchedulerTest, ReconcileTask)
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
- subscribe->set_force(true);
mesos.send(call);
}
@@ -361,7 +359,6 @@ TEST_F(SchedulerTest, KillTask)
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
- subscribe->set_force(true);
mesos.send(call);
}
@@ -485,7 +482,6 @@ TEST_F(SchedulerTest, ShutdownExecutor)
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
- subscribe->set_force(true);
mesos.send(call);
}
@@ -598,7 +594,6 @@ TEST_F(SchedulerTest, Teardown)
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
- subscribe->set_force(true);
mesos.send(call);
}
@@ -695,7 +690,6 @@ TEST_F(SchedulerTest, Decline)
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
- subscribe->set_force(true);
mesos.send(call);
}
@@ -774,7 +768,6 @@ TEST_F(SchedulerTest, Revive)
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
- subscribe->set_force(true);
mesos.send(call);
}
@@ -873,7 +866,6 @@ TEST_F(SchedulerTest, Message)
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(DEFAULT_FRAMEWORK_INFO);
- subscribe->set_force(true);
mesos.send(call);
}