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:
49  : ProcessBase(process::ID::generate("agent-garbage-collector")),
50  metrics(this) {}
51 
52  virtual ~GarbageCollectorProcess();
53 
55  const Duration& d,
56  const std::string& path);
57 
58  process::Future<bool> unschedule(const std::string& path);
59 
60  void prune(const Duration& d);
61 
62 private:
63  void reset();
64 
65  void remove(const process::Timeout& removalTime);
66 
67  struct PathInfo
68  {
69  PathInfo(const std::string& _path)
70  : path(_path) {}
71 
72  bool operator==(const PathInfo& that) const
73  {
74  return path == that.path;
75  }
76 
77  const std::string path;
78 
79  // This promise tracks the scheduled gc for the path.
81 
82  bool removing = false;
83  };
84 
85  // Callback for `remove` for bookkeeping after path removal.
86  void _remove(
87  const process::Future<Nothing>& result,
89 
90  struct Metrics
91  {
92  explicit Metrics(GarbageCollectorProcess *gc);
93  ~Metrics();
94 
95  process::metrics::Counter path_removals_succeeded;
96  process::metrics::Counter path_removals_failed;
97  process::metrics::Gauge path_removals_pending;
98  } metrics;
99 
100  // Store all the timeouts and corresponding paths to delete.
101  // NOTE: We are using Multimap here instead of Multihashmap, because
102  // we need the keys of the map (deletion time) to be sorted.
104 
105  // We also need efficient lookup for a path, to determine whether
106  // it exists in our paths mapping.
108 
109  process::Timer timer;
110 
111  // For executing path removals in a separate actor.
112  process::Executor executor;
113 };
114 
115 } // namespace slave {
116 } // namespace internal {
117 } // namespace mesos {
118 
119 #endif // __SLAVE_GC_PROCESS_HPP__
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
Definition: gauge.hpp:27
Try< std::vector< Info > > infos(int familiy, int states)
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)
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
Definition: timeout.hpp:24
Definition: timer.hpp:30
JSON::Object Metrics()
Definition: owned.hpp:35
Definition: executor.hpp:29
Definition: process.hpp:493
GarbageCollectorProcess()
Definition: gc_process.hpp:48