Apache Mesos
gc_process.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 __SLAVE_GC_PROCESS_HPP__
18 #define __SLAVE_GC_PROCESS_HPP__
19 
20 #include <list>
21 #include <string>
22 
23 #include <process/executor.hpp>
24 #include <process/future.hpp>
25 #include <process/id.hpp>
26 #include <process/owned.hpp>
27 #include <process/process.hpp>
28 #include <process/timeout.hpp>
29 #include <process/timer.hpp>
30 
33 
34 #include <stout/duration.hpp>
35 #include <stout/hashmap.hpp>
36 #include <stout/multimap.hpp>
37 #include <stout/nothing.hpp>
38 #include <stout/try.hpp>
39 
40 namespace mesos {
41 namespace internal {
42 namespace slave {
43 
45  public process::Process<GarbageCollectorProcess>
46 {
47 public:
48  explicit GarbageCollectorProcess(const std::string& _workDir)
49  : ProcessBase(process::ID::generate("agent-garbage-collector")),
50  metrics(this),
51  workDir(_workDir) {}
52 
53  ~GarbageCollectorProcess() override;
54 
56  const Duration& d,
57  const std::string& path);
58 
59  process::Future<bool> unschedule(const std::string& path);
60 
61  void prune(const Duration& d);
62 
63 private:
64  void reset();
65 
66  void remove(const process::Timeout& removalTime);
67 
68  struct PathInfo
69  {
70  PathInfo(const std::string& _path)
71  : path(_path) {}
72 
73  bool operator==(const PathInfo& that) const
74  {
75  return path == that.path;
76  }
77 
78  const std::string path;
79 
80  // This promise tracks the scheduled gc for the path.
82 
83  bool removing = false;
84  };
85 
86  // Callback for `remove` for bookkeeping after path removal.
87  void _remove(
88  const process::Future<Nothing>& result,
90 
91  struct Metrics
92  {
93  explicit Metrics(GarbageCollectorProcess *gc);
94  ~Metrics();
95 
96  process::metrics::Counter path_removals_succeeded;
97  process::metrics::Counter path_removals_failed;
98  process::metrics::PullGauge path_removals_pending;
99  } metrics;
100 
101  const std::string workDir;
102 
103  // Store all the timeouts and corresponding paths to delete.
104  // NOTE: We are using Multimap here instead of Multihashmap, because
105  // we need the keys of the map (deletion time) to be sorted.
107 
108  // We also need efficient lookup for a path, to determine whether
109  // it exists in our paths mapping.
111 
112  process::Timer timer;
113 
114  // For executing path removals in a separate actor.
115  process::Executor executor;
116 };
117 
118 } // namespace slave {
119 } // namespace internal {
120 } // namespace mesos {
121 
122 #endif // __SLAVE_GC_PROCESS_HPP__
Definition: path.hpp:29
std::string generate(const std::string &prefix="")
Returns &#39;prefix(N)&#39; where N represents the number of instances where the same prefix (wrt...
bool operator==(const DockerVolume &left, const DockerVolume &right)
Definition: state.hpp:29
ProcessBase(const std::string &id="")
process::Future< bool > unschedule(const std::string &path)
Definition: duration.hpp:32
Definition: counter.hpp:26
GarbageCollectorProcess(const std::string &_workDir)
Definition: gc_process.hpp:48
Definition: pull_gauge.hpp:46
Try< std::vector< Info > > infos(int familiy, int states)
Definition: agent.hpp:25
Protocol< PromiseRequest, PromiseResponse > promise
Definition: multimap.hpp:30
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
process::Future< Nothing > schedule(const Duration &d, const std::string &path)
Definition: attributes.hpp:24
Definition: timeout.hpp:24
Definition: timer.hpp:30
Definition: executor.hpp:48
JSON::Object Metrics()
Definition: owned.hpp:36
Definition: executor.hpp:29
Definition: process.hpp:505