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 
31 #include "slave/flags.hpp"
32 
34 
36 
37 namespace mesos {
38 namespace internal {
39 namespace slave {
40 
42 {
43 public:
45 
46  ~XfsDiskIsolatorProcess() override;
47 
49  {
51  }
52 
54  const std::vector<mesos::slave::ContainerState>& states,
55  const hashset<ContainerID>& orphans) override;
56 
58  const ContainerID& containerId,
59  const mesos::slave::ContainerConfig& containerConfig) override;
60 
62  const ContainerID& containerId) override;
63 
65  const ContainerID& containerId,
66  const Resources& resources) override;
67 
69  const ContainerID& containerId) override;
70 
72  const ContainerID& containerId) override;
73 
74 protected:
75  void initialize() override;
76 
77 private:
78  struct Info
79  {
80  struct PathInfo
81  {
83  const prid_t projectId;
85  };
86 
87  Info(const std::string& directory, prid_t projectId)
88  {
89  paths.put(directory, PathInfo{Bytes(0), projectId, None()});
90  }
91 
94  };
95 
97  Duration watchInterval,
98  xfs::QuotaPolicy quotaPolicy,
99  const std::string& workDir,
100  const IntervalSet<prid_t>& projectIds,
101  Duration projectWatchInterval);
102 
103  // Responsible for validating a container hasn't broken the soft limit.
104  void check();
105 
106  // Take the next project ID from the unallocated pool.
107  Option<prid_t> nextProjectId();
108 
109  // Return this project ID to the unallocated pool.
110  void returnProjectId(prid_t projectId);
111 
112  // Check which project IDs are currently in use and deallocate the ones
113  // that are not.
114  void reclaimProjectIds();
115 
116  const Duration watchInterval;
117  const Duration projectWatchInterval;
118  xfs::QuotaPolicy quotaPolicy;
119  const std::string workDir;
120  const IntervalSet<prid_t> totalProjectIds;
121  IntervalSet<prid_t> freeProjectIds;
123 
124  // Track the device and filesystem path of unused project IDs we want
125  // to reclaim.
127 
128  // Metrics used by the XFS disk isolator.
129  struct Metrics
130  {
131  Metrics();
132  ~Metrics();
133 
134  process::metrics::PushGauge project_ids_total;
135  process::metrics::PushGauge project_ids_free;
136  } metrics;
137 };
138 
139 } // namespace slave {
140 } // namespace internal {
141 } // namespace mesos {
142 
143 #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:81
std::string paths()
Definition: os.hpp:136
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:84
process::Future< Nothing > cleanup(const ContainerID &containerId) override
Definition: spec.hpp:26
static Try< mesos::slave::Isolator * > create(const Flags &flags)
process::Future< ResourceStatistics > usage(const ContainerID &containerId) override
QuotaPolicy
Definition: utils.hpp:73
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:279
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