Re-order structs to prevent forward declaration dependency.

Necessary for unrestricted union implementation of Option<T>.

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


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

Branch: refs/heads/master
Commit: 1226e0ad6b036a19a5b981c7c1b85941677e25c5
Parents: a5640ad
Author: Joris Van Remoortere <[email protected]>
Authored: Sat May 2 17:16:58 2015 -0700
Committer: Benjamin Hindman <[email protected]>
Committed: Sat May 2 17:51:48 2015 -0700

----------------------------------------------------------------------
 src/slave/state.hpp | 124 +++++++++++++++++++++++++----------------------
 1 file changed, 66 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1226e0ad/src/slave/state.hpp
----------------------------------------------------------------------
diff --git a/src/slave/state.hpp b/src/slave/state.hpp
index 31dfdd5..fed4b7e 100644
--- a/src/slave/state.hpp
+++ b/src/slave/state.hpp
@@ -47,11 +47,12 @@ namespace state {
 // Forward declarations.
 struct State;
 struct SlaveState;
+struct ResourcesState;
 struct FrameworkState;
 struct ExecutorState;
 struct RunState;
 struct TaskState;
-struct ResourcesState;
+
 
 // This function performs recovery from the state stored at 'rootDir'.
 // If the 'strict' flag is set, any errors encountered while
@@ -66,6 +67,7 @@ struct ResourcesState;
 // machine has rebooted since the last slave run, None is returned.
 Result<State> recover(const std::string& rootDir, bool strict);
 
+
 namespace internal {
 
 inline Try<Nothing> checkpoint(
@@ -166,47 +168,72 @@ Try<Nothing> checkpoint(const std::string& path, const T& 
t)
 }
 
 
-// The top level state. Each of the structs below (recursively)
-// recover the checkpointed state.
-struct State
+// NOTE: The *State structs (e.g., TaskState, RunState, etc) are
+// defined in reverse dependency order because many of them have
+// Option<*State> dependencies which means we need them declared in
+// their entirety in order to compile because things like
+// Option<*State> need to know the final size of the types.
+
+struct TaskState
 {
-  State() : errors(0) {}
+  TaskState () : errors(0) {}
 
-  Option<ResourcesState> resources;
-  Option<SlaveState> slave;
+  static Try<TaskState> recover(
+      const std::string& rootDir,
+      const SlaveID& slaveId,
+      const FrameworkID& frameworkId,
+      const ExecutorID& executorId,
+      const ContainerID& containerId,
+      const TaskID& taskId,
+      bool strict);
 
-  // TODO(jieyu): Consider using a vector of Option<Error> here so
-  // that we can print all the errors. This also applies to all the
-  // State structs below.
+  TaskID id;
+  Option<Task> info;
+  std::vector<StatusUpdate> updates;
+  hashset<UUID> acks;
   unsigned int errors;
 };
 
 
-struct ResourcesState
+struct RunState
 {
-  ResourcesState() : errors(0) {}
+  RunState () : completed(false), errors(0) {}
 
-  static Try<ResourcesState> recover(
+  static Try<RunState> recover(
       const std::string& rootDir,
+      const SlaveID& slaveId,
+      const FrameworkID& frameworkId,
+      const ExecutorID& executorId,
+      const ContainerID& containerId,
       bool strict);
 
-  Resources resources;
+  Option<ContainerID> id;
+  hashmap<TaskID, TaskState> tasks;
+  Option<pid_t> forkedPid;
+  Option<process::UPID> libprocessPid;
+
+  // Executor terminated and all its updates acknowledged.
+  bool completed;
+
   unsigned int errors;
 };
 
 
-struct SlaveState
+struct ExecutorState
 {
-  SlaveState () : errors(0) {}
+  ExecutorState () : errors(0) {}
 
-  static Try<SlaveState> recover(
+  static Try<ExecutorState> recover(
       const std::string& rootDir,
       const SlaveID& slaveId,
+      const FrameworkID& frameworkId,
+      const ExecutorID& executorId,
       bool strict);
 
-  SlaveID id;
-  Option<SlaveInfo> info;
-  hashmap<FrameworkID, FrameworkState> frameworks;
+  ExecutorID id;
+  Option<ExecutorInfo> info;
+  Option<ContainerID> latest;
+  hashmap<ContainerID, RunState> runs;
   unsigned int errors;
 };
 
@@ -229,66 +256,47 @@ struct FrameworkState
 };
 
 
-struct ExecutorState
+struct ResourcesState
 {
-  ExecutorState () : errors(0) {}
+  ResourcesState() : errors(0) {}
 
-  static Try<ExecutorState> recover(
+  static Try<ResourcesState> recover(
       const std::string& rootDir,
-      const SlaveID& slaveId,
-      const FrameworkID& frameworkId,
-      const ExecutorID& executorId,
       bool strict);
 
-  ExecutorID id;
-  Option<ExecutorInfo> info;
-  Option<ContainerID> latest;
-  hashmap<ContainerID, RunState> runs;
+  Resources resources;
   unsigned int errors;
 };
 
 
-struct RunState
+struct SlaveState
 {
-  RunState () : completed(false), errors(0) {}
+  SlaveState () : errors(0) {}
 
-  static Try<RunState> recover(
+  static Try<SlaveState> recover(
       const std::string& rootDir,
       const SlaveID& slaveId,
-      const FrameworkID& frameworkId,
-      const ExecutorID& executorId,
-      const ContainerID& containerId,
       bool strict);
 
-  Option<ContainerID> id;
-  hashmap<TaskID, TaskState> tasks;
-  Option<pid_t> forkedPid;
-  Option<process::UPID> libprocessPid;
-
-  // Executor terminated and all its updates acknowledged.
-  bool completed;
-
+  SlaveID id;
+  Option<SlaveInfo> info;
+  hashmap<FrameworkID, FrameworkState> frameworks;
   unsigned int errors;
 };
 
 
-struct TaskState
+// The top level state. The members are child nodes in the tree. Each
+// child node (recursively) recovers the checkpointed state.
+struct State
 {
-  TaskState () : errors(0) {}
+  State() : errors(0) {}
 
-  static Try<TaskState> recover(
-      const std::string& rootDir,
-      const SlaveID& slaveId,
-      const FrameworkID& frameworkId,
-      const ExecutorID& executorId,
-      const ContainerID& containerId,
-      const TaskID& taskId,
-      bool strict);
+  Option<ResourcesState> resources;
+  Option<SlaveState> slave;
 
-  TaskID id;
-  Option<Task> info;
-  std::vector<StatusUpdate> updates;
-  hashset<UUID> acks;
+  // TODO(jieyu): Consider using a vector of Option<Error> here so
+  // that we can print all the errors. This also applies to all the
+  // State structs below.
   unsigned int errors;
 };
 

Reply via email to