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 
28 #include "slave/flags.hpp"
29 
31 
32 namespace mesos {
33 namespace internal {
34 namespace slave {
35 
36 // Forward declarations.
37 class DiskUsageCollectorProcess;
38 
39 
40 // Responsible for collecting disk usage for paths, while ensuring
41 // that an interval elapses between each collection.
43 {
44 public:
45  DiskUsageCollector(const Duration& interval);
47 
48  // Returns the disk usage rooted at 'path'. The user can discard the
49  // returned future to cancel the check.
51  const std::string& path,
52  const std::vector<std::string>& excludes);
53 
54 private:
55  DiskUsageCollectorProcess* process;
56 };
57 
58 
59 // This isolator monitors the disk usage for containers, and reports
60 // ContainerLimitation when a container exceeds its disk quota. This
61 // leverages the DiskUsageCollector to ensure that we don't induce too
62 // much CPU usage and disk caching effects from running 'du' too
63 // often.
64 //
65 // NOTE: Currently all containers are processed in the same queue,
66 // which means that when a container starts, it could take many disk
67 // collection intervals until any data is available in the resource
68 // usage statistics!
69 //
70 // TODO(jieyu): Consider handling each container independently, or
71 // triggering an initial collection when the container starts, to
72 // ensure that we have usage statistics without a large delay.
74 {
75 public:
77 
78  virtual ~PosixDiskIsolatorProcess();
79 
80  virtual bool supportsNesting();
81  virtual bool supportsStandalone();
82 
84  const std::list<mesos::slave::ContainerState>& states,
85  const hashset<ContainerID>& orphans);
86 
88  const ContainerID& containerId,
89  const mesos::slave::ContainerConfig& containerConfig);
90 
92  const ContainerID& containerId,
93  pid_t pid);
94 
96  const ContainerID& containerId);
97 
99  const ContainerID& containerId,
100  const Resources& resources);
101 
103  const ContainerID& containerId);
104 
106  const ContainerID& containerId);
107 
108 private:
109  PosixDiskIsolatorProcess(const Flags& flags);
110 
112  const ContainerID& containerId,
113  const std::string& path);
114 
115  void _collect(
116  const ContainerID& containerId,
117  const std::string& path,
118  const process::Future<Bytes>& future);
119 
120  const Flags flags;
121  DiskUsageCollector collector;
122 
123  struct Info
124  {
125  explicit Info(const std::string& _directory) : directory(_directory) {}
126 
127  // We save executor working directory here so that we know where
128  // to collect disk usage for disk resources without DiskInfo.
129  const std::string directory;
130 
132 
133  // The keys of the hashmaps contain the executor working directory
134  // above, and optionally paths of volumes used by the container.
135  // For each path, we maintain its quota and its last usage.
136  struct PathInfo
137  {
138  ~PathInfo();
139 
143  };
144 
146  };
147 
149 };
150 
151 } // namespace slave {
152 } // namespace internal {
153 } // namespace mesos {
154 
155 #endif // __POSIX_DISK_ISOLATOR_HPP__
Protocol< RecoverRequest, RecoverResponse > recover
Definition: path.hpp:26
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:79
std::string paths()
Definition: os.hpp:136
Definition: flags.hpp:39
Definition: duration.hpp:32
process::Future< Bytes > usage
Definition: disk.hpp:141
Definition: hashmap.hpp:38
DWORD pid_t
Definition: windows.hpp:187
Try< std::vector< Info > > infos(int familiy, int states)
Definition: spec.hpp:30
DiskUsageCollector(const Duration &interval)
#define flags
Definition: decoder.hpp:18
Definition: attributes.hpp:24
Definition: executor.hpp:47
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: parse.hpp:33
Future< std::list< T > > collect(const std::list< Future< T >> &futures)
Definition: collect.hpp:270