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& resourceRequests,
68  const google::protobuf::Map<
69  std::string, Value::Scalar>& resourceLimits = {}) override;
70 
72  const ContainerID& containerId) override;
73 
75  const ContainerID& containerId) override;
76 
77 protected:
78  void initialize() override;
79 
80 private:
81  struct Info
82  {
83  struct PathInfo
84  {
86  const prid_t projectId;
88  };
89 
90  Info(const std::string& directory, prid_t projectId)
91  {
92  paths.put(directory, PathInfo{Bytes(0), projectId, None()});
93  }
94 
97  };
98 
99  struct ProjectRoots {
100  std::string deviceName;
101  hashset<std::string> directories;
102  };
103 
105  Duration watchInterval,
106  xfs::QuotaPolicy quotaPolicy,
107  const std::string& workDir,
108  const IntervalSet<prid_t>& projectIds,
109  Duration projectWatchInterval);
110 
111  // Responsible for validating a container hasn't broken the soft limit.
112  void check();
113 
114  // Take the next project ID from the unallocated pool.
115  Option<prid_t> nextProjectId();
116 
117  // Return this project ID to the unallocated pool.
118  void returnProjectId(prid_t projectId);
119 
120  // Check which project IDs are currently in use and deallocate the ones
121  // that are not.
122  void reclaimProjectIds();
123 
124  Try<Nothing> scheduleProjectRoot(
125  prid_t projectId, const std::string& rootDir);
126 
127  const Duration watchInterval;
128  const Duration projectWatchInterval;
129  xfs::QuotaPolicy quotaPolicy;
130  const std::string workDir;
131  const IntervalSet<prid_t> totalProjectIds;
132  IntervalSet<prid_t> freeProjectIds;
134 
135  // Track the device and filesystem path of unused project IDs we want
136  // to reclaim.
137  hashmap<prid_t, ProjectRoots> scheduledProjects;
138 
139  // Metrics used by the XFS disk isolator.
140  struct Metrics
141  {
142  Metrics();
143  ~Metrics();
144 
145  process::metrics::PushGauge project_ids_total;
146  process::metrics::PushGauge project_ids_free;
147  } metrics;
148 };
149 
150 } // namespace slave {
151 } // namespace internal {
152 } // namespace mesos {
153 
154 #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:138
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:87
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
process::Future< Nothing > update(const ContainerID &containerId, const Resources &resourceRequests, const google::protobuf::Map< std::string, Value::Scalar > &resourceLimits={}) 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()
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