1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 Red Hat
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.
15 #ifndef PURGE_QUEUE_H_
16 #define PURGE_QUEUE_H_
18 #include "include/compact_set.h"
19 #include "mds/MDSMap.h"
20 #include "osdc/Journaler.h"
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)
32 enum Action
: uint8_t {
40 //None PurgeItem serves as NoOp for splicing out journal entries;
41 //so there has to be a "pad_size" to specify the size of journal
42 //space to be spliced.
48 compact_set
<int64_t> old_pools
;
53 : pad_size(0), action(NONE
), ino(0), size(0)
56 void encode(bufferlist
&bl
) const;
57 void decode(bufferlist::const_iterator
&p
);
59 static Action
str_to_type(std::string_view str
) {
60 return PurgeItem::actions
.at(std::string(str
));
63 void dump(Formatter
*f
) const
65 f
->dump_int("action", action
);
66 f
->dump_int("ino", ino
);
67 f
->dump_int("size", size
);
68 f
->open_object_section("layout");
71 f
->open_object_section("SnapContext");
74 f
->open_object_section("fragtree");
79 std::string_view
get_type_str() const;
81 static const std::map
<std::string
, PurgeItem::Action
> actions
;
83 WRITE_CLASS_ENCODER(PurgeItem
)
88 // How many items have been finished by PurgeQueue
90 l_pq_executing_ops_high_water
,
92 l_pq_executing_high_water
,
98 * A persistent queue of PurgeItems. This class both writes and reads
99 * to the queue. There is one of these per MDS rank.
101 * Note that this class does not take a reference to MDSRank: we are
102 * independent of all the metadata structures and do not need to
103 * take mds_lock for anything.
109 const mds_rank_t rank
;
111 bool readonly
= false;
113 int64_t metadata_pool
;
115 // Don't use the MDSDaemon's Finisher and Timer, because this class
116 // operates outside of MDSDaemon::mds_lock
121 std::unique_ptr
<PerfCounters
> logger
;
127 // Map of Journaler offset to PurgeItem
128 std::map
<uint64_t, PurgeItem
> in_flight
;
130 std::set
<uint64_t> pending_expire
;
132 // Throttled allowances
133 uint64_t ops_in_flight
;
135 // Dynamic op limit per MDS based on PG count
136 uint64_t max_purge_ops
;
138 uint32_t _calculate_ops(const PurgeItem
&item
) const;
142 // How many bytes were remaining when drain() was first called,
143 // used for indicating progress.
144 uint64_t drain_initial
;
146 // Has drain() ever been called on this instance?
149 // recover the journal write_pos (drop any partial written entry)
153 * @return true if we were in a position to try and consume something:
154 * does not mean we necessarily did.
158 // Do we currently have a flush timer event waiting?
159 Context
*delayed_flush
;
162 const PurgeItem
&item
,
164 void _execute_item_complete(
168 std::list
<Context
*> waiting_for_recovery
;
170 void _go_readonly(int r
);
172 uint64_t ops_high_water
= 0;
173 uint64_t files_high_water
= 0;
180 void create_logger();
182 // Write an empty queue, use this during MDS rank creation
183 void create(Context
*completion
);
185 // Read the Journaler header for an existing queue and start consuming
186 void open(Context
*completion
);
188 void wait_for_recovery(Context
*c
);
190 // Submit one entry to the work queue. Call back when it is persisted
191 // to the queue (there is no callback for when it is executed)
192 void push(const PurgeItem
&pi
, Context
*completion
);
194 // If the on-disk queue is empty and we are not currently processing
196 bool is_idle() const;
199 * Signal to the PurgeQueue that you would like it to hurry up and
200 * finish consuming everything in the queue. Provides progress
203 * @param progress: bytes consumed since we started draining
204 * @param progress_total: max bytes that were outstanding during purge
205 * @param in_flight_count: number of file purges currently in flight
207 * @returns true if drain is complete
211 uint64_t *progress_total
,
212 size_t *in_flight_count
);
214 void update_op_limit(const MDSMap
&mds_map
);
216 void handle_conf_change(const std::set
<std::string
>& changed
, const MDSMap
& mds_map
);
221 const int64_t metadata_pool_
,