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& resourceRequests,
102  const google::protobuf::Map<
103  std::string, Value::Scalar>& resourceLimits = {}) override;
104 
106  const ContainerID& containerId) override;
107 
109  const ContainerID& containerId) override;
110 
111 private:
112  PosixDiskIsolatorProcess(const Flags& flags);
113 
115  const ContainerID& containerId,
116  const std::string& path);
117 
118  void _collect(
119  const ContainerID& containerId,
120  const std::string& path,
121  const process::Future<Bytes>& future);
122 
123  const Flags flags;
124  DiskUsageCollector collector;
125 
126  struct Info
127  {
128  explicit Info(const std::string& _directory)
129  : directories({_directory}), sandbox(_directory) {}
130 
131  Bytes ephemeralUsage() const;
132 
133  // Save the executor ephemeral storage (sandbox and rootfs)
134  // directories so that we know where to collect disk usage
135  // for disk resources without DiskInfo.
136  hashset<std::string> directories;
137 
138  std::string sandbox;
139 
141 
142  // The keys of the hashmaps contain the executor working directory
143  // above, and optionally paths of volumes used by the container.
144  // For each path, we maintain its quota and its last usage.
145  struct PathInfo
146  {
147  ~PathInfo();
148 
152  };
153 
155  };
156 
158 };
159 
160 } // namespace slave {
161 } // namespace internal {
162 } // namespace mesos {
163 
164 #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:138
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:150
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