Apache Mesos
disk.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __POSIX_DISK_ISOLATOR_HPP__
18 #define __POSIX_DISK_ISOLATOR_HPP__
19 
20 #include <string>
21 
22 #include <process/owned.hpp>
23 
24 #include <stout/bytes.hpp>
25 #include <stout/duration.hpp>
26 #include <stout/hashmap.hpp>
27 #include <stout/hashset.hpp>
28 
29 #include "slave/flags.hpp"
30 
32 
33 namespace mesos {
34 namespace internal {
35 namespace slave {
36 
37 // Forward declarations.
38 class DiskUsageCollectorProcess;
39 
40 
41 // Responsible for collecting disk usage for paths, while ensuring
42 // that an interval elapses between each collection.
44 {
45 public:
46  DiskUsageCollector(const Duration& interval);
48 
49  // Returns the disk usage rooted at 'path'. The user can discard the
50  // returned future to cancel the check.
52  const std::string& path,
53  const std::vector<std::string>& excludes);
54 
55 private:
56  DiskUsageCollectorProcess* process;
57 };
58 
59 
60 // This isolator monitors the disk usage for containers, and reports
61 // ContainerLimitation when a container exceeds its disk quota. This
62 // leverages the DiskUsageCollector to ensure that we don't induce too
63 // much CPU usage and disk caching effects from running 'du' too
64 // often.
65 //
66 // NOTE: Currently all containers are processed in the same queue,
67 // which means that when a container starts, it could take many disk
68 // collection intervals until any data is available in the resource
69 // usage statistics!
70 //
71 // TODO(jieyu): Consider handling each container independently, or
72 // triggering an initial collection when the container starts, to
73 // ensure that we have usage statistics without a large delay.
75 {
76 public:
78 
79  ~PosixDiskIsolatorProcess() override;
80 
81  bool supportsNesting() override;
82  bool supportsStandalone() override;
83 
85  const std::vector<mesos::slave::ContainerState>& states,
86  const hashset<ContainerID>& orphans) override;
87 
89  const ContainerID& containerId,
90  const mesos::slave::ContainerConfig& containerConfig) override;
91 
93  const ContainerID& containerId,
94  pid_t pid) override;
95 
97  const ContainerID& containerId) override;
98 
100  const ContainerID& containerId,
101  const Resources& resources) override;
102 
104  const ContainerID& containerId) override;
105 
107  const ContainerID& containerId) override;
108 
109 private:
110  PosixDiskIsolatorProcess(const Flags& flags);
111 
113  const ContainerID& containerId,
114  const std::string& path);
115 
116  void _collect(
117  const ContainerID& containerId,
118  const std::string& path,
119  const process::Future<Bytes>& future);
120 
121  const Flags flags;
122  DiskUsageCollector collector;
123 
124  struct Info
125  {
126  explicit Info(const std::string& _directory)
127  : directories({_directory}), sandbox(_directory) {}
128 
129  Bytes ephemeralUsage() const;
130 
131  // Save the executor ephemeral storage (sandbox and rootfs)
132  // directories so that we know where to collect disk usage
133  // for disk resources without DiskInfo.
134  hashset<std::string> directories;
135 
136  std::string sandbox;
137 
139 
140  // The keys of the hashmaps contain the executor working directory
141  // above, and optionally paths of volumes used by the container.
142  // For each path, we maintain its quota and its last usage.
143  struct PathInfo
144  {
145  ~PathInfo();
146 
150  };
151 
153  };
154 
156 };
157 
158 } // namespace slave {
159 } // namespace internal {
160 } // namespace mesos {
161 
162 #endif // __POSIX_DISK_ISOLATOR_HPP__
Protocol< RecoverRequest, RecoverResponse > recover
Definition: path.hpp:29
Try< Nothing > isolate(const std::string &hierarchy, const std::string &cgroup, pid_t pid)
Try< bool > update(const std::string &link, const Handle &parent, uint16_t protocol, const action::Mirror &mirror)
Definition: check.hpp:33
process::Future< Bytes > usage(const std::string &path, const std::vector< std::string > &excludes)
process::Future< bool > cleanup(const std::string &hierarchy)
Definition: resources.hpp:83
std::string paths()
Definition: os.hpp:137
Definition: flags.hpp:39
Definition: duration.hpp:32
Future< std::vector< T > > collect(const std::vector< Future< T >> &futures)
Definition: collect.hpp:274
process::Future< Bytes > usage
Definition: disk.hpp:148
Definition: hashmap.hpp:38
DWORD pid_t
Definition: windows.hpp:181
Try< std::vector< Info > > infos(int familiy, int states)
Definition: agent.hpp:25
DiskUsageCollector(const Duration &interval)
#define flags
Definition: decoder.hpp:18
Definition: attributes.hpp:24
Definition: executor.hpp:48
Try< std::string > prepare(const std::string &baseHierarchy, const std::string &subsystem, const std::string &cgroup)
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
Definition: bytes.hpp:30
Definition: parse.hpp:33