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 __XFS_DISK_ISOLATOR_HPP__
18 #define __XFS_DISK_ISOLATOR_HPP__
19 
20 #include <string>
21 #include <utility>
22 
23 #include <process/owned.hpp>
24 
26 
27 #include <stout/bytes.hpp>
28 #include <stout/duration.hpp>
29 #include <stout/hashmap.hpp>
30 #include <stout/hashset.hpp>
31 
32 #include "slave/flags.hpp"
33 
35 
37 
38 namespace mesos {
39 namespace internal {
40 namespace slave {
41 
43 {
44 public:
46 
47  ~XfsDiskIsolatorProcess() override;
48 
50  {
52  }
53 
55  const std::vector<mesos::slave::ContainerState>& states,
56  const hashset<ContainerID>& orphans) override;
57 
59  const ContainerID& containerId,
60  const mesos::slave::ContainerConfig& containerConfig) override;
61 
63  const ContainerID& containerId) override;
64 
66  const ContainerID& containerId,
67  const Resources& resources) override;
68 
70  const ContainerID& containerId) override;
71 
73  const ContainerID& containerId) override;
74 
75 protected:
76  void initialize() override;
77 
78 private:
79  struct Info
80  {
81  struct PathInfo
82  {
84  const prid_t projectId;
86  };
87 
88  Info(const std::string& directory, prid_t projectId)
89  {
90  paths.put(directory, PathInfo{Bytes(0), projectId, None()});
91  }
92 
95  };
96 
97  struct ProjectRoots {
98  std::string deviceName;
99  hashset<std::string> directories;
100  };
101 
103  Duration watchInterval,
104  xfs::QuotaPolicy quotaPolicy,
105  const std::string& workDir,
106  const IntervalSet<prid_t>& projectIds,
107  Duration projectWatchInterval);
108 
109  // Responsible for validating a container hasn't broken the soft limit.
110  void check();
111 
112  // Take the next project ID from the unallocated pool.
113  Option<prid_t> nextProjectId();
114 
115  // Return this project ID to the unallocated pool.
116  void returnProjectId(prid_t projectId);
117 
118  // Check which project IDs are currently in use and deallocate the ones
119  // that are not.
120  void reclaimProjectIds();
121 
122  Try<Nothing> scheduleProjectRoot(
123  prid_t projectId, const std::string& rootDir);
124 
125  const Duration watchInterval;
126  const Duration projectWatchInterval;
127  xfs::QuotaPolicy quotaPolicy;
128  const std::string workDir;
129  const IntervalSet<prid_t> totalProjectIds;
130  IntervalSet<prid_t> freeProjectIds;
132 
133  // Track the device and filesystem path of unused project IDs we want
134  // to reclaim.
135  hashmap<prid_t, ProjectRoots> scheduledProjects;
136 
137  // Metrics used by the XFS disk isolator.
138  struct Metrics
139  {
140  Metrics();
141  ~Metrics();
142 
143  process::metrics::PushGauge project_ids_total;
144  process::metrics::PushGauge project_ids_free;
145  } metrics;
146 };
147 
148 } // namespace slave {
149 } // namespace internal {
150 } // namespace mesos {
151 
152 #endif // __XFS_DISK_ISOLATOR_HPP__
process::Future< mesos::slave::ContainerLimitation > watch(const ContainerID &containerId) override
Definition: check.hpp:33
void initialize() override
Invoked when a process gets spawned.
Definition: resources.hpp:83
std::string paths()
Definition: os.hpp:137
Definition: flags.hpp:39
Definition: duration.hpp:32
process::Future< Option< mesos::slave::ContainerLaunchInfo > > prepare(const ContainerID &containerId, const mesos::slave::ContainerConfig &containerConfig) override
Definition: hashmap.hpp:38
const Option< Resource::DiskInfo > disk
Definition: disk.hpp:85
process::Future< Nothing > cleanup(const ContainerID &containerId) override
Definition: agent.hpp:25
static Try< mesos::slave::Isolator * > create(const Flags &flags)
process::Future< ResourceStatistics > usage(const ContainerID &containerId) override
QuotaPolicy
Definition: utils.hpp:79
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
Definition: none.hpp:27
Definition: attributes.hpp:24
JSON::Object Metrics()
process::Future< Nothing > update(const ContainerID &containerId, const Resources &resources) override
Definition: bytes.hpp:30
process::Future< Nothing > recover(const std::vector< mesos::slave::ContainerState > &states, const hashset< ContainerID > &orphans) override
Definition: parse.hpp:33
Definition: push_gauge.hpp:41