Fixed a bug related to persistent volumes during slave recovery. Review: https://reviews.apache.org/r/36684
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7f29a726 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7f29a726 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7f29a726 Branch: refs/heads/master Commit: 7f29a72602ad96861f1bb80cce466a82fa0e59e4 Parents: 47071a6 Author: Jie Yu <[email protected]> Authored: Tue Jul 21 23:42:19 2015 -0700 Committer: Jie Yu <[email protected]> Committed: Wed Jul 22 15:48:40 2015 -0700 ---------------------------------------------------------------------- .../isolators/filesystem/posix.cpp | 38 +++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/7f29a726/src/slave/containerizer/isolators/filesystem/posix.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/isolators/filesystem/posix.cpp b/src/slave/containerizer/isolators/filesystem/posix.cpp index 1904279..b78c547 100644 --- a/src/slave/containerizer/isolators/filesystem/posix.cpp +++ b/src/slave/containerizer/isolators/filesystem/posix.cpp @@ -218,15 +218,35 @@ Future<Nothing> PosixFilesystemIsolatorProcess::update( string link = path::join(info->directory, containerPath); - LOG(INFO) << "Adding symlink from '" << original << "' to '" - << link << "' for persistent volume " << resource - << " of container " << containerId; - - Try<Nothing> symlink = ::fs::symlink(original, link); - if (symlink.isError()) { - return Failure( - "Failed to symlink persistent volume from '" + - original + "' to '" + link + "'"); + if (os::exists(link)) { + // NOTE: This is possible because 'info->resources' will be + // reset when slave restarts and recovers. When the slave calls + // 'containerizer->update' after the executor re-registers, + // we'll try to relink all the already symlinked volumes. + Result<string> realpath = os::realpath(link); + if (!realpath.isSome()) { + return Failure( + "Failed to get the realpath of symlink '" + link + "': " + + (realpath.isError() ? realpath.error() : "No such directory")); + } + + // NOTE: A sanity check which we don't expect it to happen. + if (realpath.get() != original) { + return Failure( + "The existing symlink '" + link + "' points to '" + original + + "' and the new target is '" + realpath.get() + "'"); + } + } else { + LOG(INFO) << "Adding symlink from '" << original << "' to '" + << link << "' for persistent volume " << resource + << " of container " << containerId; + + Try<Nothing> symlink = ::fs::symlink(original, link); + if (symlink.isError()) { + return Failure( + "Failed to symlink persistent volume from '" + + original + "' to '" + link + "'"); + } } }
