]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/PurgeQueue.h
update source to 12.2.11
[ceph.git] / ceph / src / mds / PurgeQueue.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2015 Red Hat
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#ifndef PURGE_QUEUE_H_
16#define PURGE_QUEUE_H_
17
18#include "include/compact_set.h"
19#include "mds/MDSMap.h"
20#include "osdc/Journaler.h"
21
22
23/**
24 * Descriptor of the work associated with purging a file. We record
25 * the minimal amount of information from the inode such as the size
26 * and layout: all other un-needed inode metadata (times, permissions, etc)
27 * has been discarded.
28 */
29class PurgeItem
30{
31public:
32 enum Action : uint8_t {
33 NONE = 0,
34 PURGE_FILE = 1,
35 TRUNCATE_FILE,
36 PURGE_DIR
37 };
38
39 Action action;
40 inodeno_t ino;
41 uint64_t size;
42 file_layout_t layout;
43 compact_set<int64_t> old_pools;
44 SnapContext snapc;
45 fragtree_t fragtree;
46
47 PurgeItem()
48 : action(NONE), ino(0), size(0)
49 {}
50
51 void encode(bufferlist &bl) const;
52 void decode(bufferlist::iterator &p);
53};
54WRITE_CLASS_ENCODER(PurgeItem)
55
56enum {
57 l_pq_first = 3500,
58
59 // How many items have been finished by PurgeQueue
60 l_pq_executing_ops,
61 l_pq_executing,
62 l_pq_executed,
63 l_pq_last
64};
65
66/**
67 * A persistent queue of PurgeItems. This class both writes and reads
68 * to the queue. There is one of these per MDS rank.
69 *
70 * Note that this class does not take a reference to MDSRank: we are
71 * independent of all the metadata structures and do not need to
72 * take mds_lock for anything.
73 */
74class PurgeQueue
75{
76protected:
77 CephContext *cct;
78 const mds_rank_t rank;
79 Mutex lock;
f64942e4 80 bool readonly = false;
7c673cae
FG
81
82 int64_t metadata_pool;
83
84 // Don't use the MDSDaemon's Finisher and Timer, because this class
85 // operates outside of MDSDaemon::mds_lock
86 Finisher finisher;
87 SafeTimer timer;
88 Filer filer;
89 Objecter *objecter;
90 std::unique_ptr<PerfCounters> logger;
91
92 Journaler journaler;
93
94 Context *on_error;
95
96 // Map of Journaler offset to PurgeItem
97 std::map<uint64_t, PurgeItem> in_flight;
98
99 // Throttled allowances
100 uint64_t ops_in_flight;
101
102 // Dynamic op limit per MDS based on PG count
103 uint64_t max_purge_ops;
104
105 uint32_t _calculate_ops(const PurgeItem &item) const;
106
f64942e4 107 bool _can_consume();
7c673cae
FG
108
109 // How many bytes were remaining when drain() was first called,
110 // used for indicating progress.
111 uint64_t drain_initial;
112
113 // Has drain() ever been called on this instance?
114 bool draining;
115
116 // recover the journal write_pos (drop any partial written entry)
3efd9988 117 void _recover();
7c673cae
FG
118
119 /**
120 * @return true if we were in a position to try and consume something:
121 * does not mean we necessarily did.
122 */
123 bool _consume();
124
125 // Do we currently have a flush timer event waiting?
126 Context *delayed_flush;
127
128 void _execute_item(
129 const PurgeItem &item,
130 uint64_t expire_to);
131 void _execute_item_complete(
132 uint64_t expire_to);
133
3efd9988
FG
134 bool recovered;
135 std::list<Context*> waiting_for_recovery;
7c673cae 136
f64942e4
AA
137 void _go_readonly(int r);
138
7c673cae
FG
139public:
140 void init();
c07f9fc5 141 void activate();
7c673cae
FG
142 void shutdown();
143
144 void create_logger();
145
146 // Write an empty queue, use this during MDS rank creation
147 void create(Context *completion);
148
149 // Read the Journaler header for an existing queue and start consuming
150 void open(Context *completion);
151
3efd9988
FG
152 void wait_for_recovery(Context *c);
153
7c673cae
FG
154 // Submit one entry to the work queue. Call back when it is persisted
155 // to the queue (there is no callback for when it is executed)
156 void push(const PurgeItem &pi, Context *completion);
157
158 // If the on-disk queue is empty and we are not currently processing
159 // anything.
160 bool is_idle() const;
161
162 /**
163 * Signal to the PurgeQueue that you would like it to hurry up and
164 * finish consuming everything in the queue. Provides progress
165 * feedback.
166 *
167 * @param progress: bytes consumed since we started draining
168 * @param progress_total: max bytes that were outstanding during purge
169 * @param in_flight_count: number of file purges currently in flight
170 *
171 * @returns true if drain is complete
172 */
173 bool drain(
174 uint64_t *progress,
175 uint64_t *progress_total,
176 size_t *in_flight_count);
177
178 void update_op_limit(const MDSMap &mds_map);
179
180 void handle_conf_change(const struct md_config_t *conf,
181 const std::set <std::string> &changed,
182 const MDSMap &mds_map);
183
184 PurgeQueue(
185 CephContext *cct_,
186 mds_rank_t rank_,
187 const int64_t metadata_pool_,
188 Objecter *objecter_,
189 Context *on_error);
190 ~PurgeQueue();
191};
192
193
194#endif
195