MCPcopy Create free account
hub / github.com/apache/mesos / recover

Function recover

src/slave/state.cpp:66–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65
66Try<State> recover(const string& rootDir, bool strict)
67{
68 LOG(INFO) << "Recovering state from '" << rootDir << "'";
69
70 State state;
71
72 // We consider the absence of 'rootDir' to mean that this is either
73 // the first time this slave was started or this slave was started after
74 // an upgrade (--recover=cleanup).
75 if (!os::exists(rootDir)) {
76 return state;
77 }
78
79 // Recover resources regardless whether the host has rebooted.
80 Try<ResourcesState> resources = ResourcesState::recover(rootDir, strict);
81 if (resources.isError()) {
82 return Error(resources.error());
83 }
84
85 // TODO(jieyu): Do not set 'state.resources' if we cannot find the
86 // resources checkpoint file.
87 state.resources = resources.get();
88
89 const string bootIdPath = paths::getBootIdPath(rootDir);
90 if (os::exists(bootIdPath)) {
91 Result<string> read = state::read<string>(bootIdPath);
92 if (read.isError()) {
93 LOG(WARNING) << "Failed to read '"
94 << bootIdPath << "': " << read.error();
95 } else {
96 Try<string> id = os::bootId();
97 CHECK_SOME(id);
98
99 if (id.get() != strings::trim(read.get())) {
100 LOG(INFO) << "Agent host rebooted";
101 state.rebooted = true;
102 }
103 }
104 }
105
106 const string latest = paths::getLatestSlavePath(rootDir);
107
108 // Check if the "latest" symlink to a slave directory exists.
109 if (!os::exists(latest)) {
110 // The slave was asked to shutdown or died before it registered
111 // and had a chance to create the "latest" symlink.
112 LOG(INFO) << "Failed to find the latest agent from '" << rootDir << "'";
113 return state;
114 }
115
116 // Get the latest slave id.
117 Result<string> directory = os::realpath(latest);
118 if (!directory.isSome()) {
119 return Error("Failed to find latest agent: " +
120 (directory.isError()
121 ? directory.error()
122 : "No such file or directory"));
123 }

Callers 2

foreachFunction · 0.70

Calls 13

getBootIdPathFunction · 0.85
trimFunction · 0.85
getLatestSlavePathFunction · 0.85
PathClass · 0.85
errorMethod · 0.65
existsFunction · 0.50
ErrorFunction · 0.50
bootIdFunction · 0.50
realpathFunction · 0.50
isErrorMethod · 0.45
getMethod · 0.45
isSomeMethod · 0.45

Tested by

no test coverage detected