You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2019/02/26 19:47:11 UTC

[mesos] branch master updated (6c4ff71 -> 8174ccf)

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

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


    from 6c4ff71  Avoided waiting for 180s when test `NvidiaDockerImage` fails.
     new aa75504  Added the concept of "orphaned operations" to the master.
     new 32e4a40  Handle possible orphaned operations after master/agent failover.
     new 2f0ed6d  Added cleanup logic for orphaned operations.
     new df9be40  Handled terminal operation status updates for orphans.
     new fd9d99c  Added a recovery path for orphan operation.
     new a0baa34  Modified when master responds to operation status updates.
     new 44c439b  Removed operations when removing resource providers.
     new 529ec27  Accounted for possible lack of OperationID in RP responses.
     new 01d4c74  Added test for tearing down frameworks while creating disks.
     new 8174ccf  Added test for terminal operation updates after master failover.

The 10 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/master/constants.hpp                           |   7 +
 src/master/master.cpp                              | 428 +++++++++++++++++----
 src/master/master.hpp                              |  21 +
 src/slave/slave.cpp                                |  13 +
 .../storage_local_resource_provider_tests.cpp      | 361 +++++++++++++++++
 5 files changed, 751 insertions(+), 79 deletions(-)


[mesos] 02/10: Handle possible orphaned operations after master/agent failover.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 32e4a404174e8d6b32b23a64569ae44ecd8e4351
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Tue Feb 12 14:06:31 2019 -0800

    Handle possible orphaned operations after master/agent failover.
    
    This is one of two possible code paths which can introduce orphaned
    operations.
    
    When a master failover occurs, all agents and frameworks must
    reregister with the master.  Agents that reregister will report their
    operations with an UpdateSlaveMessage.  Any operations without a
    known framework will be considered orphans.  Known frameworks are
    discovered when the framework reregisters, or an agent running a task
    under the framework reregisters.  The race between these reregistrations
    will be addressed in a separate commit.
    
    Agent failover can also introduce orphans, if the agent has a pending
    operation during failover, and then is migrated to a separate master
    before restarting.  This will be handled the same way as agent
    reregistration after a master failover.
    
    Review: https://reviews.apache.org/r/69961
---
 src/master/master.cpp | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/src/master/master.cpp b/src/master/master.cpp
index 75e6db7..da970a5 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -8232,6 +8232,11 @@ void Master::updateSlave(UpdateSlaveMessage&& message)
              resourceProvider.resource_version_uuid(),
              {}});
 
+        // NOTE: We must add the resource provider's resources to the total
+        // before adding any operations, because orphan operations will
+        // subsequently subtract from this total.
+        slave->totalResources += resourceProvider.total_resources();
+
         hashmap<FrameworkID, Resources> usedByOperations;
 
         foreach (
@@ -8248,8 +8253,8 @@ void Master::updateSlave(UpdateSlaveMessage&& message)
           if (!protobuf::isTerminalState(operation.latest_status().state()) &&
               operation.has_framework_id()) {
             // If we do not yet know the `FrameworkInfo` of the framework the
-            // operation originated from, we cannot properly track the operation
-            // at this point.
+            // operation originated from, the operation is an orphan, and
+            // will not be accounted for by the allocator.
             //
             // TODO(bbannier): Consider introducing ways of making sure an agent
             // always knows the `FrameworkInfo` of operations triggered on its
@@ -8257,12 +8262,6 @@ void Master::updateSlave(UpdateSlaveMessage&& message)
             // operations like is already done for `RunTaskMessage`, see
             // MESOS-8582.
             if (framework == nullptr) {
-              LOG(WARNING)
-                << "Cannot properly account for operation " << operation.uuid()
-                << " learnt in reconciliation of agent " << slaveId
-                << " since framework " << operation.framework_id()
-                << " is unknown; this can lead to assertion failures after the"
-                   " operation terminates, see MESOS-8536";
               continue;
             }
 
@@ -8278,8 +8277,6 @@ void Master::updateSlave(UpdateSlaveMessage&& message)
           }
         }
 
-        slave->totalResources += resourceProvider.total_resources();
-
         allocator->addResourceProvider(
             slaveId, resourceProvider.total_resources(), usedByOperations);
       } else {
@@ -11513,6 +11510,22 @@ void Master::addOperation(
 
   if (framework != nullptr) {
     framework->addOperation(operation);
+  } else {
+    // When the framework is not known by the master, this means either:
+    //   * The framework has been completed.
+    //   * The framework has no known tasks and has yet to reregister.
+    // The master cannot always differentiate these cases, because completed
+    // frameworks are only kept in memory, in a circular buffer.
+    //
+    // TODO(josephw): Once MESOS-8582 is resolved, operations may include
+    // enough information to add a framework entry, which means only
+    // completed frameworks would result in orphans.
+    //
+    // These operations will be preemptively considered "orphans" and
+    // will be given a grace period before the master adopts them.
+    // After which, the master will acknowledge any associated operation
+    // status updates.
+    slave->markOperationAsOrphan(operation);
   }
 }
 


[mesos] 05/10: Added a recovery path for orphan operation.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fd9d99cea0915b6006a396a5926322ca1352ccd4
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Tue Feb 12 16:08:32 2019 -0800

    Added a recovery path for orphan operation.
    
    An orphan can be recovered if the originating framework reregisters
    with the master.  When this happens, the resource accounting is
    reversed and resources are added back to the agent's total
    and the allocator.
    
    Review: https://reviews.apache.org/r/69967
---
 src/master/master.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 9 deletions(-)

diff --git a/src/master/master.cpp b/src/master/master.cpp
index de1ba56..1e04d82 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -10283,19 +10283,58 @@ void Master::recoverFramework(
       }
     }
 
-    foreachvalue (Operation* operation, slave->operations) {
+    // Combine all the operations of the agent into one list
+    // so they can be processed the same way.
+    vector<Operation*> allOperations = slave->operations.values();
+    foreachvalue (const Slave::ResourceProvider& resourceProvider,
+                  slave->resourceProviders) {
+      foreachvalue (Operation* operation, resourceProvider.operations) {
+        allOperations.push_back(operation);
+      }
+    }
+
+    foreach (Operation* operation, allOperations) {
       if (operation->has_framework_id() &&
           operation->framework_id() == framework->id()) {
         framework->addOperation(operation);
-      }
-    }
 
-    foreachvalue (const Slave::ResourceProvider& resourceProvider,
-                  slave->resourceProviders) {
-      foreachvalue (Operation* operation, resourceProvider.operations) {
-        if (operation->has_framework_id() &&
-            operation->framework_id() == framework->id()) {
-          framework->addOperation(operation);
+        // If this is an orphaned operation, the orphan's resources
+        // must be added back to the agent's total, and the allocator
+        // will need to be updated with the new total and allocation.
+        if (slave->orphanedOperations.contains(operation->uuid())) {
+          LOG(INFO)
+            << "Recovered orphan operation " << operation->uuid()
+            << (operation->info().has_id()
+                ? " (ID: " + operation->info().id().value() + ")"
+                : "")
+            << " on agent " << operation->slave_id()
+            << " belonging to framework " << operation->framework_id()
+            << " in state " << operation->latest_status().state();
+
+          slave->orphanedOperations.erase(operation->uuid());
+
+          // A terminal orphan operation is one whose resources are no longer
+          // allocated, but the terminal status has yet to be acknowledged.
+          // The operation will be removed once this framework acknowledges it.
+          if (protobuf::isTerminalState(operation->latest_status().state())) {
+            continue;
+          }
+
+          Try<Resources> consumed =
+            protobuf::getConsumedResources(operation->info());
+
+          CHECK_SOME(consumed);
+
+          Resources consumedUnallocated = consumed.get();
+          consumedUnallocated.unallocate();
+
+          slave->totalResources += consumedUnallocated;
+          slave->usedResources[framework->id()] += consumed.get();
+
+          allocator->updateSlave(slave->id, slave->info, slave->totalResources);
+
+          // NOTE: The allocation of these orphan operation resources will be
+          // updated in `addFramework` below.
         }
       }
     }


[mesos] 09/10: Added test for tearing down frameworks while creating disks.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 01d4c74f30cf32431c0bd70e5743dcdffab91b0e
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Wed Jan 30 17:32:31 2019 -0800

    Added test for tearing down frameworks while creating disks.
    
    The CREATE_DISK and DESTROY_DISK operations are "non-speculative"
    operations, which means the master must wait for the operations to
    complete successfully before the master can update its resources.
    Because the master must wait to update the results of non-speculative
    operations, it is possible for the framework making the
    CREATE/DESTROY_DISK to be torn down before the operation completes.
    
    This commit adds a test to make sure the master can gracefully handle
    such a case.
    
    Review: https://reviews.apache.org/r/69869
---
 .../storage_local_resource_provider_tests.cpp      | 170 +++++++++++++++++++++
 1 file changed, 170 insertions(+)

diff --git a/src/tests/storage_local_resource_provider_tests.cpp b/src/tests/storage_local_resource_provider_tests.cpp
index a661951..6b38c4f 100644
--- a/src/tests/storage_local_resource_provider_tests.cpp
+++ b/src/tests/storage_local_resource_provider_tests.cpp
@@ -5123,6 +5123,176 @@ TEST_F(StorageLocalResourceProviderTest, RetryRpcWithExponentialBackoff)
       "csi_plugin/rpcs/csi.v0.Controller.DeleteVolume/errors")));
 }
 
+
+// This test verifies the master can handle "non-speculative"
+// (i.e. the master cannot assume the success of the operation) operation
+// status updates that originate from frameworks which have been torn down.
+// Non-speculative operations include CREATE_DISK.
+TEST_F(
+    StorageLocalResourceProviderTest,
+    FrameworkTeardownBeforeTerminalOperationStatusUpdate)
+{
+  const string profilesPath = path::join(sandbox.get(), "profiles.json");
+
+  ASSERT_SOME(
+      os::write(profilesPath, createDiskProfileMapping({{"test", None()}})));
+
+  loadUriDiskProfileAdaptorModule(profilesPath);
+
+  setupResourceProviderConfig(Gigabytes(4));
+
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+
+  slave::Flags slaveFlags = CreateSlaveFlags();
+  slaveFlags.disk_profile_adaptor = URI_DISK_PROFILE_ADAPTOR_NAME;
+
+  Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+    FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
+  ASSERT_SOME(slave);
+
+  AWAIT_READY(slaveRegisteredMessage);
+
+  // Register a framework to exercise an operation.
+  v1::FrameworkInfo frameworkInfo = v1::DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_roles(0, "storage");
+
+  auto scheduler = std::make_shared<v1::MockHTTPScheduler>();
+
+  // NOTE: The scheduler may connect again after the TEARDOWN call.
+  EXPECT_CALL(*scheduler, connected(_))
+    .WillOnce(v1::scheduler::SendSubscribe(frameworkInfo))
+    .WillRepeatedly(Return());
+
+  Future<v1::scheduler::Event::Subscribed> subscribed;
+  EXPECT_CALL(*scheduler, subscribed(_, _))
+    .WillOnce(FutureArg<1>(&subscribed));
+
+  EXPECT_CALL(*scheduler, heartbeat(_))
+    .WillRepeatedly(Return()); // Ignore heartbeats.
+
+  // Decline offers that contain only the agent's default resources.
+  EXPECT_CALL(*scheduler, offers(_, _))
+    .WillRepeatedly(v1::scheduler::DeclineOffers());
+
+  // We are only interested in an offer with raw disk resources
+  auto isRaw = [](const v1::Resource& r) {
+    return r.has_disk() &&
+      r.disk().has_source() &&
+      r.disk().source().has_profile() &&
+      r.disk().source().type() == v1::Resource::DiskInfo::Source::RAW;
+  };
+
+  Future<v1::scheduler::Event::Offers> offers;
+
+  EXPECT_CALL(
+      *scheduler,
+      offers(_, v1::scheduler::OffersHaveAnyResource(isRaw)))
+    .WillOnce(FutureArg<1>(&offers));
+
+  v1::scheduler::TestMesos mesos(
+      master.get()->pid,
+      ContentType::PROTOBUF,
+      scheduler);
+
+  AWAIT_READY(subscribed);
+
+  const v1::FrameworkID& frameworkId = subscribed->framework_id();
+
+  // Prepare to intercept the terminal operation status message between
+  // agent and master, to allow the framework to teardown first.
+  // This will cause the operation to become an orphan operation.
+  Future<UpdateOperationStatusMessage> updateMessage =
+    DROP_PROTOBUF(
+        UpdateOperationStatusMessage(), slave.get()->pid, master.get()->pid);
+
+  AWAIT_READY(offers);
+  ASSERT_FALSE(offers->offers().empty());
+
+  const v1::Offer& offer = offers->offers(0);
+
+  ASSERT_FALSE(offer.resources().empty());
+
+  // The test relies on retry logic within the SLRP module to resend the
+  // terminal operation feedback message. We pause the clock here to control
+  // when this retry happens.
+  Clock::pause();
+
+  // Have the framework call CREATE_DISK, a non-speculative operation.
+  Option<v1::Resource> rawDisk;
+
+  foreach (const v1::Resource& resource, offer.resources()) {
+    if (isRaw(resource)) {
+      rawDisk = resource;
+      break;
+    }
+  }
+
+  ASSERT_SOME(rawDisk);
+
+  v1::OperationID operationId;
+  operationId.set_value("operation");
+
+  mesos.send(v1::createCallAccept(
+      frameworkId,
+      offer,
+      {v1::CREATE_DISK(
+          rawDisk.get(),
+          v1::Resource::DiskInfo::Source::MOUNT,
+          None(),
+          operationId)}));
+
+  // This message will be sent once the agent has completed the operation.
+  AWAIT_READY(updateMessage);
+
+  EXPECT_EQ(
+      OperationState::OPERATION_FINISHED, updateMessage->status().state());
+  EXPECT_EQ(
+      operationId.value(), updateMessage->status().operation_id().value());
+
+  // We can now tear down the framework, since we are certain the operation
+  // has reached the agent.
+  scheduler.reset();
+
+  {
+    v1::master::Call v1Call;
+    v1Call.set_type(v1::master::Call::TEARDOWN);
+
+    v1::master::Call::Teardown* teardown = v1Call.mutable_teardown();
+
+    teardown->mutable_framework_id()->CopyFrom(frameworkId);
+
+    Future<http::Response> response = process::http::post(
+        master.get()->pid,
+        "api/v1",
+        createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+        serialize(ContentType::PROTOBUF, v1Call),
+        stringify(ContentType::PROTOBUF));
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(http::OK().status, response);
+  }
+
+  // Since the scheduler is gone, the master will acknowledge the operation
+  // status update on its behalf.
+  Future<AcknowledgeOperationStatusMessage> acknowledgeOperationStatusMessage =
+    FUTURE_PROTOBUF(
+        AcknowledgeOperationStatusMessage(),
+        master.get()->pid,
+        slave.get()->pid);
+
+  // Resend the dropped operation status update.
+  Clock::advance(slave::STATUS_UPDATE_RETRY_INTERVAL_MIN);
+  Clock::settle();
+
+  AWAIT_READY(acknowledgeOperationStatusMessage);
+
+  Clock::resume();
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {


[mesos] 03/10: Added cleanup logic for orphaned operations.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2f0ed6dcd7762eee52d0152d09210b138ae8628a
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Tue Feb 12 14:19:05 2019 -0800

    Added cleanup logic for orphaned operations.
    
    The resources used by orphaned operations are not accounted for
    in the Slave struct's `usedResources`, and must be treated differently
    when cleaning up the operation.  Removal of non-terminal orphan
    operations will instead augment the `totalResources`.
    
    NOTE: The only codepath that can remove non-terminal operations is
    when removing the agent or a resource provider.  In this case,
    there is no need to update the allocator with the augmented
    `totalResources` because the removal codepaths will already
    update the allocator.
    
    Review: https://reviews.apache.org/r/69962
---
 src/master/master.cpp | 46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/src/master/master.cpp b/src/master/master.cpp
index da970a5..54f96f9 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -11697,8 +11697,11 @@ void Master::removeOperation(Operation* operation)
 
   // If the operation was not speculated and is not terminal we
   // need to also recover its used resources in the allocator.
+  // If the operation is an orphan, the resources have already been
+  // recovered from the allocator.
   if (!protobuf::isSpeculativeOperation(operation->info()) &&
-      !protobuf::isTerminalState(operation->latest_status().state())) {
+      !protobuf::isTerminalState(operation->latest_status().state()) &&
+      !slave->orphanedOperations.contains(operation->uuid())) {
     Try<Resources> consumed = protobuf::getConsumedResources(operation->info());
     CHECK_SOME(consumed);
 
@@ -12792,10 +12795,39 @@ void Slave::removeOperation(Operation* operation)
 
   CHECK(!resourceProviderId.isError()) << resourceProviderId.error();
 
-  // Recover the resource used by this operation.
-  if (!protobuf::isSpeculativeOperation(operation->info()) &&
-      !protobuf::isTerminalState(operation->latest_status().state())) {
-    recoverResources(operation);
+  if (orphanedOperations.contains(uuid)) {
+    orphanedOperations.erase(uuid);
+
+    CHECK(!protobuf::isSpeculativeOperation(operation->info()))
+      << "Orphaned operations can only be non-speculative";
+
+    // If the orphan is removed before reaching a terminal state,
+    // the used resources must be added back into the agent's total
+    // resources. Terminal orphaned operations are handled by
+    // `Master::updateOperation`.
+    if (!protobuf::isTerminalState(operation->latest_status().state())) {
+      Try<Resources> consumed =
+        protobuf::getConsumedResources(operation->info());
+
+      CHECK_SOME(consumed);
+
+      Resources consumedUnallocated = consumed.get();
+      consumedUnallocated.unallocate();
+
+      // NOTE: Non-terminal operations are only removed when the agent or
+      // resource provider is removed. When the agent is removed, the master
+      // will call `allocator->removeSlave` in `Master::_removeSlave()`.
+      // When a resource provider is removed, the master will call
+      // `allocator->updateSlave()` in `Master::updateSlave()`.
+      // This means we do not need to update the allocator in this method.
+      totalResources += consumedUnallocated;
+    }
+  } else {
+    // Recover the resource used by this operation.
+    if (!protobuf::isSpeculativeOperation(operation->info()) &&
+        !protobuf::isTerminalState(operation->latest_status().state())) {
+      recoverResources(operation);
+    }
   }
 
   // Remove the operation.
@@ -12804,7 +12836,7 @@ void Slave::removeOperation(Operation* operation)
       << "Unknown operation (uuid: " << uuid << ")"
       << " to agent " << *this;
 
-    operations.erase(operation->uuid());
+    operations.erase(uuid);
   } else {
     CHECK(resourceProviders.contains(resourceProviderId.get()))
       << "resource provider " << resourceProviderId.get() << " is unknown";
@@ -12817,7 +12849,7 @@ void Slave::removeOperation(Operation* operation)
       << " to resource provider " << resourceProviderId.get()
       << " on agent " << *this;
 
-    resourceProvider.operations.erase(operation->uuid());
+    resourceProvider.operations.erase(uuid);
   }
 }
 


[mesos] 10/10: Added test for terminal operation updates after master failover.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8174ccf0983c82e21ca103bc87a5f78d5bff4971
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Tue Feb 19 16:41:51 2019 -0800

    Added test for terminal operation updates after master failover.
    
    This test covers a corner case where an agent reregisters with the
    master with a pending operation, but the operation's originating
    framework is unknown.  This can occur in a variety of situations like:
      * the master fails over and a framework never reregisters,
      * a completed framework is rotated out of the master's memory with
        pending operations, or
      * an agent with pending operations is migrated from one cluster to
        another.
    
    In this case, the master should "adopt" the orphan operation only
    after a delay.  This gives the framework some time to reregister.
    But if the framework does not reregister in time, the master will
    be in charge of acknowledging operation status updates.
    
    Review: https://reviews.apache.org/r/70040
---
 .../storage_local_resource_provider_tests.cpp      | 191 +++++++++++++++++++++
 1 file changed, 191 insertions(+)

diff --git a/src/tests/storage_local_resource_provider_tests.cpp b/src/tests/storage_local_resource_provider_tests.cpp
index 6b38c4f..75f0d81 100644
--- a/src/tests/storage_local_resource_provider_tests.cpp
+++ b/src/tests/storage_local_resource_provider_tests.cpp
@@ -5293,6 +5293,197 @@ TEST_F(
   Clock::resume();
 }
 
+
+// This test verifies the master will adopt orphan operations reported
+// by agents upon reregistration. These orphans can appear whenever
+// the master fails over, but the operation's originating framework
+// never reregisters. Alternatively, and uncommonly, pending operations
+// on an agent migrated from one master to another will produce orphans.
+TEST_F(
+    StorageLocalResourceProviderTest,
+    TerminalOrphanOperationAfterMasterFailover)
+{
+  const string profilesPath = path::join(sandbox.get(), "profiles.json");
+
+  ASSERT_SOME(
+      os::write(profilesPath, createDiskProfileMapping({{"test", None()}})));
+
+  loadUriDiskProfileAdaptorModule(profilesPath);
+
+  setupResourceProviderConfig(Gigabytes(4));
+
+  master::Flags masterFlags = CreateMasterFlags();
+
+  // Greatly increase the ping timeout of the master/agent connection.
+  // The clock will be advanced by `MIN_WAIT_BEFORE_ORPHAN_OPERATION_ADOPTION`
+  // and if the ping timeout is less than this amount, the agent will
+  // disconnect.
+  masterFlags.agent_ping_timeout =
+    master::DEFAULT_AGENT_PING_TIMEOUT +
+    master::MIN_WAIT_BEFORE_ORPHAN_OPERATION_ADOPTION;
+
+  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
+  ASSERT_SOME(master);
+
+  // NOTE: This test needs to use the StandaloneMasterDetector directly
+  // (instead of the `cluster::Master::createDetector` helper) so that
+  // the restarted master can be detected by the running agent, when the
+  // test dictates.
+  StandaloneMasterDetector detector(master.get()->pid);
+
+  slave::Flags slaveFlags = CreateSlaveFlags();
+  slaveFlags.disk_profile_adaptor = URI_DISK_PROFILE_ADAPTOR_NAME;
+
+  Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+    FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+  Try<Owned<cluster::Slave>> slave = StartSlave(&detector, slaveFlags);
+  ASSERT_SOME(slave);
+
+  AWAIT_READY(slaveRegisteredMessage);
+
+  // Register a framework to exercise an operation.
+  v1::FrameworkInfo frameworkInfo = v1::DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_roles(0, "storage");
+
+  auto scheduler = std::make_shared<v1::MockHTTPScheduler>();
+
+  // NOTE: The scheduler may connect again after the TEARDOWN call.
+  EXPECT_CALL(*scheduler, connected(_))
+    .WillOnce(v1::scheduler::SendSubscribe(frameworkInfo))
+    .WillRepeatedly(Return());
+
+  Future<v1::scheduler::Event::Subscribed> subscribed;
+  EXPECT_CALL(*scheduler, subscribed(_, _))
+    .WillOnce(FutureArg<1>(&subscribed));
+
+  EXPECT_CALL(*scheduler, heartbeat(_))
+    .WillRepeatedly(Return()); // Ignore heartbeats.
+
+  // Decline offers that contain only the agent's default resources.
+  EXPECT_CALL(*scheduler, offers(_, _))
+    .WillRepeatedly(v1::scheduler::DeclineOffers());
+
+  // We are only interested in an offer with raw disk resources
+  auto isRaw = [](const v1::Resource& r) {
+    return r.has_disk() &&
+      r.disk().has_source() &&
+      r.disk().source().has_profile() &&
+      r.disk().source().type() == v1::Resource::DiskInfo::Source::RAW;
+  };
+
+  Future<v1::scheduler::Event::Offers> offers;
+
+  EXPECT_CALL(
+      *scheduler,
+      offers(_, v1::scheduler::OffersHaveAnyResource(isRaw)))
+    .WillOnce(FutureArg<1>(&offers));
+
+  v1::scheduler::TestMesos mesos(
+      master.get()->pid,
+      ContentType::PROTOBUF,
+      scheduler);
+
+  AWAIT_READY(subscribed);
+
+  const v1::FrameworkID& frameworkId = subscribed->framework_id();
+
+  // Prepare to intercept the terminal operation status message between
+  // agent and master, to allow the master to failover first.
+  // This creates a situation where the master forgets about the
+  // framework that started the operation.
+  Future<UpdateOperationStatusMessage> updateMessage =
+    DROP_PROTOBUF(
+        UpdateOperationStatusMessage(), slave.get()->pid, master.get()->pid);
+
+  AWAIT_READY(offers);
+  ASSERT_FALSE(offers->offers().empty());
+
+  const v1::Offer& offer = offers->offers(0);
+
+  ASSERT_FALSE(offer.resources().empty());
+
+  // The test relies on retry logic within the SLRP module to resend the
+  // terminal operation feedback message. We pause the clock here to control
+  // when this retry happens.
+  Clock::pause();
+
+  // Have the framework call CREATE_DISK, a non-speculative operation.
+  Option<v1::Resource> rawDisk;
+
+  foreach (const v1::Resource& resource, offer.resources()) {
+    if (isRaw(resource)) {
+      rawDisk = resource;
+      break;
+    }
+  }
+
+  ASSERT_SOME(rawDisk);
+
+  v1::OperationID operationId;
+  operationId.set_value("operation");
+
+  mesos.send(v1::createCallAccept(
+      frameworkId,
+      offer,
+      {v1::CREATE_DISK(
+          rawDisk.get(),
+          v1::Resource::DiskInfo::Source::MOUNT,
+          None(),
+          operationId)}));
+
+  // This message will be sent once the agent has completed the operation.
+  AWAIT_READY(updateMessage);
+
+  EXPECT_EQ(
+      OperationState::OPERATION_FINISHED, updateMessage->status().state());
+  EXPECT_EQ(
+      operationId.value(), updateMessage->status().operation_id().value());
+
+  Future<SlaveReregisteredMessage> slaveReregisteredMessage =
+    FUTURE_PROTOBUF(SlaveReregisteredMessage(), _, _);
+
+  // Trigger a master failover to enter a situation where a terminal operation
+  // is orphaned, and the originating framework is not "completed".
+  detector.appoint(None());
+  master->reset();
+
+  // Get rid of the framework so that it does not reregister.
+  // We want the framework to remain unknown after the master/agent recovers.
+  scheduler.reset();
+
+  // Start the master back up and wait for the agent to reregister.
+  master = StartMaster(masterFlags);
+  ASSERT_SOME(master);
+  detector.appoint(master.get()->pid);
+
+  Clock::advance(slaveFlags.registration_backoff_factor);
+  AWAIT_READY(slaveReregisteredMessage);
+
+  Future<AcknowledgeOperationStatusMessage> acknowledgeOperationStatusMessage =
+    FUTURE_PROTOBUF(
+        AcknowledgeOperationStatusMessage(),
+        master.get()->pid,
+        slave.get()->pid);
+
+  // Trigger a retry of the operation status update. The master should drop
+  // this one because the agent has just reregistered and the framework is
+  // unknown.
+  Clock::advance(slave::STATUS_UPDATE_RETRY_INTERVAL_MIN);
+  Clock::settle();
+
+  ASSERT_TRUE(acknowledgeOperationStatusMessage.isPending());
+
+  // Trigger a retry after advancing the clock beyond the operation "adoption"
+  // time, which means the master should acknowledge the terminal status.
+  Clock::advance(master::MIN_WAIT_BEFORE_ORPHAN_OPERATION_ADOPTION);
+  Clock::settle();
+
+  AWAIT_READY(acknowledgeOperationStatusMessage);
+
+  Clock::resume();
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {


[mesos] 01/10: Added the concept of "orphaned operations" to the master.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit aa75504c4b7baaf2c6d4af4829f3ea98982e291e
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Tue Feb 12 11:48:44 2019 -0800

    Added the concept of "orphaned operations" to the master.
    
    An orphaned operation is a non-speculative operation whose
    originating framework is unknown.  These operations will consume
    resources until they are terminated, but will have no entry
    in the allocator because their associated framework does not exist.
    
    To account for resources used by orphaned operations, the operation's
    resources are removed from the agent's total resources upon being
    orphaned.
    
    This commit handles one of the two possible code paths which can
    introduce orphaned operations.
    
    Review: https://reviews.apache.org/r/69960
---
 src/master/master.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/master/master.hpp | 21 +++++++++++++
 2 files changed, 103 insertions(+)

diff --git a/src/master/master.cpp b/src/master/master.cpp
index 015da54..75e6db7 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -10645,7 +10645,26 @@ void Master::removeFramework(Framework* framework)
     }
   }
 
+  hashset<Slave*> slavesWithOrphanOperations;
   foreachvalue (Operation* operation, utils::copy(framework->operations)) {
+    // Non-speculative operations are considered "orphaned" once the
+    // originating framework is removed. The resources used by the
+    // operation will remain allocated until a terminal operation
+    // status update is received.
+    if (!protobuf::isSpeculativeOperation(operation->info())) {
+      CHECK(operation->has_slave_id())
+        << "External resource provider is not supported yet";
+
+      Slave* slave = slaves.registered.get(operation->slave_id());
+      CHECK_NOTNULL(slave);
+
+      slave->markOperationAsOrphan(operation);
+
+      // We defer the required updates to the allocator until after the
+      // framework has been removed from the allocator.
+      slavesWithOrphanOperations.insert(slave);
+    }
+
     framework->removeOperation(operation);
   }
 
@@ -10684,10 +10703,28 @@ void Master::removeFramework(Framework* framework)
     }
   }
 
+  // Prevent any allocations from ocurring between the multiple resource
+  // changes below. Removal of a framework removes allocation, while orphan
+  // operations will reduce total resources.
+  allocator->pause();
+
   // Remove the framework.
   frameworks.registered.erase(framework->id());
   allocator->removeFramework(framework->id());
 
+  // For any pending operations, we temporarily remove the operations'
+  // resources from the allocator, because these resources are technically
+  // still in use by the (now removed) framework.
+  foreach (Slave* slave, slavesWithOrphanOperations) {
+    allocator->updateSlave(slave->id, slave->info, slave->totalResources);
+
+    // NOTE: Even though we are modifying the slave's total resources, we
+    // do not need to rescind any offers because the resources removed cannot
+    // be offered between the `removeFramework()` and `updateSlave()` calls.
+  }
+
+  allocator->resume();
+
   // The framework pointer is now owned by `frameworks.completed`.
   frameworks.completed.set(framework->id(), Owned<Framework>(framework));
 
@@ -12772,6 +12809,51 @@ void Slave::removeOperation(Operation* operation)
 }
 
 
+void Slave::markOperationAsOrphan(Operation* operation)
+{
+  // Only non-speculative operations can be orphaned.
+  if (protobuf::isSpeculativeOperation(operation->info())) {
+    return;
+  }
+
+  LOG(INFO) << "Marking operation " << operation->uuid()
+            << (operation->info().has_id()
+                ? " (ID: " + operation->info().id().value() + ")"
+                : "")
+            << (operation->has_slave_id()
+                ? " (Agent: " + operation->slave_id().value() + ")"
+                : "")
+            << (operation->has_framework_id()
+                ? " (Framework: " + operation->framework_id().value() + ")"
+                : "")
+            << " in state " << operation->latest_status().state()
+            << " as an orphan";
+
+  orphanedOperations.insert(operation->uuid());
+
+  // Only non-terminal orphans require additional resource math.
+  if (protobuf::isTerminalState(operation->latest_status().state())) {
+    return;
+  }
+
+  // Orphaned operations have no framework, and hence cannot be accounted
+  // for within the allocator. Instead, the operation's resources are removed
+  // from the agent's total resources until the operation terminates.
+  recoverResources(operation);
+
+  Try<Resources> consumed = protobuf::getConsumedResources(operation->info());
+  CHECK_SOME(consumed);
+
+  Resources consumedUnallocated = consumed.get();
+  consumedUnallocated.unallocate();
+
+  CHECK(totalResources.contains(consumedUnallocated))
+    << "Unknown resources from orphan operation: " << consumedUnallocated;
+
+  totalResources -= consumedUnallocated;
+}
+
+
 Operation* Slave::getOperation(const UUID& uuid) const
 {
   if (operations.contains(uuid)) {
diff --git a/src/master/master.hpp b/src/master/master.hpp
index ccd117f..aceab34 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -153,6 +153,14 @@ Slave(Master* const _master,
 
   void removeOperation(Operation* operation);
 
+  // Marks a non-speculative operation as an orphan when the originating
+  // framework is torn down by the master, or when an agent reregisters
+  // with operations from unknown frameworks. If the operation is
+  // non-terminal, this has the side effect of modifying the agent's
+  // total resources, and should therefore be followed by
+  // `allocator->updateSlave()`.
+  void markOperationAsOrphan(Operation* operation);
+
   Operation* getOperation(const UUID& uuid) const;
 
   void addOffer(Offer* offer);
@@ -248,6 +256,19 @@ Slave(Master* const _master,
   // unacknowledged status updates on this agent.
   hashmap<UUID, Operation*> operations;
 
+  // Pending operations whose originating framework is unknown.
+  // These operations could be pending, or terminal with unacknowledged
+  // status updates.
+  //
+  // This list can be populated whenever a framework is torn down in the
+  // lifetime of the master, or when an agent reregisters with an operation.
+  //
+  // If the originating framework is completed, the master will
+  // acknowledge any status updates instead of the framework.
+  // If an orphan does not belong to a completed framework, the master
+  // will only acknowledge status updates after a fixed delay.
+  hashset<UUID> orphanedOperations;
+
   // Active offers on this slave.
   hashset<Offer*> offers;
 


[mesos] 07/10: Removed operations when removing resource providers.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 44c439baae0c273025f183ecf26e4b1bc4be8262
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Tue Feb 19 14:44:47 2019 -0800

    Removed operations when removing resource providers.
    
    When a resource provider explicitly disconnects from the agent, the
    agent will send a `UpdateSlaveMessage` to the master, telling the
    master to remove the resource provider.  If there are any operations
    associated with the resource provider, they must be removed too,
    because there is no way to make forward progress on resource provider
    operations without a resource provider.
    
    This removes a potential memory leak in the master's Framework structs.
    
    Review: https://reviews.apache.org/r/70014
---
 src/master/master.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/master/master.cpp b/src/master/master.cpp
index f71c6fd..665c1c7 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -8391,6 +8391,15 @@ void Master::updateSlave(UpdateSlaveMessage&& message)
       // total, but never in the used resources.
       CHECK(slave->resourceProviders.contains(resourceProviderId));
 
+      // Clean up any associated operations belonging to the removed
+      // resource provider.
+      foreachvalue (
+          Operation* operation,
+          utils::copy(slave->resourceProviders.at(resourceProviderId)
+            .operations)) {
+        removeOperation(operation);
+      }
+
       slave->totalResources -=
         slave->resourceProviders.at(resourceProviderId).totalResources;
 


[mesos] 04/10: Handled terminal operation status updates for orphans.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit df9be400cefe99f73fb5f2af9c51127caede845c
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Tue Feb 12 14:58:33 2019 -0800

    Handled terminal operation status updates for orphans.
    
    When an orphaned operation is transitioned from non-terminal to
    terminal, the operation's resources must be added back to the agent's
    total resources, while accounting for resource conversion if the
    operation is successful.
    
    There is an odd case where an orphan is transitioned to terminal
    via an UpdateSlaveMessage (instead of UpdateOperationStatusMessage).
    When this happens, the required resource math is actually done by
    the agent.
    
    Review: https://reviews.apache.org/r/69963
---
 src/master/master.cpp | 173 ++++++++++++++++++++++++++++++++++----------------
 1 file changed, 120 insertions(+), 53 deletions(-)

diff --git a/src/master/master.cpp b/src/master/master.cpp
index 54f96f9..de1ba56 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -11598,77 +11598,144 @@ void Master::updateOperation(
   Slave* slave = slaves.registered.get(operation->slave_id());
   CHECK_NOTNULL(slave);
 
-  switch (operation->latest_status().state()) {
-    // Terminal state, and the conversion is successful.
-    case OPERATION_FINISHED: {
-      const Resources converted =
-        operation->latest_status().converted_resources();
-
-      if (convertResources) {
-        allocator->updateAllocation(
-            operation->framework_id(),
-            operation->slave_id(),
-            consumed.get(),
-            {ResourceConversion(consumed.get(), converted)});
+  // Orphaned operations are handled differently, because the allocator
+  // has no knowledge of resources consumed by these operations;
+  // and any resource consumption is accounted for in the agent's total
+  // resources.
+  if (slave->orphanedOperations.contains(operation->uuid())) {
+    bool updated = false;
+
+    switch (operation->latest_status().state()) {
+      // Terminal state, and the conversion is successful.
+      case OPERATION_FINISHED: {
+        const Resources converted =
+          operation->latest_status().converted_resources();
+
+        if (convertResources) {
+          Resources convertedUnallocated = converted;
+          convertedUnallocated.unallocate();
+
+          slave->totalResources += convertedUnallocated;
+          updated = true;
+        } else {
+          // NOTE: This is only reachable when an existing orphan operation
+          // is transitioned to a terminal status via an UpdateSlaveMessage.
+          // When this happens, the `slave->totalResources` already contains
+          // the converted resources.
+          // The handling for normal operations must recover the consumed
+          // resources from the allocator. We cannot mirror this resource
+          // recovery (i.e. `slave->totalResources += consumed.get()`) because
+          // the resource has already been converted and no longer exists.
+        }
 
-        allocator->recoverResources(
-            operation->framework_id(),
-            operation->slave_id(),
-            converted,
-            None());
+        break;
+      }
 
+      // Terminal state, and the conversion has failed.
+      case OPERATION_DROPPED:
+      case OPERATION_ERROR:
+      case OPERATION_FAILED:
+      case OPERATION_GONE_BY_OPERATOR: {
         Resources consumedUnallocated = consumed.get();
         consumedUnallocated.unallocate();
 
-        Resources convertedUnallocated = converted;
-        convertedUnallocated.unallocate();
+        slave->totalResources += consumedUnallocated;
+        updated = true;
+        break;
+      }
+
+      // Non-terminal or not expected from an agent. This shouldn't happen.
+      case OPERATION_UNSUPPORTED:
+      case OPERATION_PENDING:
+      case OPERATION_UNREACHABLE:
+      case OPERATION_RECOVERING:
+      case OPERATION_UNKNOWN: {
+        LOG(FATAL) << "Unexpected operation state "
+                   << operation->latest_status().state();
 
-        slave->apply(
-            {ResourceConversion(consumedUnallocated, convertedUnallocated)});
-      } else {
+        break;
+      }
+    }
+
+    // If we've added resources to the agent's total, the allocator
+    // must be informed about the new totals.
+    if (updated) {
+      allocator->updateSlave(slave->id, slave->info, slave->totalResources);
+    }
+
+  } else {
+    switch (operation->latest_status().state()) {
+      // Terminal state, and the conversion is successful.
+      case OPERATION_FINISHED: {
+        const Resources converted =
+          operation->latest_status().converted_resources();
+
+        if (convertResources) {
+          allocator->updateAllocation(
+              operation->framework_id(),
+              operation->slave_id(),
+              consumed.get(),
+              {ResourceConversion(consumed.get(), converted)});
+
+          allocator->recoverResources(
+              operation->framework_id(),
+              operation->slave_id(),
+              converted,
+              None());
+
+          Resources consumedUnallocated = consumed.get();
+          consumedUnallocated.unallocate();
+
+          Resources convertedUnallocated = converted;
+          convertedUnallocated.unallocate();
+
+          slave->apply(
+              {ResourceConversion(consumedUnallocated, convertedUnallocated)});
+        } else {
+          allocator->recoverResources(
+              operation->framework_id(),
+              operation->slave_id(),
+              consumed.get(),
+              None());
+        }
+
+        break;
+      }
+
+      // Terminal state, and the conversion has failed.
+      case OPERATION_DROPPED:
+      case OPERATION_ERROR:
+      case OPERATION_FAILED:
+      case OPERATION_GONE_BY_OPERATOR: {
         allocator->recoverResources(
             operation->framework_id(),
             operation->slave_id(),
             consumed.get(),
             None());
-      }
-
-      break;
-    }
 
-    // Terminal state, and the conversion has failed.
-    case OPERATION_DROPPED:
-    case OPERATION_ERROR:
-    case OPERATION_FAILED:
-    case OPERATION_GONE_BY_OPERATOR: {
-      allocator->recoverResources(
-          operation->framework_id(),
-          operation->slave_id(),
-          consumed.get(),
-          None());
-
-      break;
-    }
+        break;
+      }
 
-    // Non-terminal or not expected from an agent. This shouldn't happen.
-    case OPERATION_UNSUPPORTED:
-    case OPERATION_PENDING:
-    case OPERATION_UNREACHABLE:
-    case OPERATION_RECOVERING:
-    case OPERATION_UNKNOWN: {
-      LOG(FATAL) << "Unexpected operation state "
-                 << operation->latest_status().state();
+      // Non-terminal or not expected from an agent. This shouldn't happen.
+      case OPERATION_UNSUPPORTED:
+      case OPERATION_PENDING:
+      case OPERATION_UNREACHABLE:
+      case OPERATION_RECOVERING:
+      case OPERATION_UNKNOWN: {
+        LOG(FATAL) << "Unexpected operation state "
+                   << operation->latest_status().state();
 
-      break;
+        break;
+      }
     }
-  }
 
-  slave->recoverResources(operation);
+    slave->recoverResources(operation);
 
-  Framework* framework = getFramework(operation->framework_id());
+    Framework* framework = getFramework(operation->framework_id());
 
-  if (framework != nullptr) {
-    framework->recoverResources(operation);
+    if (framework != nullptr) {
+      framework->recoverResources(operation);
+    }
   }
 }
 


[mesos] 06/10: Modified when master responds to operation status updates.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a0baa345b2eb6483648fcbcd7af8aa9eac9148c3
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Wed Feb 13 15:00:51 2019 -0800

    Modified when master responds to operation status updates.
    
    When dealing with orphaned operation status updates, there are two
    cases the master must deal with:
    - The simple case is when the master knows the framework is completed.
      These status updates can be acknowledged by the master.
    - However, a completed framework can be rotated out of the master's
      memory.  In addition, after master failover, if an agent reregisters
      before the framework, an operation can appear to be orphaned until
      the framework reregisters.
    
    This adds a fixed delay between agent reregistration and when the
    master acknowledges operation status updates from unknown frameworks.
    The delay should give frameworks ample time to reregister.
    
    The delay is based on agent reregistration in order to mitigate the
    delay of acknowledging status updates of frameworks rotated out of
    the completed frameworks buffer.
    
    Review: https://reviews.apache.org/r/69980
---
 src/master/constants.hpp |  7 +++++++
 src/master/master.cpp    | 30 +++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/master/constants.hpp b/src/master/constants.hpp
index b0ab918..8f729d1 100644
--- a/src/master/constants.hpp
+++ b/src/master/constants.hpp
@@ -106,6 +106,13 @@ constexpr size_t DEFAULT_MAX_COMPLETED_TASKS_PER_FRAMEWORK = 1000;
 // to store in the cache.
 constexpr size_t DEFAULT_MAX_UNREACHABLE_TASKS_PER_FRAMEWORK = 1000;
 
+// The minimum amount of time the master waits for a framework to reregister
+// before the master adopts any operations originating from that
+// framework. This applies to any framework not explicitly marked "completed"
+// in the master's memory.
+// Adopted operations will be acknowledged by the master.
+constexpr Duration MIN_WAIT_BEFORE_ORPHAN_OPERATION_ADOPTION = Minutes(10);
+
 // Time interval to check for updated watchers list.
 constexpr Duration WHITELIST_WATCH_INTERVAL = Seconds(5);
 
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 1e04d82..f71c6fd 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -8725,9 +8725,13 @@ void Master::updateOperationStatus(UpdateOperationStatusMessage&& update)
 
   const OperationStatus& latestStatus = *operation->statuses().rbegin();
 
+  // Frameworks are sent operation status updates when the operation has
+  // a framework-specified ID and the framework is still running.
+  // Orphaned operations have no framework to send updates to.
   bool frameworkWillAcknowledge =
     operation->info().has_id() &&
-    !isCompletedFramework(frameworkId.get());
+    !isCompletedFramework(frameworkId.get()) &&
+    !slave->orphanedOperations.contains(operation->uuid());
 
   if (frameworkWillAcknowledge) {
     // Forward the status update to the framework.
@@ -8754,6 +8758,30 @@ void Master::updateOperationStatus(UpdateOperationStatusMessage&& update)
       // an operation ID or the associated framework terminated, so
       // the master has to send an acknowledgement.
 
+      // If an orphan operation belongs to a framework that is not
+      // marked "completed", there is a chance the framework will
+      // reregister in future. The master will drop these status
+      // updates until the framework reregisters or a certain amount
+      // of time has passed since the associated agent has reregistered.
+      //
+      // This behavior prevents the master from acknowledging operations
+      // directly after master failover, while both agents and frameworks
+      // reregister. If an agent with pending operations reregisters first,
+      // the operations may be considered orphans until the framework
+      // reregisters.
+      //
+      // NOTE: Frameworks rotated out of the master's completed frameworks
+      // buffer may also be affected by this wait.
+      if (operation->info().has_id() &&
+          slave->orphanedOperations.contains(operation->uuid()) &&
+          !isCompletedFramework(frameworkId.get())) {
+        if (slave->reregisteredTime.isSome() &&
+            (Clock::now() - slave->reregisteredTime.get()) <
+              MIN_WAIT_BEFORE_ORPHAN_OPERATION_ADOPTION) {
+          return;
+        }
+      }
+
       Result<ResourceProviderID> resourceProviderId =
         getResourceProviderId(operation->info());
 


[mesos] 08/10: Accounted for possible lack of OperationID in RP responses.

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 529ec2783159b9b1517a49271e8b30e87deebfec
Author: Joseph Wu <jo...@apache.org>
AuthorDate: Wed Jan 30 18:32:38 2019 -0800

    Accounted for possible lack of OperationID in RP responses.
    
    Operations sent to a resource provider may include an OperationID
    in addition to an Operation UUID.  The UUID is sufficient to uniquely
    identify the operation, so it is possible for the resource provider
    to omit the OperationID in its responses to the agent.
    
    This commit lets the agent fill in any missing ID before updates
    are acted upon, such as being sent to the master.
    
    Review: https://reviews.apache.org/r/69872
---
 src/slave/slave.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index e3c2c00..75f0d9d 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -8084,6 +8084,19 @@ void Slave::handleResourceProviderMessage(
       Operation* operation = getOperation(operationUUID);
 
       if (operation != nullptr) {
+        // It is possible for the resource provider to forget or incorrectly
+        // copy the OperationID in its status update. We make sure the ID
+        // is filled in with the correct value before proceeding.
+        if (operation->info().has_id()) {
+          update.mutable_status()->mutable_operation_id()
+            ->CopyFrom(operation->info().id());
+
+          if (update.has_latest_status()) {
+            update.mutable_latest_status()->mutable_operation_id()
+              ->CopyFrom(operation->info().id());
+          }
+        }
+
         // The agent might not know about the operation in the
         // following cases:
         //