Repository: mesos Updated Branches: refs/heads/1.5.x 336b067be -> 899efac6c
Simplified master's `updateOperation` function. This replaces repetitive code by instead using a helper variable which allows us to avoid branching. We can then also replace a `Try<bool>` with a plain `bool` further simplifying the code. Review: https://reviews.apache.org/r/65093/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/62f157ac Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/62f157ac Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/62f157ac Branch: refs/heads/1.5.x Commit: 62f157ac1c23f9a33b4fa71771f210da0376a26f Parents: 336b067 Author: Benjamin Bannier <[email protected]> Authored: Fri Jan 12 15:40:32 2018 -0800 Committer: Greg Mann <[email protected]> Committed: Fri Jan 12 17:17:38 2018 -0800 ---------------------------------------------------------------------- src/master/master.cpp | 48 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/62f157ac/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index e169a60..07bf76a 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -10320,37 +10320,8 @@ void Master::updateOperation( { CHECK_NOTNULL(operation); - const OperationStatus& status = update.status(); - - Option<OperationStatus> latestStatus; - if (update.has_latest_status()) { - latestStatus = update.latest_status(); - } - - // Whether the operation has just become terminated. - Option<bool> terminated; - - if (latestStatus.isSome()) { - terminated = - !protobuf::isTerminalState(operation->latest_status().state()) && - protobuf::isTerminalState(latestStatus->state()); - - // If the operation has already transitioned to a terminal state, - // do not update its state. - if (!protobuf::isTerminalState(operation->latest_status().state())) { - operation->mutable_latest_status()->CopyFrom(latestStatus.get()); - } - } else { - terminated = - !protobuf::isTerminalState(operation->latest_status().state()) && - protobuf::isTerminalState(status.state()); - - if (!protobuf::isTerminalState(operation->latest_status().state())) { - operation->mutable_latest_status()->CopyFrom(status); - } - } - - operation->add_statuses()->CopyFrom(status); + const OperationStatus& status = + update.has_latest_status() ? update.latest_status() : update.status(); LOG(INFO) << "Updating the state of operation '" << operation->info().id() << "' (uuid: " << update.operation_uuid() @@ -10358,9 +10329,20 @@ void Master::updateOperation( << " (latest state: " << operation->latest_status().state() << ", status update state: " << status.state() << ")"; - CHECK_SOME(terminated); + // Whether the operation has just become terminated. + const bool terminated = + !protobuf::isTerminalState(operation->latest_status().state()) && + protobuf::isTerminalState(status.state()); + + // If the operation has already transitioned to a terminal state, + // do not update its state. + if (!protobuf::isTerminalState(operation->latest_status().state())) { + operation->mutable_latest_status()->CopyFrom(status); + } + + operation->add_statuses()->CopyFrom(status); - if (!terminated.get()) { + if (!terminated) { return; }
