]>
Commit | Line | Data |
---|---|---|
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 | ||
11fdf7f2 | 15 | #include <string_view> |
f67539c2 | 16 | #include <typeinfo> |
7c673cae FG |
17 | #include "common/debug.h" |
18 | #include "common/errno.h" | |
a4b75251 | 19 | #include "common/likely.h" |
f67539c2 | 20 | #include "common/async/blocked_completion.h" |
7c673cae FG |
21 | |
22 | #include "messages/MClientRequestForward.h" | |
23 | #include "messages/MMDSLoadTargets.h" | |
7c673cae | 24 | #include "messages/MMDSTableRequest.h" |
f67539c2 | 25 | #include "messages/MMDSMetrics.h" |
7c673cae | 26 | |
9f95a23c TL |
27 | #include "mgr/MgrClient.h" |
28 | ||
7c673cae FG |
29 | #include "MDSDaemon.h" |
30 | #include "MDSMap.h" | |
f67539c2 | 31 | #include "MetricAggregator.h" |
7c673cae FG |
32 | #include "SnapClient.h" |
33 | #include "SnapServer.h" | |
34 | #include "MDBalancer.h" | |
91327a77 | 35 | #include "Migrator.h" |
7c673cae | 36 | #include "Locker.h" |
7c673cae FG |
37 | #include "InoTable.h" |
38 | #include "mon/MonClient.h" | |
39 | #include "common/HeartbeatMap.h" | |
40 | #include "ScrubStack.h" | |
41 | ||
42 | ||
43 | #include "MDSRank.h" | |
44 | ||
45 | #define dout_context g_ceph_context | |
46 | #define dout_subsys ceph_subsys_mds | |
47 | #undef dout_prefix | |
48 | #define dout_prefix *_dout << "mds." << whoami << '.' << incarnation << ' ' | |
20effc67 TL |
49 | |
50 | using std::ostream; | |
51 | using std::set; | |
52 | using std::string; | |
53 | using std::vector; | |
9f95a23c | 54 | using TOPNSPC::common::cmd_getval; |
20effc67 | 55 | |
f64942e4 AA |
56 | class C_Flush_Journal : public MDSInternalContext { |
57 | public: | |
58 | C_Flush_Journal(MDCache *mdcache, MDLog *mdlog, MDSRank *mds, | |
59 | std::ostream *ss, Context *on_finish) | |
60 | : MDSInternalContext(mds), | |
61 | mdcache(mdcache), mdlog(mdlog), ss(ss), on_finish(on_finish), | |
62 | whoami(mds->whoami), incarnation(mds->incarnation) { | |
63 | } | |
64 | ||
65 | void send() { | |
20effc67 | 66 | ceph_assert(ceph_mutex_is_locked(mds->mds_lock)); |
f64942e4 AA |
67 | |
68 | dout(20) << __func__ << dendl; | |
69 | ||
70 | if (mdcache->is_readonly()) { | |
71 | dout(5) << __func__ << ": read-only FS" << dendl; | |
f67539c2 | 72 | complete(-CEPHFS_EROFS); |
f64942e4 AA |
73 | return; |
74 | } | |
75 | ||
76 | if (!mds->is_active()) { | |
77 | dout(5) << __func__ << ": MDS not active, no-op" << dendl; | |
78 | complete(0); | |
79 | return; | |
80 | } | |
81 | ||
82 | flush_mdlog(); | |
83 | } | |
84 | ||
85 | private: | |
86 | ||
87 | void flush_mdlog() { | |
88 | dout(20) << __func__ << dendl; | |
89 | ||
90 | // I need to seal off the current segment, and then mark all | |
91 | // previous segments for expiry | |
92 | mdlog->start_new_segment(); | |
93 | ||
9f95a23c | 94 | Context *ctx = new LambdaContext([this](int r) { |
f64942e4 AA |
95 | handle_flush_mdlog(r); |
96 | }); | |
97 | ||
98 | // Flush initially so that all the segments older than our new one | |
99 | // will be elegible for expiry | |
100 | mdlog->flush(); | |
101 | mdlog->wait_for_safe(new MDSInternalContextWrapper(mds, ctx)); | |
102 | } | |
103 | ||
104 | void handle_flush_mdlog(int r) { | |
105 | dout(20) << __func__ << ": r=" << r << dendl; | |
106 | ||
107 | if (r != 0) { | |
108 | *ss << "Error " << r << " (" << cpp_strerror(r) << ") while flushing journal"; | |
109 | complete(r); | |
110 | return; | |
111 | } | |
112 | ||
113 | clear_mdlog(); | |
114 | } | |
115 | ||
116 | void clear_mdlog() { | |
117 | dout(20) << __func__ << dendl; | |
118 | ||
9f95a23c | 119 | Context *ctx = new LambdaContext([this](int r) { |
f64942e4 AA |
120 | handle_clear_mdlog(r); |
121 | }); | |
122 | ||
123 | // Because we may not be the last wait_for_safe context on MDLog, | |
124 | // and subsequent contexts might wake up in the middle of our | |
125 | // later trim_all and interfere with expiry (by e.g. marking | |
126 | // dirs/dentries dirty on previous log segments), we run a second | |
127 | // wait_for_safe here. See #10368 | |
128 | mdlog->wait_for_safe(new MDSInternalContextWrapper(mds, ctx)); | |
129 | } | |
130 | ||
131 | void handle_clear_mdlog(int r) { | |
132 | dout(20) << __func__ << ": r=" << r << dendl; | |
133 | ||
134 | if (r != 0) { | |
135 | *ss << "Error " << r << " (" << cpp_strerror(r) << ") while flushing journal"; | |
136 | complete(r); | |
137 | return; | |
138 | } | |
139 | ||
140 | trim_mdlog(); | |
141 | } | |
142 | ||
143 | void trim_mdlog() { | |
144 | // Put all the old log segments into expiring or expired state | |
145 | dout(5) << __func__ << ": beginning segment expiry" << dendl; | |
146 | ||
147 | int ret = mdlog->trim_all(); | |
148 | if (ret != 0) { | |
149 | *ss << "Error " << ret << " (" << cpp_strerror(ret) << ") while trimming log"; | |
150 | complete(ret); | |
151 | return; | |
152 | } | |
153 | ||
154 | expire_segments(); | |
155 | } | |
156 | ||
157 | void expire_segments() { | |
158 | dout(20) << __func__ << dendl; | |
159 | ||
160 | // Attach contexts to wait for all expiring segments to expire | |
f91f0fd5 | 161 | MDSGatherBuilder expiry_gather(g_ceph_context); |
f64942e4 AA |
162 | |
163 | const auto &expiring_segments = mdlog->get_expiring_segments(); | |
164 | for (auto p : expiring_segments) { | |
f91f0fd5 | 165 | p->wait_for_expiry(expiry_gather.new_sub()); |
f64942e4 | 166 | } |
f91f0fd5 | 167 | dout(5) << __func__ << ": waiting for " << expiry_gather.num_subs_created() |
f64942e4 AA |
168 | << " segments to expire" << dendl; |
169 | ||
f91f0fd5 | 170 | if (!expiry_gather.has_subs()) { |
f64942e4 | 171 | trim_segments(); |
f64942e4 AA |
172 | return; |
173 | } | |
174 | ||
9f95a23c | 175 | Context *ctx = new LambdaContext([this](int r) { |
f64942e4 AA |
176 | handle_expire_segments(r); |
177 | }); | |
f91f0fd5 TL |
178 | expiry_gather.set_finisher(new MDSInternalContextWrapper(mds, ctx)); |
179 | expiry_gather.activate(); | |
f64942e4 AA |
180 | } |
181 | ||
182 | void handle_expire_segments(int r) { | |
183 | dout(20) << __func__ << ": r=" << r << dendl; | |
184 | ||
185 | ceph_assert(r == 0); // MDLog is not allowed to raise errors via | |
186 | // wait_for_expiry | |
187 | trim_segments(); | |
188 | } | |
189 | ||
190 | void trim_segments() { | |
191 | dout(20) << __func__ << dendl; | |
192 | ||
9f95a23c | 193 | Context *ctx = new C_OnFinisher(new LambdaContext([this](int) { |
11fdf7f2 | 194 | std::lock_guard locker(mds->mds_lock); |
f64942e4 AA |
195 | trim_expired_segments(); |
196 | }), mds->finisher); | |
197 | ctx->complete(0); | |
198 | } | |
199 | ||
200 | void trim_expired_segments() { | |
201 | dout(5) << __func__ << ": expiry complete, expire_pos/trim_pos is now " | |
202 | << std::hex << mdlog->get_journaler()->get_expire_pos() << "/" | |
203 | << mdlog->get_journaler()->get_trimmed_pos() << dendl; | |
204 | ||
205 | // Now everyone I'm interested in is expired | |
206 | mdlog->trim_expired_segments(); | |
207 | ||
208 | dout(5) << __func__ << ": trim complete, expire_pos/trim_pos is now " | |
209 | << std::hex << mdlog->get_journaler()->get_expire_pos() << "/" | |
210 | << mdlog->get_journaler()->get_trimmed_pos() << dendl; | |
211 | ||
212 | write_journal_head(); | |
213 | } | |
214 | ||
215 | void write_journal_head() { | |
216 | dout(20) << __func__ << dendl; | |
217 | ||
9f95a23c | 218 | Context *ctx = new LambdaContext([this](int r) { |
11fdf7f2 | 219 | std::lock_guard locker(mds->mds_lock); |
f64942e4 AA |
220 | handle_write_head(r); |
221 | }); | |
222 | // Flush the journal header so that readers will start from after | |
223 | // the flushed region | |
224 | mdlog->get_journaler()->write_head(ctx); | |
225 | } | |
226 | ||
227 | void handle_write_head(int r) { | |
228 | if (r != 0) { | |
229 | *ss << "Error " << r << " (" << cpp_strerror(r) << ") while writing header"; | |
230 | } else { | |
231 | dout(5) << __func__ << ": write_head complete, all done!" << dendl; | |
232 | } | |
233 | ||
234 | complete(r); | |
235 | } | |
236 | ||
237 | void finish(int r) override { | |
238 | dout(20) << __func__ << ": r=" << r << dendl; | |
239 | on_finish->complete(r); | |
240 | } | |
241 | ||
242 | MDCache *mdcache; | |
243 | MDLog *mdlog; | |
244 | std::ostream *ss; | |
245 | Context *on_finish; | |
246 | ||
247 | // so as to use dout | |
248 | mds_rank_t whoami; | |
249 | int incarnation; | |
250 | }; | |
251 | ||
252 | class C_Drop_Cache : public MDSInternalContext { | |
253 | public: | |
254 | C_Drop_Cache(Server *server, MDCache *mdcache, MDLog *mdlog, | |
255 | MDSRank *mds, uint64_t recall_timeout, | |
256 | Formatter *f, Context *on_finish) | |
257 | : MDSInternalContext(mds), | |
258 | server(server), mdcache(mdcache), mdlog(mdlog), | |
a8e16298 TL |
259 | recall_timeout(recall_timeout), recall_start(mono_clock::now()), |
260 | f(f), on_finish(on_finish), | |
f64942e4 AA |
261 | whoami(mds->whoami), incarnation(mds->incarnation) { |
262 | } | |
263 | ||
264 | void send() { | |
265 | // not really a hard requirement here, but lets ensure this in | |
266 | // case we change the logic here. | |
20effc67 | 267 | ceph_assert(ceph_mutex_is_locked(mds->mds_lock)); |
f64942e4 AA |
268 | |
269 | dout(20) << __func__ << dendl; | |
a8e16298 | 270 | f->open_object_section("result"); |
f64942e4 AA |
271 | recall_client_state(); |
272 | } | |
273 | ||
274 | private: | |
f67539c2 | 275 | // context which completes itself (with -CEPHFS_ETIMEDOUT) after a specified |
f64942e4 AA |
276 | // timeout or when explicitly completed, whichever comes first. Note |
277 | // that the context does not detroy itself after completion -- it | |
278 | // needs to be explicitly freed. | |
279 | class C_ContextTimeout : public MDSInternalContext { | |
280 | public: | |
281 | C_ContextTimeout(MDSRank *mds, uint64_t timeout, Context *on_finish) | |
282 | : MDSInternalContext(mds), | |
283 | timeout(timeout), | |
f64942e4 AA |
284 | on_finish(on_finish) { |
285 | } | |
286 | ~C_ContextTimeout() { | |
287 | ceph_assert(timer_task == nullptr); | |
288 | } | |
289 | ||
290 | void start_timer() { | |
291 | if (!timeout) { | |
292 | return; | |
293 | } | |
294 | ||
9f95a23c | 295 | timer_task = new LambdaContext([this](int) { |
f64942e4 | 296 | timer_task = nullptr; |
f67539c2 | 297 | complete(-CEPHFS_ETIMEDOUT); |
f64942e4 AA |
298 | }); |
299 | mds->timer.add_event_after(timeout, timer_task); | |
300 | } | |
301 | ||
302 | void finish(int r) override { | |
303 | Context *ctx = nullptr; | |
304 | { | |
11fdf7f2 | 305 | std::lock_guard locker(lock); |
f64942e4 AA |
306 | std::swap(on_finish, ctx); |
307 | } | |
308 | if (ctx != nullptr) { | |
309 | ctx->complete(r); | |
310 | } | |
311 | } | |
312 | void complete(int r) override { | |
313 | if (timer_task != nullptr) { | |
314 | mds->timer.cancel_event(timer_task); | |
315 | } | |
316 | ||
317 | finish(r); | |
318 | } | |
319 | ||
320 | uint64_t timeout; | |
9f95a23c | 321 | ceph::mutex lock = ceph::make_mutex("mds::context::timeout"); |
f64942e4 AA |
322 | Context *on_finish = nullptr; |
323 | Context *timer_task = nullptr; | |
324 | }; | |
325 | ||
11fdf7f2 TL |
326 | auto do_trim() { |
327 | auto [throttled, count] = mdcache->trim(UINT64_MAX); | |
328 | dout(10) << __func__ | |
329 | << (throttled ? " (throttled)" : "") | |
330 | << " trimmed " << count << " caps" << dendl; | |
331 | dentries_trimmed += count; | |
332 | return std::make_pair(throttled, count); | |
333 | } | |
334 | ||
f64942e4 AA |
335 | void recall_client_state() { |
336 | dout(20) << __func__ << dendl; | |
a8e16298 TL |
337 | auto now = mono_clock::now(); |
338 | auto duration = std::chrono::duration<double>(now-recall_start).count(); | |
f64942e4 | 339 | |
f91f0fd5 | 340 | MDSGatherBuilder gather(g_ceph_context); |
92f5a8d4 | 341 | auto flags = Server::RecallFlags::STEADY|Server::RecallFlags::TRIM; |
f91f0fd5 | 342 | auto [throttled, count] = server->recall_client_state(&gather, flags); |
a8e16298 TL |
343 | dout(10) << __func__ |
344 | << (throttled ? " (throttled)" : "") | |
345 | << " recalled " << count << " caps" << dendl; | |
346 | ||
347 | caps_recalled += count; | |
348 | if ((throttled || count > 0) && (recall_timeout == 0 || duration < recall_timeout)) { | |
11fdf7f2 | 349 | C_ContextTimeout *ctx = new C_ContextTimeout( |
9f95a23c | 350 | mds, 1, new LambdaContext([this](int r) { |
11fdf7f2 TL |
351 | recall_client_state(); |
352 | })); | |
353 | ctx->start_timer(); | |
f91f0fd5 TL |
354 | gather.set_finisher(new MDSInternalContextWrapper(mds, ctx)); |
355 | gather.activate(); | |
11fdf7f2 TL |
356 | mdlog->flush(); /* use down-time to incrementally flush log */ |
357 | do_trim(); /* use down-time to incrementally trim cache */ | |
a8e16298 | 358 | } else { |
f91f0fd5 | 359 | if (!gather.has_subs()) { |
a8e16298 TL |
360 | return handle_recall_client_state(0); |
361 | } else if (recall_timeout > 0 && duration > recall_timeout) { | |
f91f0fd5 TL |
362 | gather.set_finisher(new C_MDSInternalNoop); |
363 | gather.activate(); | |
f67539c2 | 364 | return handle_recall_client_state(-CEPHFS_ETIMEDOUT); |
a8e16298 TL |
365 | } else { |
366 | uint64_t remaining = (recall_timeout == 0 ? 0 : recall_timeout-duration); | |
367 | C_ContextTimeout *ctx = new C_ContextTimeout( | |
9f95a23c | 368 | mds, remaining, new LambdaContext([this](int r) { |
a8e16298 TL |
369 | handle_recall_client_state(r); |
370 | })); | |
371 | ||
372 | ctx->start_timer(); | |
f91f0fd5 TL |
373 | gather.set_finisher(new MDSInternalContextWrapper(mds, ctx)); |
374 | gather.activate(); | |
a8e16298 | 375 | } |
f64942e4 | 376 | } |
f64942e4 AA |
377 | } |
378 | ||
379 | void handle_recall_client_state(int r) { | |
380 | dout(20) << __func__ << ": r=" << r << dendl; | |
381 | ||
382 | // client recall section | |
383 | f->open_object_section("client_recall"); | |
384 | f->dump_int("return_code", r); | |
385 | f->dump_string("message", cpp_strerror(r)); | |
a8e16298 | 386 | f->dump_int("recalled", caps_recalled); |
f64942e4 AA |
387 | f->close_section(); |
388 | ||
389 | // we can still continue after recall timeout | |
f64942e4 AA |
390 | flush_journal(); |
391 | } | |
392 | ||
393 | void flush_journal() { | |
394 | dout(20) << __func__ << dendl; | |
395 | ||
9f95a23c | 396 | Context *ctx = new LambdaContext([this](int r) { |
f64942e4 AA |
397 | handle_flush_journal(r); |
398 | }); | |
399 | ||
400 | C_Flush_Journal *flush_journal = new C_Flush_Journal(mdcache, mdlog, mds, &ss, ctx); | |
401 | flush_journal->send(); | |
402 | } | |
403 | ||
404 | void handle_flush_journal(int r) { | |
405 | dout(20) << __func__ << ": r=" << r << dendl; | |
406 | ||
407 | if (r != 0) { | |
408 | cmd_err(f, ss.str()); | |
409 | complete(r); | |
410 | return; | |
411 | } | |
412 | ||
413 | // journal flush section | |
414 | f->open_object_section("flush_journal"); | |
415 | f->dump_int("return_code", r); | |
416 | f->dump_string("message", ss.str()); | |
417 | f->close_section(); | |
418 | ||
a8e16298 TL |
419 | trim_cache(); |
420 | } | |
421 | ||
422 | void trim_cache() { | |
423 | dout(20) << __func__ << dendl; | |
424 | ||
11fdf7f2 | 425 | auto [throttled, count] = do_trim(); |
a8e16298 | 426 | if (throttled && count > 0) { |
9f95a23c | 427 | auto timer = new LambdaContext([this](int) { |
a8e16298 TL |
428 | trim_cache(); |
429 | }); | |
430 | mds->timer.add_event_after(1.0, timer); | |
431 | } else { | |
432 | cache_status(); | |
433 | } | |
f64942e4 AA |
434 | } |
435 | ||
436 | void cache_status() { | |
437 | dout(20) << __func__ << dendl; | |
438 | ||
a8e16298 TL |
439 | f->open_object_section("trim_cache"); |
440 | f->dump_int("trimmed", dentries_trimmed); | |
441 | f->close_section(); | |
442 | ||
f64942e4 AA |
443 | // cache status section |
444 | mdcache->cache_status(f); | |
f64942e4 AA |
445 | |
446 | complete(0); | |
447 | } | |
448 | ||
449 | void finish(int r) override { | |
450 | dout(20) << __func__ << ": r=" << r << dendl; | |
451 | ||
a8e16298 TL |
452 | auto d = std::chrono::duration<double>(mono_clock::now()-recall_start); |
453 | f->dump_float("duration", d.count()); | |
454 | ||
455 | f->close_section(); | |
f64942e4 AA |
456 | on_finish->complete(r); |
457 | } | |
458 | ||
459 | Server *server; | |
460 | MDCache *mdcache; | |
461 | MDLog *mdlog; | |
462 | uint64_t recall_timeout; | |
a8e16298 | 463 | mono_time recall_start; |
f64942e4 AA |
464 | Formatter *f; |
465 | Context *on_finish; | |
466 | ||
467 | int retval = 0; | |
468 | std::stringstream ss; | |
a8e16298 TL |
469 | uint64_t caps_recalled = 0; |
470 | uint64_t dentries_trimmed = 0; | |
f64942e4 AA |
471 | |
472 | // so as to use dout | |
473 | mds_rank_t whoami; | |
474 | int incarnation; | |
475 | ||
11fdf7f2 | 476 | void cmd_err(Formatter *f, std::string_view err) { |
f64942e4 AA |
477 | f->reset(); |
478 | f->open_object_section("result"); | |
479 | f->dump_string("error", err); | |
480 | f->close_section(); | |
481 | } | |
482 | }; | |
483 | ||
7c673cae FG |
484 | MDSRank::MDSRank( |
485 | mds_rank_t whoami_, | |
a4b75251 | 486 | ceph::fair_mutex &mds_lock_, |
7c673cae | 487 | LogChannelRef &clog_, |
a4b75251 | 488 | CommonSafeTimer<ceph::fair_mutex> &timer_, |
7c673cae | 489 | Beacon &beacon_, |
11fdf7f2 | 490 | std::unique_ptr<MDSMap>& mdsmap_, |
7c673cae FG |
491 | Messenger *msgr, |
492 | MonClient *monc_, | |
9f95a23c | 493 | MgrClient *mgrc, |
7c673cae | 494 | Context *respawn_hook_, |
f67539c2 TL |
495 | Context *suicide_hook_, |
496 | boost::asio::io_context& ioc) : | |
9f95a23c TL |
497 | cct(msgr->cct), mds_lock(mds_lock_), clog(clog_), |
498 | timer(timer_), mdsmap(mdsmap_), | |
f67539c2 | 499 | objecter(new Objecter(g_ceph_context, msgr, monc_, ioc)), |
9f95a23c | 500 | damage_table(whoami_), sessionmap(this), |
11fdf7f2 TL |
501 | op_tracker(g_ceph_context, g_conf()->mds_enable_op_tracker, |
502 | g_conf()->osd_num_op_tracker_shard), | |
20effc67 | 503 | progress_thread(this), whoami(whoami_), |
7c673cae FG |
504 | purge_queue(g_ceph_context, whoami_, |
505 | mdsmap_->get_metadata_pool(), objecter, | |
9f95a23c TL |
506 | new LambdaContext([this](int r) { |
507 | std::lock_guard l(mds_lock); | |
508 | handle_write_error(r); | |
509 | } | |
7c673cae FG |
510 | ) |
511 | ), | |
f67539c2 | 512 | metrics_handler(cct, this), |
9f95a23c TL |
513 | beacon(beacon_), |
514 | messenger(msgr), monc(monc_), mgrc(mgrc), | |
7c673cae FG |
515 | respawn_hook(respawn_hook_), |
516 | suicide_hook(suicide_hook_), | |
1e59de90 | 517 | inject_journal_corrupt_dentry_first(g_conf().get_val<double>("mds_inject_journal_corrupt_dentry_first")), |
f67539c2 TL |
518 | starttime(mono_clock::now()), |
519 | ioc(ioc) | |
7c673cae FG |
520 | { |
521 | hb = g_ceph_context->get_heartbeat_map()->add_worker("MDSRank", pthread_self()); | |
522 | ||
b3b6e05e TL |
523 | // The metadata pool won't change in the whole life time |
524 | // of the fs, with this we can get rid of the mds_lock | |
525 | // in many places too. | |
526 | metadata_pool = mdsmap->get_metadata_pool(); | |
527 | ||
7c673cae FG |
528 | purge_queue.update_op_limit(*mdsmap); |
529 | ||
9f95a23c | 530 | objecter->unset_honor_pool_full(); |
7c673cae | 531 | |
9f95a23c | 532 | finisher = new Finisher(cct, "MDSRank", "MR_Finisher"); |
7c673cae FG |
533 | |
534 | mdcache = new MDCache(this, purge_queue); | |
535 | mdlog = new MDLog(this); | |
536 | balancer = new MDBalancer(this, messenger, monc); | |
537 | ||
9f95a23c | 538 | scrubstack = new ScrubStack(mdcache, clog, finisher); |
7c673cae FG |
539 | |
540 | inotable = new InoTable(this); | |
541 | snapserver = new SnapServer(this, monc); | |
542 | snapclient = new SnapClient(this); | |
543 | ||
f67539c2 | 544 | server = new Server(this, &metrics_handler); |
7c673cae FG |
545 | locker = new Locker(this, mdcache); |
546 | ||
33c7a0ef | 547 | _heartbeat_reset_grace = g_conf().get_val<uint64_t>("mds_heartbeat_reset_grace"); |
f67539c2 | 548 | heartbeat_grace = g_conf().get_val<double>("mds_heartbeat_grace"); |
b32b8144 FG |
549 | op_tracker.set_complaint_and_threshold(cct->_conf->mds_op_complaint_time, |
550 | cct->_conf->mds_op_log_threshold); | |
551 | op_tracker.set_history_size_and_duration(cct->_conf->mds_op_history_size, | |
552 | cct->_conf->mds_op_history_duration); | |
9f95a23c TL |
553 | |
554 | schedule_update_timer_task(); | |
7c673cae FG |
555 | } |
556 | ||
557 | MDSRank::~MDSRank() | |
558 | { | |
559 | if (hb) { | |
560 | g_ceph_context->get_heartbeat_map()->remove_worker(hb); | |
20effc67 | 561 | hb = nullptr; |
7c673cae FG |
562 | } |
563 | ||
564 | if (scrubstack) { delete scrubstack; scrubstack = NULL; } | |
565 | if (mdcache) { delete mdcache; mdcache = NULL; } | |
566 | if (mdlog) { delete mdlog; mdlog = NULL; } | |
567 | if (balancer) { delete balancer; balancer = NULL; } | |
568 | if (inotable) { delete inotable; inotable = NULL; } | |
569 | if (snapserver) { delete snapserver; snapserver = NULL; } | |
570 | if (snapclient) { delete snapclient; snapclient = NULL; } | |
7c673cae FG |
571 | |
572 | if (server) { delete server; server = 0; } | |
573 | if (locker) { delete locker; locker = 0; } | |
574 | ||
575 | if (logger) { | |
576 | g_ceph_context->get_perfcounters_collection()->remove(logger); | |
577 | delete logger; | |
578 | logger = 0; | |
579 | } | |
580 | if (mlogger) { | |
581 | g_ceph_context->get_perfcounters_collection()->remove(mlogger); | |
582 | delete mlogger; | |
583 | mlogger = 0; | |
584 | } | |
585 | ||
586 | delete finisher; | |
587 | finisher = NULL; | |
588 | ||
589 | delete suicide_hook; | |
590 | suicide_hook = NULL; | |
591 | ||
592 | delete respawn_hook; | |
593 | respawn_hook = NULL; | |
594 | ||
595 | delete objecter; | |
596 | objecter = nullptr; | |
597 | } | |
598 | ||
599 | void MDSRankDispatcher::init() | |
600 | { | |
601 | objecter->init(); | |
602 | messenger->add_dispatcher_head(objecter); | |
603 | ||
604 | objecter->start(); | |
605 | ||
606 | update_log_config(); | |
607 | create_logger(); | |
608 | ||
609 | // Expose the OSDMap (already populated during MDS::init) to anyone | |
610 | // who is interested in it. | |
611 | handle_osd_map(); | |
612 | ||
613 | progress_thread.create("mds_rank_progr"); | |
614 | ||
615 | purge_queue.init(); | |
616 | ||
617 | finisher->start(); | |
618 | } | |
619 | ||
11fdf7f2 | 620 | void MDSRank::update_targets() |
7c673cae FG |
621 | { |
622 | // get MonMap's idea of my export_targets | |
623 | const set<mds_rank_t>& map_targets = mdsmap->get_mds_info(get_nodeid()).export_targets; | |
624 | ||
625 | dout(20) << "updating export targets, currently " << map_targets.size() << " ranks are targets" << dendl; | |
626 | ||
627 | bool send = false; | |
628 | set<mds_rank_t> new_map_targets; | |
629 | ||
630 | auto it = export_targets.begin(); | |
631 | while (it != export_targets.end()) { | |
632 | mds_rank_t rank = it->first; | |
11fdf7f2 TL |
633 | auto &counter = it->second; |
634 | dout(20) << "export target mds." << rank << " is " << counter << dendl; | |
7c673cae | 635 | |
11fdf7f2 | 636 | double val = counter.get(); |
7c673cae FG |
637 | if (val <= 0.01) { |
638 | dout(15) << "export target mds." << rank << " is no longer an export target" << dendl; | |
639 | export_targets.erase(it++); | |
640 | send = true; | |
641 | continue; | |
642 | } | |
643 | if (!map_targets.count(rank)) { | |
644 | dout(15) << "export target mds." << rank << " not in map's export_targets" << dendl; | |
645 | send = true; | |
646 | } | |
647 | new_map_targets.insert(rank); | |
648 | it++; | |
649 | } | |
650 | if (new_map_targets.size() < map_targets.size()) { | |
651 | dout(15) << "export target map holds stale targets, sending update" << dendl; | |
652 | send = true; | |
653 | } | |
654 | ||
655 | if (send) { | |
656 | dout(15) << "updating export_targets, now " << new_map_targets.size() << " ranks are targets" << dendl; | |
9f95a23c | 657 | auto m = make_message<MMDSLoadTargets>(mds_gid_t(monc->get_global_id()), new_map_targets); |
11fdf7f2 | 658 | monc->send_mon_message(m.detach()); |
7c673cae FG |
659 | } |
660 | } | |
661 | ||
11fdf7f2 | 662 | void MDSRank::hit_export_target(mds_rank_t rank, double amount) |
7c673cae | 663 | { |
11fdf7f2 | 664 | double rate = g_conf()->mds_bal_target_decay; |
7c673cae | 665 | if (amount < 0.0) { |
11fdf7f2 | 666 | amount = 100.0/g_conf()->mds_bal_target_decay; /* a good default for "i am trying to keep this export_target active" */ |
7c673cae | 667 | } |
11fdf7f2 TL |
668 | auto em = export_targets.emplace(std::piecewise_construct, std::forward_as_tuple(rank), std::forward_as_tuple(DecayRate(rate))); |
669 | auto &counter = em.first->second; | |
670 | counter.hit(amount); | |
7c673cae | 671 | if (em.second) { |
11fdf7f2 TL |
672 | dout(15) << "hit export target (new) is " << counter << dendl; |
673 | } else { | |
674 | dout(15) << "hit export target is " << counter << dendl; | |
675 | } | |
676 | } | |
677 | ||
678 | class C_MDS_MonCommand : public MDSInternalContext { | |
679 | std::string cmd; | |
680 | public: | |
681 | std::string outs; | |
682 | C_MDS_MonCommand(MDSRank *m, std::string_view c) | |
683 | : MDSInternalContext(m), cmd(c) {} | |
684 | void finish(int r) override { | |
685 | mds->_mon_command_finish(r, cmd, outs); | |
686 | } | |
687 | }; | |
688 | ||
689 | void MDSRank::_mon_command_finish(int r, std::string_view cmd, std::string_view outs) | |
690 | { | |
691 | if (r < 0) { | |
692 | dout(0) << __func__ << ": mon command " << cmd << " failed with errno " << r | |
693 | << " (" << outs << ")" << dendl; | |
7c673cae | 694 | } else { |
11fdf7f2 | 695 | dout(1) << __func__ << ": mon command " << cmd << " succeed" << dendl; |
7c673cae | 696 | } |
11fdf7f2 TL |
697 | } |
698 | ||
699 | void MDSRank::set_mdsmap_multimds_snaps_allowed() | |
700 | { | |
701 | static bool already_sent = false; | |
702 | if (already_sent) | |
703 | return; | |
704 | ||
f67539c2 TL |
705 | CachedStackStringStream css; |
706 | *css << "{\"prefix\":\"fs set\", \"fs_name\":\"" << mdsmap->get_fs_name() << "\", "; | |
707 | *css << "\"var\":\"allow_multimds_snaps\", \"val\":\"true\", "; | |
708 | *css << "\"confirm\":\"--yes-i-am-really-a-mds\"}"; | |
709 | std::vector<std::string> cmd = {css->str()}; | |
11fdf7f2 TL |
710 | |
711 | dout(0) << __func__ << ": sending mon command: " << cmd[0] << dendl; | |
712 | ||
713 | C_MDS_MonCommand *fin = new C_MDS_MonCommand(this, cmd[0]); | |
714 | monc->start_mon_command(cmd, {}, nullptr, &fin->outs, new C_IO_Wrapper(this, fin)); | |
715 | ||
716 | already_sent = true; | |
717 | } | |
718 | ||
7c673cae FG |
719 | void MDSRankDispatcher::tick() |
720 | { | |
721 | heartbeat_reset(); | |
722 | ||
723 | if (beacon.is_laggy()) { | |
91327a77 | 724 | dout(1) << "skipping upkeep work because connection to Monitors appears laggy" << dendl; |
7c673cae FG |
725 | return; |
726 | } | |
727 | ||
728 | check_ops_in_flight(); | |
729 | ||
730 | // Wake up thread in case we use to be laggy and have waiting_for_nolaggy | |
731 | // messages to progress. | |
732 | progress_thread.signal(); | |
733 | ||
734 | // make sure mds log flushes, trims periodically | |
735 | mdlog->flush(); | |
736 | ||
91327a77 AA |
737 | // update average session uptime |
738 | sessionmap.update_average_session_age(); | |
739 | ||
7c673cae | 740 | if (is_active() || is_stopping()) { |
7c673cae FG |
741 | mdlog->trim(); // NOT during recovery! |
742 | } | |
743 | ||
7c673cae | 744 | // ... |
b3b6e05e | 745 | if (is_clientreplay() || is_active() || is_stopping()) { |
7c673cae | 746 | server->find_idle_sessions(); |
91327a77 | 747 | server->evict_cap_revoke_non_responders(); |
7c673cae FG |
748 | locker->tick(); |
749 | } | |
750 | ||
11fdf7f2 TL |
751 | // log |
752 | if (logger) { | |
753 | logger->set(l_mds_subtrees, mdcache->num_subtrees()); | |
754 | mdcache->log_stat(); | |
755 | } | |
756 | ||
7c673cae FG |
757 | if (is_reconnect()) |
758 | server->reconnect_tick(); | |
759 | ||
760 | if (is_active()) { | |
761 | balancer->tick(); | |
762 | mdcache->find_stale_fragment_freeze(); | |
763 | mdcache->migrator->find_stale_export_freeze(); | |
11fdf7f2 TL |
764 | |
765 | if (mdsmap->get_tableserver() == whoami) { | |
7c673cae | 766 | snapserver->check_osd_map(false); |
11fdf7f2 TL |
767 | // Filesystem was created by pre-mimic mds. Allow multi-active mds after |
768 | // all old snapshots are deleted. | |
769 | if (!mdsmap->allows_multimds_snaps() && | |
770 | snapserver->can_allow_multimds_snaps()) { | |
771 | set_mdsmap_multimds_snaps_allowed(); | |
772 | } | |
773 | } | |
f67539c2 TL |
774 | |
775 | if (whoami == 0) | |
776 | scrubstack->advance_scrub_status(); | |
7c673cae FG |
777 | } |
778 | ||
779 | if (is_active() || is_stopping()) { | |
11fdf7f2 | 780 | update_targets(); |
7c673cae FG |
781 | } |
782 | ||
783 | // shut down? | |
784 | if (is_stopping()) { | |
785 | mdlog->trim(); | |
786 | if (mdcache->shutdown_pass()) { | |
787 | uint64_t pq_progress = 0 ; | |
788 | uint64_t pq_total = 0; | |
789 | size_t pq_in_flight = 0; | |
790 | if (!purge_queue.drain(&pq_progress, &pq_total, &pq_in_flight)) { | |
791 | dout(7) << "shutdown_pass=true, but still waiting for purge queue" | |
792 | << dendl; | |
793 | // This takes unbounded time, so we must indicate progress | |
794 | // to the administrator: we do it in a slightly imperfect way | |
795 | // by sending periodic (tick frequency) clog messages while | |
796 | // in this state. | |
797 | clog->info() << "MDS rank " << whoami << " waiting for purge queue (" | |
798 | << std::dec << pq_progress << "/" << pq_total << " " << pq_in_flight | |
799 | << " files purging" << ")"; | |
800 | } else { | |
801 | dout(7) << "shutdown_pass=true, finished w/ shutdown, moving to " | |
802 | "down:stopped" << dendl; | |
803 | stopping_done(); | |
804 | } | |
805 | } | |
806 | else { | |
807 | dout(7) << "shutdown_pass=false" << dendl; | |
808 | } | |
809 | } | |
810 | ||
811 | // Expose ourselves to Beacon to update health indicators | |
812 | beacon.notify_health(this); | |
813 | } | |
814 | ||
815 | void MDSRankDispatcher::shutdown() | |
816 | { | |
817 | // It should never be possible for shutdown to get called twice, because | |
818 | // anyone picking up mds_lock checks if stopping is true and drops | |
819 | // out if it is. | |
11fdf7f2 | 820 | ceph_assert(stopping == false); |
7c673cae FG |
821 | stopping = true; |
822 | ||
823 | dout(1) << __func__ << ": shutting down rank " << whoami << dendl; | |
824 | ||
92f5a8d4 TL |
825 | g_conf().remove_observer(this); |
826 | ||
7c673cae FG |
827 | timer.shutdown(); |
828 | ||
829 | // MDLog has to shut down before the finisher, because some of its | |
830 | // threads block on IOs that require finisher to complete. | |
831 | mdlog->shutdown(); | |
832 | ||
833 | // shut down cache | |
834 | mdcache->shutdown(); | |
835 | ||
836 | purge_queue.shutdown(); | |
837 | ||
f67539c2 TL |
838 | // shutdown metrics handler/updater -- this is ok even if it was not |
839 | // inited. | |
840 | metrics_handler.shutdown(); | |
841 | ||
842 | // shutdown metric aggergator | |
843 | if (metric_aggregator != nullptr) { | |
844 | metric_aggregator->shutdown(); | |
845 | } | |
846 | ||
9f95a23c | 847 | mds_lock.unlock(); |
7c673cae | 848 | finisher->stop(); // no flushing |
9f95a23c | 849 | mds_lock.lock(); |
7c673cae | 850 | |
31f18b77 | 851 | if (objecter->initialized) |
7c673cae FG |
852 | objecter->shutdown(); |
853 | ||
854 | monc->shutdown(); | |
855 | ||
856 | op_tracker.on_shutdown(); | |
857 | ||
858 | progress_thread.shutdown(); | |
859 | ||
860 | // release mds_lock for finisher/messenger threads (e.g. | |
861 | // MDSDaemon::ms_handle_reset called from Messenger). | |
9f95a23c | 862 | mds_lock.unlock(); |
7c673cae FG |
863 | |
864 | // shut down messenger | |
865 | messenger->shutdown(); | |
866 | ||
9f95a23c | 867 | mds_lock.lock(); |
7c673cae FG |
868 | |
869 | // Workaround unclean shutdown: HeartbeatMap will assert if | |
870 | // worker is not removed (as we do in ~MDS), but ~MDS is not | |
871 | // always called after suicide. | |
872 | if (hb) { | |
873 | g_ceph_context->get_heartbeat_map()->remove_worker(hb); | |
874 | hb = NULL; | |
875 | } | |
876 | } | |
877 | ||
878 | /** | |
879 | * Helper for simple callbacks that call a void fn with no args. | |
880 | */ | |
881 | class C_MDS_VoidFn : public MDSInternalContext | |
882 | { | |
883 | typedef void (MDSRank::*fn_ptr)(); | |
884 | protected: | |
885 | fn_ptr fn; | |
886 | public: | |
887 | C_MDS_VoidFn(MDSRank *mds_, fn_ptr fn_) | |
888 | : MDSInternalContext(mds_), fn(fn_) | |
889 | { | |
11fdf7f2 TL |
890 | ceph_assert(mds_); |
891 | ceph_assert(fn_); | |
7c673cae FG |
892 | } |
893 | ||
894 | void finish(int r) override | |
895 | { | |
896 | (mds->*fn)(); | |
897 | } | |
898 | }; | |
899 | ||
7c673cae FG |
900 | MDSTableClient *MDSRank::get_table_client(int t) |
901 | { | |
902 | switch (t) { | |
903 | case TABLE_ANCHOR: return NULL; | |
904 | case TABLE_SNAP: return snapclient; | |
905 | default: ceph_abort(); | |
906 | } | |
907 | } | |
908 | ||
909 | MDSTableServer *MDSRank::get_table_server(int t) | |
910 | { | |
911 | switch (t) { | |
912 | case TABLE_ANCHOR: return NULL; | |
913 | case TABLE_SNAP: return snapserver; | |
914 | default: ceph_abort(); | |
915 | } | |
916 | } | |
917 | ||
918 | void MDSRank::suicide() | |
919 | { | |
920 | if (suicide_hook) { | |
921 | suicide_hook->complete(0); | |
922 | suicide_hook = NULL; | |
923 | } | |
924 | } | |
925 | ||
926 | void MDSRank::respawn() | |
927 | { | |
928 | if (respawn_hook) { | |
929 | respawn_hook->complete(0); | |
930 | respawn_hook = NULL; | |
931 | } | |
932 | } | |
933 | ||
934 | void MDSRank::damaged() | |
935 | { | |
11fdf7f2 | 936 | ceph_assert(whoami != MDS_RANK_NONE); |
9f95a23c | 937 | ceph_assert(ceph_mutex_is_locked_by_me(mds_lock)); |
7c673cae | 938 | |
11fdf7f2 | 939 | beacon.set_want_state(*mdsmap, MDSMap::STATE_DAMAGED); |
7c673cae FG |
940 | monc->flush_log(); // Flush any clog error from before we were called |
941 | beacon.notify_health(this); // Include latest status in our swan song | |
11fdf7f2 | 942 | beacon.send_and_wait(g_conf()->mds_mon_shutdown_timeout); |
7c673cae FG |
943 | |
944 | // It's okay if we timed out and the mon didn't get our beacon, because | |
945 | // another daemon (or ourselves after respawn) will eventually take the | |
946 | // rank and report DAMAGED again when it hits same problem we did. | |
947 | ||
948 | respawn(); // Respawn into standby in case mon has other work for us | |
949 | } | |
950 | ||
951 | void MDSRank::damaged_unlocked() | |
952 | { | |
11fdf7f2 | 953 | std::lock_guard l(mds_lock); |
7c673cae FG |
954 | damaged(); |
955 | } | |
956 | ||
957 | void MDSRank::handle_write_error(int err) | |
958 | { | |
f67539c2 TL |
959 | if (err == -CEPHFS_EBLOCKLISTED) { |
960 | derr << "we have been blocklisted (fenced), respawning..." << dendl; | |
7c673cae FG |
961 | respawn(); |
962 | return; | |
963 | } | |
964 | ||
11fdf7f2 | 965 | if (g_conf()->mds_action_on_write_error >= 2) { |
7c673cae FG |
966 | derr << "unhandled write error " << cpp_strerror(err) << ", suicide..." << dendl; |
967 | respawn(); | |
11fdf7f2 | 968 | } else if (g_conf()->mds_action_on_write_error == 1) { |
7c673cae FG |
969 | derr << "unhandled write error " << cpp_strerror(err) << ", force readonly..." << dendl; |
970 | mdcache->force_readonly(); | |
971 | } else { | |
972 | // ignore; | |
973 | derr << "unhandled write error " << cpp_strerror(err) << ", ignore..." << dendl; | |
974 | } | |
975 | } | |
976 | ||
f67539c2 TL |
977 | void MDSRank::handle_write_error_with_lock(int err) |
978 | { | |
979 | std::scoped_lock l(mds_lock); | |
980 | handle_write_error(err); | |
981 | } | |
982 | ||
7c673cae FG |
983 | void *MDSRank::ProgressThread::entry() |
984 | { | |
9f95a23c | 985 | std::unique_lock l(mds->mds_lock); |
7c673cae | 986 | while (true) { |
9f95a23c TL |
987 | cond.wait(l, [this] { |
988 | return (mds->stopping || | |
989 | !mds->finished_queue.empty() || | |
990 | (!mds->waiting_for_nolaggy.empty() && !mds->beacon.is_laggy())); | |
991 | }); | |
7c673cae FG |
992 | |
993 | if (mds->stopping) { | |
994 | break; | |
995 | } | |
996 | ||
997 | mds->_advance_queues(); | |
998 | } | |
999 | ||
1000 | return NULL; | |
1001 | } | |
1002 | ||
1003 | ||
1004 | void MDSRank::ProgressThread::shutdown() | |
1005 | { | |
9f95a23c | 1006 | ceph_assert(ceph_mutex_is_locked_by_me(mds->mds_lock)); |
11fdf7f2 | 1007 | ceph_assert(mds->stopping); |
7c673cae FG |
1008 | |
1009 | if (am_self()) { | |
1010 | // Stopping is set, we will fall out of our main loop naturally | |
1011 | } else { | |
1012 | // Kick the thread to notice mds->stopping, and join it | |
9f95a23c TL |
1013 | cond.notify_all(); |
1014 | mds->mds_lock.unlock(); | |
7c673cae FG |
1015 | if (is_started()) |
1016 | join(); | |
9f95a23c | 1017 | mds->mds_lock.lock(); |
7c673cae FG |
1018 | } |
1019 | } | |
1020 | ||
9f95a23c | 1021 | bool MDSRankDispatcher::ms_dispatch(const cref_t<Message> &m) |
7c673cae | 1022 | { |
f67539c2 TL |
1023 | if (m->get_source().is_mds()) { |
1024 | const Message *msg = m.get(); | |
1025 | const MMDSOp *op = dynamic_cast<const MMDSOp*>(msg); | |
1026 | if (!op) | |
1027 | dout(0) << typeid(*msg).name() << " is not an MMDSOp type" << dendl; | |
1028 | ceph_assert(op); | |
1029 | } | |
1030 | else if (m->get_source().is_client()) { | |
11fdf7f2 | 1031 | Session *session = static_cast<Session*>(m->get_connection()->get_priv().get()); |
f64942e4 AA |
1032 | if (session) |
1033 | session->last_seen = Session::clock::now(); | |
1034 | } | |
1035 | ||
7c673cae | 1036 | inc_dispatch_depth(); |
f64942e4 | 1037 | bool ret = _dispatch(m, true); |
7c673cae FG |
1038 | dec_dispatch_depth(); |
1039 | return ret; | |
1040 | } | |
1041 | ||
9f95a23c | 1042 | bool MDSRank::_dispatch(const cref_t<Message> &m, bool new_msg) |
7c673cae FG |
1043 | { |
1044 | if (is_stale_message(m)) { | |
7c673cae FG |
1045 | return true; |
1046 | } | |
f6b5b4d7 TL |
1047 | // do not proceed if this message cannot be handled |
1048 | if (!is_valid_message(m)) { | |
1049 | return false; | |
1050 | } | |
7c673cae FG |
1051 | |
1052 | if (beacon.is_laggy()) { | |
91327a77 | 1053 | dout(5) << " laggy, deferring " << *m << dendl; |
7c673cae FG |
1054 | waiting_for_nolaggy.push_back(m); |
1055 | } else if (new_msg && !waiting_for_nolaggy.empty()) { | |
91327a77 | 1056 | dout(5) << " there are deferred messages, deferring " << *m << dendl; |
7c673cae FG |
1057 | waiting_for_nolaggy.push_back(m); |
1058 | } else { | |
f6b5b4d7 | 1059 | handle_message(m); |
7c673cae FG |
1060 | heartbeat_reset(); |
1061 | } | |
1062 | ||
1063 | if (dispatch_depth > 1) | |
1064 | return true; | |
1065 | ||
1066 | // finish any triggered contexts | |
1067 | _advance_queues(); | |
1068 | ||
1069 | if (beacon.is_laggy()) { | |
1070 | // We've gone laggy during dispatch, don't do any | |
1071 | // more housekeeping | |
1072 | return true; | |
1073 | } | |
1074 | ||
7c673cae FG |
1075 | // hack: thrash exports |
1076 | static utime_t start; | |
1077 | utime_t now = ceph_clock_now(); | |
1078 | if (start == utime_t()) | |
1079 | start = now; | |
1080 | /*double el = now - start; | |
1081 | if (el > 30.0 && | |
1082 | el < 60.0)*/ | |
11fdf7f2 | 1083 | for (int i=0; i<g_conf()->mds_thrash_exports; i++) { |
7c673cae FG |
1084 | set<mds_rank_t> s; |
1085 | if (!is_active()) break; | |
1086 | mdsmap->get_mds_set(s, MDSMap::STATE_ACTIVE); | |
1087 | if (s.size() < 2 || CInode::count() < 10) | |
1088 | break; // need peers for this to work. | |
11fdf7f2 TL |
1089 | if (mdcache->migrator->get_num_exporting() > g_conf()->mds_thrash_exports * 5 || |
1090 | mdcache->migrator->get_export_queue_size() > g_conf()->mds_thrash_exports * 10) | |
7c673cae FG |
1091 | break; |
1092 | ||
11fdf7f2 | 1093 | dout(7) << "mds thrashing exports pass " << (i+1) << "/" << g_conf()->mds_thrash_exports << dendl; |
7c673cae FG |
1094 | |
1095 | // pick a random dir inode | |
1096 | CInode *in = mdcache->hack_pick_random_inode(); | |
1097 | ||
9f95a23c | 1098 | auto&& ls = in->get_dirfrags(); |
7c673cae | 1099 | if (!ls.empty()) { // must be an open dir. |
9f95a23c | 1100 | const auto& dir = ls[rand() % ls.size()]; |
7c673cae FG |
1101 | if (!dir->get_parent_dir()) continue; // must be linked. |
1102 | if (!dir->is_auth()) continue; // must be auth. | |
1103 | ||
1104 | mds_rank_t dest; | |
1105 | do { | |
1106 | int k = rand() % s.size(); | |
1107 | set<mds_rank_t>::iterator p = s.begin(); | |
1108 | while (k--) ++p; | |
1109 | dest = *p; | |
1110 | } while (dest == whoami); | |
1111 | mdcache->migrator->export_dir_nicely(dir,dest); | |
1112 | } | |
1113 | } | |
1114 | // hack: thrash fragments | |
11fdf7f2 | 1115 | for (int i=0; i<g_conf()->mds_thrash_fragments; i++) { |
7c673cae | 1116 | if (!is_active()) break; |
11fdf7f2 TL |
1117 | if (mdcache->get_num_fragmenting_dirs() > 5 * g_conf()->mds_thrash_fragments) break; |
1118 | dout(7) << "mds thrashing fragments pass " << (i+1) << "/" << g_conf()->mds_thrash_fragments << dendl; | |
7c673cae FG |
1119 | |
1120 | // pick a random dir inode | |
1121 | CInode *in = mdcache->hack_pick_random_inode(); | |
1122 | ||
9f95a23c | 1123 | auto&& ls = in->get_dirfrags(); |
7c673cae FG |
1124 | if (ls.empty()) continue; // must be an open dir. |
1125 | CDir *dir = ls.front(); | |
1126 | if (!dir->get_parent_dir()) continue; // must be linked. | |
1127 | if (!dir->is_auth()) continue; // must be auth. | |
1128 | frag_t fg = dir->get_frag(); | |
11fdf7f2 TL |
1129 | if ((fg == frag_t() || (rand() % (1 << fg.bits()) == 0))) { |
1130 | mdcache->split_dir(dir, 1); | |
1131 | } else { | |
1132 | balancer->queue_merge(dir); | |
7c673cae FG |
1133 | } |
1134 | } | |
1135 | ||
1136 | // hack: force hash root? | |
1137 | /* | |
1138 | if (false && | |
1139 | mdcache->get_root() && | |
1140 | mdcache->get_root()->dir && | |
1141 | !(mdcache->get_root()->dir->is_hashed() || | |
1142 | mdcache->get_root()->dir->is_hashing())) { | |
1143 | dout(0) << "hashing root" << dendl; | |
1144 | mdcache->migrator->hash_dir(mdcache->get_root()->dir); | |
1145 | } | |
1146 | */ | |
1147 | ||
c07f9fc5 FG |
1148 | update_mlogger(); |
1149 | return true; | |
1150 | } | |
1151 | ||
1152 | void MDSRank::update_mlogger() | |
1153 | { | |
7c673cae FG |
1154 | if (mlogger) { |
1155 | mlogger->set(l_mdm_ino, CInode::count()); | |
1156 | mlogger->set(l_mdm_dir, CDir::count()); | |
1157 | mlogger->set(l_mdm_dn, CDentry::count()); | |
1158 | mlogger->set(l_mdm_cap, Capability::count()); | |
7c673cae FG |
1159 | mlogger->set(l_mdm_inoa, CInode::increments()); |
1160 | mlogger->set(l_mdm_inos, CInode::decrements()); | |
1161 | mlogger->set(l_mdm_dira, CDir::increments()); | |
1162 | mlogger->set(l_mdm_dirs, CDir::decrements()); | |
1163 | mlogger->set(l_mdm_dna, CDentry::increments()); | |
1164 | mlogger->set(l_mdm_dns, CDentry::decrements()); | |
1165 | mlogger->set(l_mdm_capa, Capability::increments()); | |
1166 | mlogger->set(l_mdm_caps, Capability::decrements()); | |
7c673cae | 1167 | } |
7c673cae FG |
1168 | } |
1169 | ||
f6b5b4d7 TL |
1170 | // message types that the mds can handle |
1171 | bool MDSRank::is_valid_message(const cref_t<Message> &m) { | |
1172 | int port = m->get_type() & 0xff00; | |
1173 | int type = m->get_type(); | |
1174 | ||
1175 | if (port == MDS_PORT_CACHE || | |
1176 | port == MDS_PORT_MIGRATOR || | |
1177 | type == CEPH_MSG_CLIENT_SESSION || | |
1178 | type == CEPH_MSG_CLIENT_RECONNECT || | |
1179 | type == CEPH_MSG_CLIENT_RECLAIM || | |
1180 | type == CEPH_MSG_CLIENT_REQUEST || | |
f67539c2 | 1181 | type == MSG_MDS_PEER_REQUEST || |
f6b5b4d7 TL |
1182 | type == MSG_MDS_HEARTBEAT || |
1183 | type == MSG_MDS_TABLE_REQUEST || | |
1184 | type == MSG_MDS_LOCK || | |
1185 | type == MSG_MDS_INODEFILECAPS || | |
f67539c2 TL |
1186 | type == MSG_MDS_SCRUB || |
1187 | type == MSG_MDS_SCRUB_STATS || | |
f6b5b4d7 TL |
1188 | type == CEPH_MSG_CLIENT_CAPS || |
1189 | type == CEPH_MSG_CLIENT_CAPRELEASE || | |
1190 | type == CEPH_MSG_CLIENT_LEASE) { | |
1191 | return true; | |
1192 | } | |
1193 | ||
1194 | return false; | |
1195 | } | |
1196 | ||
7c673cae FG |
1197 | /* |
1198 | * lower priority messages we defer if we seem laggy | |
1199 | */ | |
f6b5b4d7 TL |
1200 | |
1201 | #define ALLOW_MESSAGES_FROM(peers) \ | |
1202 | do { \ | |
1203 | if (m->get_connection() && (m->get_connection()->get_peer_type() & (peers)) == 0) { \ | |
1204 | dout(0) << __FILE__ << "." << __LINE__ << ": filtered out request, peer=" << m->get_connection()->get_peer_type() \ | |
1205 | << " allowing=" << #peers << " message=" << *m << dendl; \ | |
1206 | return; \ | |
1207 | } \ | |
1208 | } while (0) | |
1209 | ||
1210 | void MDSRank::handle_message(const cref_t<Message> &m) | |
7c673cae FG |
1211 | { |
1212 | int port = m->get_type() & 0xff00; | |
1213 | ||
1214 | switch (port) { | |
1215 | case MDS_PORT_CACHE: | |
1216 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MDS); | |
1217 | mdcache->dispatch(m); | |
1218 | break; | |
1219 | ||
1220 | case MDS_PORT_MIGRATOR: | |
1221 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MDS); | |
1222 | mdcache->migrator->dispatch(m); | |
1223 | break; | |
1224 | ||
1225 | default: | |
1226 | switch (m->get_type()) { | |
1227 | // SERVER | |
1228 | case CEPH_MSG_CLIENT_SESSION: | |
1229 | case CEPH_MSG_CLIENT_RECONNECT: | |
11fdf7f2 | 1230 | case CEPH_MSG_CLIENT_RECLAIM: |
7c673cae FG |
1231 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_CLIENT); |
1232 | // fall-thru | |
1233 | case CEPH_MSG_CLIENT_REQUEST: | |
1234 | server->dispatch(m); | |
1235 | break; | |
f67539c2 | 1236 | case MSG_MDS_PEER_REQUEST: |
7c673cae FG |
1237 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MDS); |
1238 | server->dispatch(m); | |
1239 | break; | |
1240 | ||
1241 | case MSG_MDS_HEARTBEAT: | |
1242 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MDS); | |
1243 | balancer->proc_message(m); | |
1244 | break; | |
1245 | ||
1246 | case MSG_MDS_TABLE_REQUEST: | |
1247 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MDS); | |
1248 | { | |
9f95a23c | 1249 | const cref_t<MMDSTableRequest> &req = ref_cast<MMDSTableRequest>(m); |
11fdf7f2 TL |
1250 | if (req->op < 0) { |
1251 | MDSTableClient *client = get_table_client(req->table); | |
1252 | client->handle_request(req); | |
1253 | } else { | |
1254 | MDSTableServer *server = get_table_server(req->table); | |
1255 | server->handle_request(req); | |
1256 | } | |
7c673cae FG |
1257 | } |
1258 | break; | |
1259 | ||
1260 | case MSG_MDS_LOCK: | |
1261 | case MSG_MDS_INODEFILECAPS: | |
1262 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MDS); | |
1263 | locker->dispatch(m); | |
1264 | break; | |
1265 | ||
1266 | case CEPH_MSG_CLIENT_CAPS: | |
1267 | case CEPH_MSG_CLIENT_CAPRELEASE: | |
1268 | case CEPH_MSG_CLIENT_LEASE: | |
1269 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_CLIENT); | |
1270 | locker->dispatch(m); | |
1271 | break; | |
1272 | ||
f67539c2 TL |
1273 | case MSG_MDS_SCRUB: |
1274 | case MSG_MDS_SCRUB_STATS: | |
1275 | ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MDS); | |
1276 | scrubstack->dispatch(m); | |
1277 | break; | |
1278 | ||
7c673cae | 1279 | default: |
f6b5b4d7 | 1280 | derr << "unrecognized message " << *m << dendl; |
7c673cae FG |
1281 | } |
1282 | } | |
7c673cae FG |
1283 | } |
1284 | ||
1285 | /** | |
1286 | * Advance finished_queue and waiting_for_nolaggy. | |
1287 | * | |
1288 | * Usually drain both queues, but may not drain waiting_for_nolaggy | |
1289 | * if beacon is currently laggy. | |
1290 | */ | |
1291 | void MDSRank::_advance_queues() | |
1292 | { | |
9f95a23c | 1293 | ceph_assert(ceph_mutex_is_locked_by_me(mds_lock)); |
7c673cae | 1294 | |
11fdf7f2 | 1295 | if (!finished_queue.empty()) { |
7c673cae | 1296 | dout(7) << "mds has " << finished_queue.size() << " queued contexts" << dendl; |
11fdf7f2 TL |
1297 | while (!finished_queue.empty()) { |
1298 | auto fin = finished_queue.front(); | |
1299 | finished_queue.pop_front(); | |
1300 | ||
1301 | dout(10) << " finish " << fin << dendl; | |
1302 | fin->complete(0); | |
7c673cae FG |
1303 | |
1304 | heartbeat_reset(); | |
1305 | } | |
1306 | } | |
1307 | ||
1308 | while (!waiting_for_nolaggy.empty()) { | |
1309 | // stop if we're laggy now! | |
1310 | if (beacon.is_laggy()) | |
1311 | break; | |
1312 | ||
9f95a23c | 1313 | cref_t<Message> old = waiting_for_nolaggy.front(); |
7c673cae FG |
1314 | waiting_for_nolaggy.pop_front(); |
1315 | ||
11fdf7f2 | 1316 | if (!is_stale_message(old)) { |
7c673cae | 1317 | dout(7) << " processing laggy deferred " << *old << dendl; |
f6b5b4d7 TL |
1318 | ceph_assert(is_valid_message(old)); |
1319 | handle_message(old); | |
7c673cae FG |
1320 | } |
1321 | ||
1322 | heartbeat_reset(); | |
1323 | } | |
1324 | } | |
1325 | ||
1326 | /** | |
1327 | * Call this when you take mds_lock, or periodically if you're going to | |
1328 | * hold the lock for a long time (e.g. iterating over clients/inodes) | |
1329 | */ | |
1330 | void MDSRank::heartbeat_reset() | |
1331 | { | |
1332 | // Any thread might jump into mds_lock and call us immediately | |
1333 | // after a call to suicide() completes, in which case MDSRank::hb | |
1334 | // has been freed and we are a no-op. | |
1335 | if (!hb) { | |
11fdf7f2 | 1336 | ceph_assert(stopping); |
7c673cae FG |
1337 | return; |
1338 | } | |
1339 | ||
1340 | // NB not enabling suicide grace, because the mon takes care of killing us | |
f67539c2 | 1341 | // (by blocklisting us) when we fail to send beacons, and it's simpler to |
7c673cae | 1342 | // only have one way of dying. |
f67539c2 TL |
1343 | g_ceph_context->get_heartbeat_map()->reset_timeout(hb, |
1344 | ceph::make_timespan(heartbeat_grace), | |
1345 | ceph::timespan::zero()); | |
7c673cae FG |
1346 | } |
1347 | ||
9f95a23c | 1348 | bool MDSRank::is_stale_message(const cref_t<Message> &m) const |
7c673cae FG |
1349 | { |
1350 | // from bad mds? | |
1351 | if (m->get_source().is_mds()) { | |
1352 | mds_rank_t from = mds_rank_t(m->get_source().num()); | |
11fdf7f2 TL |
1353 | bool bad = false; |
1354 | if (mdsmap->is_down(from)) { | |
1355 | bad = true; | |
1356 | } else { | |
1357 | // FIXME: this is a convoluted check. we should be maintaining a nice | |
1358 | // clean map of current ConnectionRefs for current mdses!!! | |
1359 | auto c = messenger->connect_to(CEPH_ENTITY_TYPE_MDS, | |
1360 | mdsmap->get_addrs(from)); | |
1361 | if (c != m->get_connection()) { | |
1362 | bad = true; | |
1363 | dout(5) << " mds." << from << " should be " << c << " " | |
1364 | << c->get_peer_addrs() << " but this message is " | |
1365 | << m->get_connection() << " " << m->get_source_addrs() | |
1366 | << dendl; | |
1367 | } | |
1368 | } | |
1369 | if (bad) { | |
7c673cae FG |
1370 | // bogus mds? |
1371 | if (m->get_type() == CEPH_MSG_MDS_MAP) { | |
1372 | dout(5) << "got " << *m << " from old/bad/imposter mds " << m->get_source() | |
1373 | << ", but it's an mdsmap, looking at it" << dendl; | |
1374 | } else if (m->get_type() == MSG_MDS_CACHEEXPIRE && | |
11fdf7f2 | 1375 | mdsmap->get_addrs(from) == m->get_source_addrs()) { |
7c673cae FG |
1376 | dout(5) << "got " << *m << " from down mds " << m->get_source() |
1377 | << ", but it's a cache_expire, looking at it" << dendl; | |
1378 | } else { | |
1379 | dout(5) << "got " << *m << " from down/old/bad/imposter mds " << m->get_source() | |
1380 | << ", dropping" << dendl; | |
1381 | return true; | |
1382 | } | |
1383 | } | |
1384 | } | |
1385 | return false; | |
1386 | } | |
1387 | ||
9f95a23c | 1388 | Session *MDSRank::get_session(const cref_t<Message> &m) |
94b18763 | 1389 | { |
11fdf7f2 TL |
1390 | // do not carry ref |
1391 | auto session = static_cast<Session *>(m->get_connection()->get_priv().get()); | |
94b18763 FG |
1392 | if (session) { |
1393 | dout(20) << "get_session have " << session << " " << session->info.inst | |
1394 | << " state " << session->get_state_name() << dendl; | |
28e407b8 | 1395 | // Check if we've imported an open session since (new sessions start closed) |
1e59de90 | 1396 | if (session->is_closed() && m->get_type() == CEPH_MSG_CLIENT_SESSION) { |
28e407b8 AA |
1397 | Session *imported_session = sessionmap.get_session(session->info.inst.name); |
1398 | if (imported_session && imported_session != session) { | |
11fdf7f2 TL |
1399 | dout(10) << __func__ << " replacing connection bootstrap session " |
1400 | << session << " with imported session " << imported_session | |
1401 | << dendl; | |
28e407b8 AA |
1402 | imported_session->info.auth_name = session->info.auth_name; |
1403 | //assert(session->info.auth_name == imported_session->info.auth_name); | |
11fdf7f2 TL |
1404 | ceph_assert(session->info.inst == imported_session->info.inst); |
1405 | imported_session->set_connection(session->get_connection().get()); | |
28e407b8 AA |
1406 | // send out any queued messages |
1407 | while (!session->preopen_out_queue.empty()) { | |
11fdf7f2 | 1408 | imported_session->get_connection()->send_message2(std::move(session->preopen_out_queue.front())); |
28e407b8 AA |
1409 | session->preopen_out_queue.pop_front(); |
1410 | } | |
1411 | imported_session->auth_caps = session->auth_caps; | |
f64942e4 | 1412 | imported_session->last_seen = session->last_seen; |
11fdf7f2 TL |
1413 | ceph_assert(session->get_nref() == 1); |
1414 | imported_session->get_connection()->set_priv(imported_session->get()); | |
28e407b8 AA |
1415 | session = imported_session; |
1416 | } | |
1417 | } | |
94b18763 FG |
1418 | } else { |
1419 | dout(20) << "get_session dne for " << m->get_source_inst() << dendl; | |
1420 | } | |
1421 | return session; | |
1422 | } | |
7c673cae | 1423 | |
9f95a23c | 1424 | void MDSRank::send_message(const ref_t<Message>& m, const ConnectionRef& c) |
7c673cae | 1425 | { |
11fdf7f2 TL |
1426 | ceph_assert(c); |
1427 | c->send_message2(m); | |
7c673cae FG |
1428 | } |
1429 | ||
20effc67 TL |
1430 | class C_MDS_RetrySendMessageMDS : public MDSInternalContext { |
1431 | public: | |
1432 | C_MDS_RetrySendMessageMDS(MDSRank* mds, mds_rank_t who, ref_t<Message> m) | |
1433 | : MDSInternalContext(mds), who(who), m(std::move(m)) {} | |
1434 | void finish(int r) override { | |
1435 | mds->send_message_mds(m, who); | |
1436 | } | |
1437 | private: | |
1438 | mds_rank_t who; | |
1439 | ref_t<Message> m; | |
1440 | }; | |
1441 | ||
7c673cae | 1442 | |
9f95a23c | 1443 | void MDSRank::send_message_mds(const ref_t<Message>& m, mds_rank_t mds) |
7c673cae FG |
1444 | { |
1445 | if (!mdsmap->is_up(mds)) { | |
1446 | dout(10) << "send_message_mds mds." << mds << " not up, dropping " << *m << dendl; | |
7c673cae | 1447 | return; |
20effc67 TL |
1448 | } else if (mdsmap->is_bootstrapping(mds)) { |
1449 | dout(5) << __func__ << "mds." << mds << " is bootstrapping, deferring " << *m << dendl; | |
1450 | wait_for_bootstrapped_peer(mds, new C_MDS_RetrySendMessageMDS(this, mds, m)); | |
1451 | return; | |
7c673cae FG |
1452 | } |
1453 | ||
1454 | // send mdsmap first? | |
f67539c2 | 1455 | auto addrs = mdsmap->get_addrs(mds); |
7c673cae | 1456 | if (mds != whoami && peer_mdsmap_epoch[mds] < mdsmap->get_epoch()) { |
20effc67 | 1457 | auto _m = make_message<MMDSMap>(monc->get_fsid(), *mdsmap); |
f67539c2 | 1458 | send_message_mds(_m, addrs); |
7c673cae FG |
1459 | peer_mdsmap_epoch[mds] = mdsmap->get_epoch(); |
1460 | } | |
1461 | ||
1462 | // send message | |
f67539c2 TL |
1463 | send_message_mds(m, addrs); |
1464 | } | |
1465 | ||
1466 | void MDSRank::send_message_mds(const ref_t<Message>& m, const entity_addrvec_t &addr) | |
1467 | { | |
1468 | messenger->send_to_mds(ref_t<Message>(m).detach(), addr); | |
7c673cae FG |
1469 | } |
1470 | ||
9f95a23c | 1471 | void MDSRank::forward_message_mds(const cref_t<MClientRequest>& m, mds_rank_t mds) |
7c673cae | 1472 | { |
11fdf7f2 | 1473 | ceph_assert(mds != whoami); |
7c673cae | 1474 | |
11fdf7f2 TL |
1475 | /* |
1476 | * don't actually forward if non-idempotent! | |
1477 | * client has to do it. although the MDS will ignore duplicate requests, | |
1478 | * the affected metadata may migrate, in which case the new authority | |
1479 | * won't have the metareq_id in the completed request map. | |
1480 | */ | |
1481 | // NEW: always make the client resend! | |
1482 | bool client_must_resend = true; //!creq->can_forward(); | |
7c673cae | 1483 | |
11fdf7f2 TL |
1484 | // tell the client where it should go |
1485 | auto session = get_session(m); | |
9f95a23c | 1486 | auto f = make_message<MClientRequestForward>(m->get_tid(), mds, m->get_num_fwd()+1, client_must_resend); |
11fdf7f2 | 1487 | send_message_client(f, session); |
7c673cae FG |
1488 | } |
1489 | ||
9f95a23c | 1490 | void MDSRank::send_message_client_counted(const ref_t<Message>& m, client_t client) |
7c673cae | 1491 | { |
11fdf7f2 | 1492 | Session *session = sessionmap.get_session(entity_name_t::CLIENT(client.v)); |
7c673cae FG |
1493 | if (session) { |
1494 | send_message_client_counted(m, session); | |
1495 | } else { | |
1496 | dout(10) << "send_message_client_counted no session for client." << client << " " << *m << dendl; | |
1497 | } | |
1498 | } | |
1499 | ||
9f95a23c | 1500 | void MDSRank::send_message_client_counted(const ref_t<Message>& m, const ConnectionRef& connection) |
7c673cae | 1501 | { |
11fdf7f2 TL |
1502 | // do not carry ref |
1503 | auto session = static_cast<Session *>(connection->get_priv().get()); | |
7c673cae | 1504 | if (session) { |
7c673cae FG |
1505 | send_message_client_counted(m, session); |
1506 | } else { | |
1507 | dout(10) << "send_message_client_counted has no session for " << m->get_source_inst() << dendl; | |
1508 | // another Connection took over the Session | |
1509 | } | |
1510 | } | |
1511 | ||
9f95a23c | 1512 | void MDSRank::send_message_client_counted(const ref_t<Message>& m, Session* session) |
7c673cae FG |
1513 | { |
1514 | version_t seq = session->inc_push_seq(); | |
1515 | dout(10) << "send_message_client_counted " << session->info.inst.name << " seq " | |
1516 | << seq << " " << *m << dendl; | |
11fdf7f2 TL |
1517 | if (session->get_connection()) { |
1518 | session->get_connection()->send_message2(m); | |
7c673cae FG |
1519 | } else { |
1520 | session->preopen_out_queue.push_back(m); | |
1521 | } | |
1522 | } | |
1523 | ||
9f95a23c | 1524 | void MDSRank::send_message_client(const ref_t<Message>& m, Session* session) |
7c673cae FG |
1525 | { |
1526 | dout(10) << "send_message_client " << session->info.inst << " " << *m << dendl; | |
11fdf7f2 TL |
1527 | if (session->get_connection()) { |
1528 | session->get_connection()->send_message2(m); | |
7c673cae FG |
1529 | } else { |
1530 | session->preopen_out_queue.push_back(m); | |
1531 | } | |
1532 | } | |
1533 | ||
1534 | /** | |
1535 | * This is used whenever a RADOS operation has been cancelled | |
f67539c2 | 1536 | * or a RADOS client has been blocklisted, to cause the MDS and |
7c673cae FG |
1537 | * any clients to wait for this OSD epoch before using any new caps. |
1538 | * | |
1539 | * See doc/cephfs/eviction | |
1540 | */ | |
1541 | void MDSRank::set_osd_epoch_barrier(epoch_t e) | |
1542 | { | |
1543 | dout(4) << __func__ << ": epoch=" << e << dendl; | |
1544 | osd_epoch_barrier = e; | |
1545 | } | |
1546 | ||
9f95a23c | 1547 | void MDSRank::retry_dispatch(const cref_t<Message> &m) |
7c673cae FG |
1548 | { |
1549 | inc_dispatch_depth(); | |
1550 | _dispatch(m, false); | |
1551 | dec_dispatch_depth(); | |
1552 | } | |
1553 | ||
91327a77 | 1554 | double MDSRank::get_dispatch_queue_max_age(utime_t now) const |
7c673cae | 1555 | { |
91327a77 | 1556 | return messenger->get_dispatch_queue_max_age(now); |
7c673cae FG |
1557 | } |
1558 | ||
1559 | bool MDSRank::is_daemon_stopping() const | |
1560 | { | |
1561 | return stopping; | |
1562 | } | |
1563 | ||
1564 | void MDSRank::request_state(MDSMap::DaemonState s) | |
1565 | { | |
1566 | dout(3) << "request_state " << ceph_mds_state_name(s) << dendl; | |
11fdf7f2 | 1567 | beacon.set_want_state(*mdsmap, s); |
7c673cae FG |
1568 | beacon.send(); |
1569 | } | |
1570 | ||
1571 | ||
1572 | class C_MDS_BootStart : public MDSInternalContext { | |
1573 | MDSRank::BootStep nextstep; | |
1574 | public: | |
1575 | C_MDS_BootStart(MDSRank *m, MDSRank::BootStep n) | |
1576 | : MDSInternalContext(m), nextstep(n) {} | |
1577 | void finish(int r) override { | |
1578 | mds->boot_start(nextstep, r); | |
1579 | } | |
1580 | }; | |
1581 | ||
1582 | ||
1583 | void MDSRank::boot_start(BootStep step, int r) | |
1584 | { | |
1585 | // Handle errors from previous step | |
1586 | if (r < 0) { | |
f67539c2 TL |
1587 | if (is_standby_replay() && (r == -CEPHFS_EAGAIN)) { |
1588 | dout(0) << "boot_start encountered an error CEPHFS_EAGAIN" | |
7c673cae FG |
1589 | << ", respawning since we fell behind journal" << dendl; |
1590 | respawn(); | |
f67539c2 | 1591 | } else if (r == -CEPHFS_EINVAL || r == -CEPHFS_ENOENT) { |
7c673cae FG |
1592 | // Invalid or absent data, indicates damaged on-disk structures |
1593 | clog->error() << "Error loading MDS rank " << whoami << ": " | |
1594 | << cpp_strerror(r); | |
1595 | damaged(); | |
11fdf7f2 | 1596 | ceph_assert(r == 0); // Unreachable, damaged() calls respawn() |
f67539c2 | 1597 | } else if (r == -CEPHFS_EROFS) { |
f64942e4 | 1598 | dout(0) << "boot error forcing transition to read-only; MDS will try to continue" << dendl; |
7c673cae FG |
1599 | } else { |
1600 | // Completely unexpected error, give up and die | |
1601 | dout(0) << "boot_start encountered an error, failing" << dendl; | |
1602 | suicide(); | |
1603 | return; | |
1604 | } | |
1605 | } | |
1606 | ||
11fdf7f2 | 1607 | ceph_assert(is_starting() || is_any_replay()); |
7c673cae FG |
1608 | |
1609 | switch(step) { | |
1610 | case MDS_BOOT_INITIAL: | |
1611 | { | |
1612 | mdcache->init_layouts(); | |
1613 | ||
1614 | MDSGatherBuilder gather(g_ceph_context, | |
1615 | new C_MDS_BootStart(this, MDS_BOOT_OPEN_ROOT)); | |
a8e16298 | 1616 | dout(2) << "Booting: " << step << ": opening inotable" << dendl; |
7c673cae FG |
1617 | inotable->set_rank(whoami); |
1618 | inotable->load(gather.new_sub()); | |
1619 | ||
a8e16298 | 1620 | dout(2) << "Booting: " << step << ": opening sessionmap" << dendl; |
7c673cae FG |
1621 | sessionmap.set_rank(whoami); |
1622 | sessionmap.load(gather.new_sub()); | |
1623 | ||
a8e16298 | 1624 | dout(2) << "Booting: " << step << ": opening mds log" << dendl; |
7c673cae FG |
1625 | mdlog->open(gather.new_sub()); |
1626 | ||
3efd9988 | 1627 | if (is_starting()) { |
a8e16298 | 1628 | dout(2) << "Booting: " << step << ": opening purge queue" << dendl; |
3efd9988 FG |
1629 | purge_queue.open(new C_IO_Wrapper(this, gather.new_sub())); |
1630 | } else if (!standby_replaying) { | |
a8e16298 | 1631 | dout(2) << "Booting: " << step << ": opening purge queue (async)" << dendl; |
3efd9988 | 1632 | purge_queue.open(NULL); |
11fdf7f2 TL |
1633 | dout(2) << "Booting: " << step << ": loading open file table (async)" << dendl; |
1634 | mdcache->open_file_table.load(nullptr); | |
3efd9988 FG |
1635 | } |
1636 | ||
7c673cae | 1637 | if (mdsmap->get_tableserver() == whoami) { |
a8e16298 | 1638 | dout(2) << "Booting: " << step << ": opening snap table" << dendl; |
7c673cae FG |
1639 | snapserver->set_rank(whoami); |
1640 | snapserver->load(gather.new_sub()); | |
1641 | } | |
1642 | ||
1643 | gather.activate(); | |
1644 | } | |
1645 | break; | |
1646 | case MDS_BOOT_OPEN_ROOT: | |
1647 | { | |
a8e16298 | 1648 | dout(2) << "Booting: " << step << ": loading/discovering base inodes" << dendl; |
7c673cae FG |
1649 | |
1650 | MDSGatherBuilder gather(g_ceph_context, | |
1651 | new C_MDS_BootStart(this, MDS_BOOT_PREPARE_LOG)); | |
1652 | ||
28e407b8 AA |
1653 | if (is_starting()) { |
1654 | // load mydir frag for the first log segment (creating subtree map) | |
1655 | mdcache->open_mydir_frag(gather.new_sub()); | |
1656 | } else { | |
1657 | mdcache->open_mydir_inode(gather.new_sub()); | |
1658 | } | |
7c673cae | 1659 | |
11fdf7f2 TL |
1660 | mdcache->create_global_snaprealm(); |
1661 | ||
28e407b8 AA |
1662 | if (whoami == mdsmap->get_root()) { // load root inode off disk if we are auth |
1663 | mdcache->open_root_inode(gather.new_sub()); | |
1664 | } else if (is_any_replay()) { | |
1665 | // replay. make up fake root inode to start with | |
1666 | mdcache->create_root_inode(); | |
1667 | } | |
7c673cae FG |
1668 | gather.activate(); |
1669 | } | |
1670 | break; | |
1671 | case MDS_BOOT_PREPARE_LOG: | |
1672 | if (is_any_replay()) { | |
a8e16298 | 1673 | dout(2) << "Booting: " << step << ": replaying mds log" << dendl; |
3efd9988 FG |
1674 | MDSGatherBuilder gather(g_ceph_context, |
1675 | new C_MDS_BootStart(this, MDS_BOOT_REPLAY_DONE)); | |
1676 | ||
1677 | if (!standby_replaying) { | |
a8e16298 | 1678 | dout(2) << "Booting: " << step << ": waiting for purge queue recovered" << dendl; |
3efd9988 FG |
1679 | purge_queue.wait_for_recovery(new C_IO_Wrapper(this, gather.new_sub())); |
1680 | } | |
1681 | ||
1682 | mdlog->replay(gather.new_sub()); | |
1683 | gather.activate(); | |
7c673cae | 1684 | } else { |
a8e16298 | 1685 | dout(2) << "Booting: " << step << ": positioning at end of old mds log" << dendl; |
7c673cae FG |
1686 | mdlog->append(); |
1687 | starting_done(); | |
1688 | } | |
1689 | break; | |
1690 | case MDS_BOOT_REPLAY_DONE: | |
11fdf7f2 | 1691 | ceph_assert(is_any_replay()); |
7c673cae FG |
1692 | |
1693 | // Sessiontable and inotable should be in sync after replay, validate | |
1694 | // that they are consistent. | |
1695 | validate_sessions(); | |
1696 | ||
1697 | replay_done(); | |
1698 | break; | |
1699 | } | |
1700 | } | |
1701 | ||
1702 | void MDSRank::validate_sessions() | |
1703 | { | |
9f95a23c | 1704 | ceph_assert(ceph_mutex_is_locked_by_me(mds_lock)); |
28e407b8 | 1705 | bool valid = true; |
7c673cae FG |
1706 | |
1707 | // Identify any sessions which have state inconsistent with other, | |
1708 | // after they have been loaded from rados during startup. | |
1709 | // Mitigate bugs like: http://tracker.ceph.com/issues/16842 | |
11fdf7f2 | 1710 | for (const auto &i : sessionmap.get_sessions()) { |
7c673cae | 1711 | Session *session = i.second; |
f67539c2 TL |
1712 | ceph_assert(session->info.prealloc_inos == session->free_prealloc_inos); |
1713 | ||
7c673cae FG |
1714 | interval_set<inodeno_t> badones; |
1715 | if (inotable->intersects_free(session->info.prealloc_inos, &badones)) { | |
28e407b8 AA |
1716 | clog->error() << "client " << *session |
1717 | << "loaded with preallocated inodes that are inconsistent with inotable"; | |
1718 | valid = false; | |
7c673cae FG |
1719 | } |
1720 | } | |
1721 | ||
28e407b8 AA |
1722 | if (!valid) { |
1723 | damaged(); | |
11fdf7f2 | 1724 | ceph_assert(valid); |
7c673cae FG |
1725 | } |
1726 | } | |
1727 | ||
1728 | void MDSRank::starting_done() | |
1729 | { | |
1730 | dout(3) << "starting_done" << dendl; | |
11fdf7f2 | 1731 | ceph_assert(is_starting()); |
7c673cae FG |
1732 | request_state(MDSMap::STATE_ACTIVE); |
1733 | ||
28e407b8 | 1734 | mdlog->start_new_segment(); |
11fdf7f2 TL |
1735 | |
1736 | // sync snaptable cache | |
1737 | snapclient->sync(new C_MDSInternalNoop); | |
7c673cae FG |
1738 | } |
1739 | ||
1740 | ||
1741 | void MDSRank::calc_recovery_set() | |
1742 | { | |
1743 | // initialize gather sets | |
1744 | set<mds_rank_t> rs; | |
1745 | mdsmap->get_recovery_mds_set(rs); | |
1746 | rs.erase(whoami); | |
1747 | mdcache->set_recovery_set(rs); | |
1748 | ||
1749 | dout(1) << " recovery set is " << rs << dendl; | |
1750 | } | |
1751 | ||
7c673cae FG |
1752 | void MDSRank::replay_start() |
1753 | { | |
1754 | dout(1) << "replay_start" << dendl; | |
1755 | ||
a4b75251 | 1756 | if (is_standby_replay()) { |
7c673cae | 1757 | standby_replaying = true; |
a4b75251 TL |
1758 | if (unlikely(g_conf().get_val<bool>("mds_standby_replay_damaged"))) { |
1759 | damaged(); | |
1760 | } | |
1761 | } | |
7c673cae | 1762 | |
7c673cae | 1763 | // Check if we need to wait for a newer OSD map before starting |
f67539c2 TL |
1764 | bool const ready = objecter->with_osdmap( |
1765 | [this](const OSDMap& o) { | |
1766 | return o.get_epoch() >= mdsmap->get_last_failure_osd_epoch(); | |
1767 | }); | |
7c673cae FG |
1768 | |
1769 | if (ready) { | |
7c673cae FG |
1770 | boot_start(); |
1771 | } else { | |
1772 | dout(1) << " waiting for osdmap " << mdsmap->get_last_failure_osd_epoch() | |
f67539c2 TL |
1773 | << " (which blocklists prior instance)" << dendl; |
1774 | Context *fin = new C_IO_Wrapper(this, new C_MDS_BootStart(this, MDS_BOOT_INITIAL)); | |
1775 | objecter->wait_for_map( | |
1776 | mdsmap->get_last_failure_osd_epoch(), | |
1777 | lambdafy(fin)); | |
7c673cae FG |
1778 | } |
1779 | } | |
1780 | ||
1781 | ||
1782 | class MDSRank::C_MDS_StandbyReplayRestartFinish : public MDSIOContext { | |
1783 | uint64_t old_read_pos; | |
1784 | public: | |
1785 | C_MDS_StandbyReplayRestartFinish(MDSRank *mds_, uint64_t old_read_pos_) : | |
1786 | MDSIOContext(mds_), old_read_pos(old_read_pos_) {} | |
1787 | void finish(int r) override { | |
1788 | mds->_standby_replay_restart_finish(r, old_read_pos); | |
1789 | } | |
91327a77 AA |
1790 | void print(ostream& out) const override { |
1791 | out << "standby_replay_restart"; | |
1792 | } | |
7c673cae FG |
1793 | }; |
1794 | ||
1795 | void MDSRank::_standby_replay_restart_finish(int r, uint64_t old_read_pos) | |
1796 | { | |
1797 | if (old_read_pos < mdlog->get_journaler()->get_trimmed_pos()) { | |
1798 | dout(0) << "standby MDS fell behind active MDS journal's expire_pos, restarting" << dendl; | |
1799 | respawn(); /* we're too far back, and this is easier than | |
1800 | trying to reset everything in the cache, etc */ | |
1801 | } else { | |
1802 | mdlog->standby_trim_segments(); | |
1803 | boot_start(MDS_BOOT_PREPARE_LOG, r); | |
1804 | } | |
1805 | } | |
1806 | ||
3efd9988 FG |
1807 | class MDSRank::C_MDS_StandbyReplayRestart : public MDSInternalContext { |
1808 | public: | |
1809 | explicit C_MDS_StandbyReplayRestart(MDSRank *m) : MDSInternalContext(m) {} | |
1810 | void finish(int r) override { | |
11fdf7f2 | 1811 | ceph_assert(!r); |
3efd9988 FG |
1812 | mds->standby_replay_restart(); |
1813 | } | |
1814 | }; | |
1815 | ||
1816 | void MDSRank::standby_replay_restart() | |
7c673cae FG |
1817 | { |
1818 | if (standby_replaying) { | |
1819 | /* Go around for another pass of replaying in standby */ | |
f64942e4 | 1820 | dout(5) << "Restarting replay as standby-replay" << dendl; |
7c673cae FG |
1821 | mdlog->get_journaler()->reread_head_and_probe( |
1822 | new C_MDS_StandbyReplayRestartFinish( | |
1823 | this, | |
1824 | mdlog->get_journaler()->get_read_pos())); | |
1825 | } else { | |
1826 | /* We are transitioning out of standby: wait for OSD map update | |
1827 | before making final pass */ | |
1828 | dout(1) << "standby_replay_restart (final takeover pass)" << dendl; | |
f67539c2 TL |
1829 | bool ready = objecter->with_osdmap( |
1830 | [this](const OSDMap& o) { | |
1831 | return o.get_epoch() >= mdsmap->get_last_failure_osd_epoch(); | |
1832 | }); | |
7c673cae | 1833 | if (ready) { |
7c673cae FG |
1834 | mdlog->get_journaler()->reread_head_and_probe( |
1835 | new C_MDS_StandbyReplayRestartFinish( | |
1836 | this, | |
1837 | mdlog->get_journaler()->get_read_pos())); | |
3efd9988 | 1838 | |
11fdf7f2 | 1839 | dout(1) << " opening purge_queue (async)" << dendl; |
3efd9988 | 1840 | purge_queue.open(NULL); |
11fdf7f2 TL |
1841 | dout(1) << " opening open_file_table (async)" << dendl; |
1842 | mdcache->open_file_table.load(nullptr); | |
7c673cae | 1843 | } else { |
f67539c2 | 1844 | auto fin = new C_IO_Wrapper(this, new C_MDS_StandbyReplayRestart(this)); |
7c673cae | 1845 | dout(1) << " waiting for osdmap " << mdsmap->get_last_failure_osd_epoch() |
f67539c2 TL |
1846 | << " (which blocklists prior instance)" << dendl; |
1847 | objecter->wait_for_map(mdsmap->get_last_failure_osd_epoch(), | |
1848 | lambdafy(fin)); | |
7c673cae FG |
1849 | } |
1850 | } | |
1851 | } | |
1852 | ||
7c673cae FG |
1853 | void MDSRank::replay_done() |
1854 | { | |
f64942e4 AA |
1855 | if (!standby_replaying) { |
1856 | dout(1) << "Finished replaying journal" << dendl; | |
1857 | } else { | |
1858 | dout(5) << "Finished replaying journal as standby-replay" << dendl; | |
1859 | } | |
7c673cae FG |
1860 | |
1861 | if (is_standby_replay()) { | |
1862 | // The replay was done in standby state, and we are still in that state | |
11fdf7f2 | 1863 | ceph_assert(standby_replaying); |
7c673cae | 1864 | dout(10) << "setting replay timer" << dendl; |
11fdf7f2 | 1865 | timer.add_event_after(g_conf()->mds_replay_interval, |
7c673cae FG |
1866 | new C_MDS_StandbyReplayRestart(this)); |
1867 | return; | |
1868 | } else if (standby_replaying) { | |
1869 | // The replay was done in standby state, we have now _left_ that state | |
1870 | dout(10) << " last replay pass was as a standby; making final pass" << dendl; | |
1871 | standby_replaying = false; | |
1872 | standby_replay_restart(); | |
1873 | return; | |
1874 | } else { | |
1875 | // Replay is complete, journal read should be up to date | |
11fdf7f2 TL |
1876 | ceph_assert(mdlog->get_journaler()->get_read_pos() == mdlog->get_journaler()->get_write_pos()); |
1877 | ceph_assert(!is_standby_replay()); | |
7c673cae FG |
1878 | |
1879 | // Reformat and come back here | |
11fdf7f2 | 1880 | if (mdlog->get_journaler()->get_stream_format() < g_conf()->mds_journal_format) { |
f64942e4 | 1881 | dout(4) << "reformatting journal on standby-replay->replay transition" << dendl; |
7c673cae FG |
1882 | mdlog->reopen(new C_MDS_BootStart(this, MDS_BOOT_REPLAY_DONE)); |
1883 | return; | |
1884 | } | |
1885 | } | |
1886 | ||
1887 | dout(1) << "making mds journal writeable" << dendl; | |
1888 | mdlog->get_journaler()->set_writeable(); | |
1889 | mdlog->get_journaler()->trim_tail(); | |
1890 | ||
11fdf7f2 TL |
1891 | if (mdsmap->get_tableserver() == whoami && |
1892 | snapserver->upgrade_format()) { | |
1893 | dout(1) << "upgrading snaptable format" << dendl; | |
1894 | snapserver->save(new C_MDSInternalNoop); | |
1895 | } | |
1896 | ||
1897 | if (g_conf()->mds_wipe_sessions) { | |
7c673cae FG |
1898 | dout(1) << "wiping out client sessions" << dendl; |
1899 | sessionmap.wipe(); | |
1900 | sessionmap.save(new C_MDSInternalNoop); | |
1901 | } | |
11fdf7f2 | 1902 | if (g_conf()->mds_wipe_ino_prealloc) { |
7c673cae FG |
1903 | dout(1) << "wiping out ino prealloc from sessions" << dendl; |
1904 | sessionmap.wipe_ino_prealloc(); | |
1905 | sessionmap.save(new C_MDSInternalNoop); | |
1906 | } | |
11fdf7f2 TL |
1907 | if (g_conf()->mds_skip_ino) { |
1908 | inodeno_t i = g_conf()->mds_skip_ino; | |
7c673cae FG |
1909 | dout(1) << "skipping " << i << " inodes" << dendl; |
1910 | inotable->skip_inos(i); | |
1911 | inotable->save(new C_MDSInternalNoop); | |
1912 | } | |
1913 | ||
1914 | if (mdsmap->get_num_in_mds() == 1 && | |
1915 | mdsmap->get_num_failed_mds() == 0) { // just me! | |
1916 | dout(2) << "i am alone, moving to state reconnect" << dendl; | |
1917 | request_state(MDSMap::STATE_RECONNECT); | |
11fdf7f2 TL |
1918 | // sync snaptable cache |
1919 | snapclient->sync(new C_MDSInternalNoop); | |
7c673cae FG |
1920 | } else { |
1921 | dout(2) << "i am not alone, moving to state resolve" << dendl; | |
1922 | request_state(MDSMap::STATE_RESOLVE); | |
1923 | } | |
1924 | } | |
1925 | ||
1926 | void MDSRank::reopen_log() | |
1927 | { | |
1928 | dout(1) << "reopen_log" << dendl; | |
1929 | mdcache->rollback_uncommitted_fragments(); | |
1930 | } | |
1931 | ||
7c673cae FG |
1932 | void MDSRank::resolve_start() |
1933 | { | |
1934 | dout(1) << "resolve_start" << dendl; | |
1935 | ||
1936 | reopen_log(); | |
1937 | ||
f91f0fd5 TL |
1938 | calc_recovery_set(); |
1939 | ||
7c673cae FG |
1940 | mdcache->resolve_start(new C_MDS_VoidFn(this, &MDSRank::resolve_done)); |
1941 | finish_contexts(g_ceph_context, waiting_for_resolve); | |
1942 | } | |
11fdf7f2 | 1943 | |
7c673cae FG |
1944 | void MDSRank::resolve_done() |
1945 | { | |
1946 | dout(1) << "resolve_done" << dendl; | |
1947 | request_state(MDSMap::STATE_RECONNECT); | |
11fdf7f2 TL |
1948 | // sync snaptable cache |
1949 | snapclient->sync(new C_MDSInternalNoop); | |
7c673cae FG |
1950 | } |
1951 | ||
a4b75251 | 1952 | void MDSRank::apply_blocklist(const std::set<entity_addr_t> &addrs, epoch_t epoch) { |
33c7a0ef TL |
1953 | auto victims = server->apply_blocklist(); |
1954 | dout(4) << __func__ << ": killed " << victims << ", blocklisted sessions (" | |
a4b75251 TL |
1955 | << addrs.size() << " blocklist entries, " |
1956 | << sessionmap.get_sessions().size() << ")" << dendl; | |
1957 | if (victims) { | |
1958 | set_osd_epoch_barrier(epoch); | |
1959 | } | |
1960 | } | |
1961 | ||
1962 | ||
7c673cae FG |
1963 | void MDSRank::reconnect_start() |
1964 | { | |
1965 | dout(1) << "reconnect_start" << dendl; | |
1966 | ||
1967 | if (last_state == MDSMap::STATE_REPLAY) { | |
1968 | reopen_log(); | |
1969 | } | |
1970 | ||
f67539c2 | 1971 | // Drop any blocklisted clients from the SessionMap before going |
31f18b77 | 1972 | // into reconnect, so that we don't wait for them. |
f67539c2 TL |
1973 | objecter->enable_blocklist_events(); |
1974 | std::set<entity_addr_t> blocklist; | |
33c7a0ef | 1975 | std::set<entity_addr_t> range; |
31f18b77 | 1976 | epoch_t epoch = 0; |
33c7a0ef TL |
1977 | objecter->with_osdmap([&blocklist, &range, &epoch](const OSDMap& o) { |
1978 | o.get_blocklist(&blocklist, &range); | |
31f18b77 FG |
1979 | epoch = o.get_epoch(); |
1980 | }); | |
a4b75251 TL |
1981 | |
1982 | apply_blocklist(blocklist, epoch); | |
31f18b77 | 1983 | |
7c673cae FG |
1984 | server->reconnect_clients(new C_MDS_VoidFn(this, &MDSRank::reconnect_done)); |
1985 | finish_contexts(g_ceph_context, waiting_for_reconnect); | |
1986 | } | |
1987 | void MDSRank::reconnect_done() | |
1988 | { | |
1989 | dout(1) << "reconnect_done" << dendl; | |
1990 | request_state(MDSMap::STATE_REJOIN); // move to rejoin state | |
1991 | } | |
1992 | ||
1993 | void MDSRank::rejoin_joint_start() | |
1994 | { | |
1995 | dout(1) << "rejoin_joint_start" << dendl; | |
1996 | mdcache->rejoin_send_rejoins(); | |
1997 | } | |
1998 | void MDSRank::rejoin_start() | |
1999 | { | |
2000 | dout(1) << "rejoin_start" << dendl; | |
2001 | mdcache->rejoin_start(new C_MDS_VoidFn(this, &MDSRank::rejoin_done)); | |
a8e16298 | 2002 | finish_contexts(g_ceph_context, waiting_for_rejoin); |
7c673cae FG |
2003 | } |
2004 | void MDSRank::rejoin_done() | |
2005 | { | |
2006 | dout(1) << "rejoin_done" << dendl; | |
2007 | mdcache->show_subtrees(); | |
2008 | mdcache->show_cache(); | |
2009 | ||
e306af50 TL |
2010 | if (mdcache->is_any_uncommitted_fragment()) { |
2011 | dout(1) << " waiting for uncommitted fragments" << dendl; | |
f91f0fd5 | 2012 | mdcache->wait_for_uncommitted_fragments(new C_MDS_VoidFn(this, &MDSRank::rejoin_done)); |
e306af50 TL |
2013 | return; |
2014 | } | |
2015 | ||
7c673cae FG |
2016 | // funny case: is our cache empty? no subtrees? |
2017 | if (!mdcache->is_subtrees()) { | |
2018 | if (whoami == 0) { | |
2019 | // The root should always have a subtree! | |
2020 | clog->error() << "No subtrees found for root MDS rank!"; | |
2021 | damaged(); | |
11fdf7f2 | 2022 | ceph_assert(mdcache->is_subtrees()); |
7c673cae FG |
2023 | } else { |
2024 | dout(1) << " empty cache, no subtrees, leaving cluster" << dendl; | |
2025 | request_state(MDSMap::STATE_STOPPED); | |
2026 | } | |
2027 | return; | |
2028 | } | |
2029 | ||
11fdf7f2 | 2030 | if (replay_queue.empty() && !server->get_num_pending_reclaim()) { |
7c673cae | 2031 | request_state(MDSMap::STATE_ACTIVE); |
11fdf7f2 TL |
2032 | } else { |
2033 | replaying_requests_done = replay_queue.empty(); | |
7c673cae | 2034 | request_state(MDSMap::STATE_CLIENTREPLAY); |
11fdf7f2 | 2035 | } |
7c673cae FG |
2036 | } |
2037 | ||
2038 | void MDSRank::clientreplay_start() | |
2039 | { | |
2040 | dout(1) << "clientreplay_start" << dendl; | |
2041 | finish_contexts(g_ceph_context, waiting_for_replay); // kick waiters | |
7c673cae FG |
2042 | queue_one_replay(); |
2043 | } | |
2044 | ||
2045 | bool MDSRank::queue_one_replay() | |
2046 | { | |
11fdf7f2 TL |
2047 | if (!replay_queue.empty()) { |
2048 | queue_waiter(replay_queue.front()); | |
2049 | replay_queue.pop_front(); | |
2050 | return true; | |
2051 | } | |
2052 | if (!replaying_requests_done) { | |
2053 | replaying_requests_done = true; | |
2054 | mdlog->flush(); | |
2055 | } | |
2056 | maybe_clientreplay_done(); | |
2057 | return false; | |
2058 | } | |
2059 | ||
2060 | void MDSRank::maybe_clientreplay_done() | |
2061 | { | |
2062 | if (is_clientreplay() && get_want_state() == MDSMap::STATE_CLIENTREPLAY) { | |
2063 | ||
2064 | // don't go to active if there are session waiting for being reclaimed | |
2065 | if (replaying_requests_done && !server->get_num_pending_reclaim()) { | |
2066 | mdlog->wait_for_safe(new C_MDS_VoidFn(this, &MDSRank::clientreplay_done)); | |
2067 | return; | |
2068 | } | |
2069 | ||
2070 | dout(1) << " still have " << replay_queue.size() + (int)!replaying_requests_done | |
2071 | << " requests need to be replayed, " << server->get_num_pending_reclaim() | |
2072 | << " sessions need to be reclaimed" << dendl; | |
7c673cae | 2073 | } |
7c673cae FG |
2074 | } |
2075 | ||
2076 | void MDSRank::clientreplay_done() | |
2077 | { | |
2078 | dout(1) << "clientreplay_done" << dendl; | |
2079 | request_state(MDSMap::STATE_ACTIVE); | |
2080 | } | |
2081 | ||
2082 | void MDSRank::active_start() | |
2083 | { | |
2084 | dout(1) << "active_start" << dendl; | |
2085 | ||
28e407b8 AA |
2086 | if (last_state == MDSMap::STATE_CREATING || |
2087 | last_state == MDSMap::STATE_STARTING) { | |
7c673cae FG |
2088 | mdcache->open_root(); |
2089 | } | |
2090 | ||
f67539c2 TL |
2091 | dout(10) << __func__ << ": initializing metrics handler" << dendl; |
2092 | metrics_handler.init(); | |
2093 | messenger->add_dispatcher_tail(&metrics_handler); | |
2094 | ||
2095 | // metric aggregation is solely done by rank 0 | |
2096 | if (is_rank0()) { | |
2097 | dout(10) << __func__ << ": initializing metric aggregator" << dendl; | |
2098 | ceph_assert(metric_aggregator == nullptr); | |
2099 | metric_aggregator = std::make_unique<MetricAggregator>(cct, this, mgrc); | |
2100 | metric_aggregator->init(); | |
2101 | messenger->add_dispatcher_tail(metric_aggregator.get()); | |
2102 | } | |
2103 | ||
7c673cae FG |
2104 | mdcache->clean_open_file_lists(); |
2105 | mdcache->export_remaining_imported_caps(); | |
2106 | finish_contexts(g_ceph_context, waiting_for_replay); // kick waiters | |
7c673cae FG |
2107 | |
2108 | mdcache->reissue_all_caps(); | |
7c673cae FG |
2109 | |
2110 | finish_contexts(g_ceph_context, waiting_for_active); // kick waiters | |
2111 | } | |
2112 | ||
2113 | void MDSRank::recovery_done(int oldstate) | |
2114 | { | |
2115 | dout(1) << "recovery_done -- successful recovery!" << dendl; | |
11fdf7f2 | 2116 | ceph_assert(is_clientreplay() || is_active()); |
7c673cae FG |
2117 | |
2118 | if (oldstate == MDSMap::STATE_CREATING) | |
2119 | return; | |
2120 | ||
2121 | mdcache->start_recovered_truncates(); | |
9f95a23c | 2122 | mdcache->start_purge_inodes(); |
adb31ebb | 2123 | mdcache->start_files_to_recover(); |
7c673cae | 2124 | |
7c673cae FG |
2125 | mdcache->populate_mydir(); |
2126 | } | |
2127 | ||
2128 | void MDSRank::creating_done() | |
2129 | { | |
2130 | dout(1)<< "creating_done" << dendl; | |
2131 | request_state(MDSMap::STATE_ACTIVE); | |
11fdf7f2 TL |
2132 | // sync snaptable cache |
2133 | snapclient->sync(new C_MDSInternalNoop); | |
7c673cae FG |
2134 | } |
2135 | ||
2136 | void MDSRank::boot_create() | |
2137 | { | |
2138 | dout(3) << "boot_create" << dendl; | |
2139 | ||
2140 | MDSGatherBuilder fin(g_ceph_context, new C_MDS_VoidFn(this, &MDSRank::creating_done)); | |
2141 | ||
2142 | mdcache->init_layouts(); | |
2143 | ||
7c673cae FG |
2144 | inotable->set_rank(whoami); |
2145 | sessionmap.set_rank(whoami); | |
2146 | ||
2147 | // start with a fresh journal | |
2148 | dout(10) << "boot_create creating fresh journal" << dendl; | |
2149 | mdlog->create(fin.new_sub()); | |
2150 | ||
2151 | // open new journal segment, but do not journal subtree map (yet) | |
2152 | mdlog->prepare_new_segment(); | |
2153 | ||
2154 | if (whoami == mdsmap->get_root()) { | |
2155 | dout(3) << "boot_create creating fresh hierarchy" << dendl; | |
2156 | mdcache->create_empty_hierarchy(fin.get()); | |
2157 | } | |
2158 | ||
2159 | dout(3) << "boot_create creating mydir hierarchy" << dendl; | |
2160 | mdcache->create_mydir_hierarchy(fin.get()); | |
2161 | ||
11fdf7f2 TL |
2162 | dout(3) << "boot_create creating global snaprealm" << dendl; |
2163 | mdcache->create_global_snaprealm(); | |
2164 | ||
7c673cae FG |
2165 | // fixme: fake out inotable (reset, pretend loaded) |
2166 | dout(10) << "boot_create creating fresh inotable table" << dendl; | |
2167 | inotable->reset(); | |
2168 | inotable->save(fin.new_sub()); | |
2169 | ||
2170 | // write empty sessionmap | |
2171 | sessionmap.save(fin.new_sub()); | |
2172 | ||
2173 | // Create empty purge queue | |
2174 | purge_queue.create(new C_IO_Wrapper(this, fin.new_sub())); | |
2175 | ||
2176 | // initialize tables | |
2177 | if (mdsmap->get_tableserver() == whoami) { | |
2178 | dout(10) << "boot_create creating fresh snaptable" << dendl; | |
11fdf7f2 | 2179 | snapserver->set_rank(whoami); |
7c673cae FG |
2180 | snapserver->reset(); |
2181 | snapserver->save(fin.new_sub()); | |
2182 | } | |
2183 | ||
11fdf7f2 | 2184 | ceph_assert(g_conf()->mds_kill_create_at != 1); |
7c673cae FG |
2185 | |
2186 | // ok now journal it | |
2187 | mdlog->journal_segment_subtree_map(fin.new_sub()); | |
2188 | mdlog->flush(); | |
2189 | ||
31f18b77 | 2190 | // Usually we do this during reconnect, but creation skips that. |
f67539c2 | 2191 | objecter->enable_blocklist_events(); |
31f18b77 | 2192 | |
7c673cae FG |
2193 | fin.activate(); |
2194 | } | |
2195 | ||
2196 | void MDSRank::stopping_start() | |
2197 | { | |
a8e16298 | 2198 | dout(2) << "Stopping..." << dendl; |
7c673cae FG |
2199 | |
2200 | if (mdsmap->get_num_in_mds() == 1 && !sessionmap.empty()) { | |
11fdf7f2 TL |
2201 | std::vector<Session*> victims; |
2202 | const auto& sessions = sessionmap.get_sessions(); | |
2203 | for (const auto& p : sessions) { | |
2204 | if (!p.first.is_client()) { | |
2205 | continue; | |
2206 | } | |
2207 | ||
2208 | Session *s = p.second; | |
2209 | victims.push_back(s); | |
2210 | } | |
2211 | ||
2212 | dout(20) << __func__ << " matched " << victims.size() << " sessions" << dendl; | |
2213 | ceph_assert(!victims.empty()); | |
2214 | ||
2215 | C_GatherBuilder gather(g_ceph_context, new C_MDSInternalNoop); | |
2216 | for (const auto &s : victims) { | |
f67539c2 | 2217 | CachedStackStringStream css; |
11fdf7f2 | 2218 | evict_client(s->get_client().v, false, |
f67539c2 | 2219 | g_conf()->mds_session_blocklist_on_evict, *css, gather.new_sub()); |
11fdf7f2 TL |
2220 | } |
2221 | gather.activate(); | |
7c673cae FG |
2222 | } |
2223 | ||
2224 | mdcache->shutdown_start(); | |
2225 | } | |
2226 | ||
2227 | void MDSRank::stopping_done() | |
2228 | { | |
a8e16298 | 2229 | dout(2) << "Finished stopping..." << dendl; |
7c673cae FG |
2230 | |
2231 | // tell monitor we shut down cleanly. | |
2232 | request_state(MDSMap::STATE_STOPPED); | |
2233 | } | |
2234 | ||
2235 | void MDSRankDispatcher::handle_mds_map( | |
9f95a23c | 2236 | const cref_t<MMDSMap> &m, |
11fdf7f2 | 2237 | const MDSMap &oldmap) |
7c673cae FG |
2238 | { |
2239 | // I am only to be passed MDSMaps in which I hold a rank | |
11fdf7f2 | 2240 | ceph_assert(whoami != MDS_RANK_NONE); |
7c673cae | 2241 | |
7c673cae | 2242 | mds_gid_t mds_gid = mds_gid_t(monc->get_global_id()); |
2a845540 TL |
2243 | MDSMap::DaemonState oldstate = oldmap.get_state_gid(mds_gid); |
2244 | if (oldstate == MDSMap::STATE_NULL) { | |
2245 | // monitor may skip sending me the STANDBY map (e.g. if paxos_propose_interval is high) | |
2246 | // Assuming I have passed STANDBY state if I got a rank in the first map. | |
2247 | oldstate = MDSMap::STATE_STANDBY; | |
2248 | } | |
2249 | // I should not miss map update | |
2250 | ceph_assert(state == oldstate); | |
7c673cae FG |
2251 | state = mdsmap->get_state_gid(mds_gid); |
2252 | if (state != oldstate) { | |
2253 | last_state = oldstate; | |
2254 | incarnation = mdsmap->get_inc_gid(mds_gid); | |
2255 | } | |
2256 | ||
2257 | version_t epoch = m->get_epoch(); | |
2258 | ||
2259 | // note source's map version | |
2260 | if (m->get_source().is_mds() && | |
2261 | peer_mdsmap_epoch[mds_rank_t(m->get_source().num())] < epoch) { | |
2262 | dout(15) << " peer " << m->get_source() | |
2263 | << " has mdsmap epoch >= " << epoch | |
2264 | << dendl; | |
2265 | peer_mdsmap_epoch[mds_rank_t(m->get_source().num())] = epoch; | |
2266 | } | |
2267 | ||
2268 | // Validate state transitions while I hold a rank | |
2269 | if (!MDSMap::state_transition_valid(oldstate, state)) { | |
2270 | derr << "Invalid state transition " << ceph_mds_state_name(oldstate) | |
2271 | << "->" << ceph_mds_state_name(state) << dendl; | |
2272 | respawn(); | |
2273 | } | |
2274 | ||
2275 | if (oldstate != state) { | |
2276 | // update messenger. | |
20effc67 TL |
2277 | auto sleep_rank_change = g_conf().get_val<double>("mds_sleep_rank_change"); |
2278 | if (unlikely(sleep_rank_change > 0)) { | |
2279 | // This is to trigger a race where another rank tries to connect to this | |
2280 | // MDS before an update to the messenger "myname" is processed. This race | |
2281 | // should be closed by ranks holding messages until the rank is out of a | |
2282 | // "bootstrapping" state. | |
2283 | usleep(sleep_rank_change); | |
2284 | } if (state == MDSMap::STATE_STANDBY_REPLAY) { | |
7c673cae | 2285 | dout(1) << "handle_mds_map i am now mds." << mds_gid << "." << incarnation |
20effc67 | 2286 | << " replaying mds." << whoami << "." << incarnation << dendl; |
7c673cae FG |
2287 | messenger->set_myname(entity_name_t::MDS(mds_gid)); |
2288 | } else { | |
2289 | dout(1) << "handle_mds_map i am now mds." << whoami << "." << incarnation << dendl; | |
2290 | messenger->set_myname(entity_name_t::MDS(whoami)); | |
2291 | } | |
2292 | } | |
2293 | ||
2294 | // tell objecter my incarnation | |
2295 | if (objecter->get_client_incarnation() != incarnation) | |
2296 | objecter->set_client_incarnation(incarnation); | |
2297 | ||
f67539c2 | 2298 | if (mdsmap->get_required_client_features() != oldmap.get_required_client_features()) |
11fdf7f2 TL |
2299 | server->update_required_client_features(); |
2300 | ||
7c673cae | 2301 | // for debug |
11fdf7f2 | 2302 | if (g_conf()->mds_dump_cache_on_map) |
7c673cae FG |
2303 | mdcache->dump_cache(); |
2304 | ||
1adf2230 AA |
2305 | cluster_degraded = mdsmap->is_degraded(); |
2306 | ||
2307 | // mdsmap and oldmap can be discontinuous. failover might happen in the missing mdsmap. | |
2308 | // the 'restart' set tracks ranks that have restarted since the old mdsmap | |
2309 | set<mds_rank_t> restart; | |
2310 | // replaying mds does not communicate with other ranks | |
2311 | if (state >= MDSMap::STATE_RESOLVE) { | |
2312 | // did someone fail? | |
2313 | // new down? | |
2314 | set<mds_rank_t> olddown, down; | |
11fdf7f2 | 2315 | oldmap.get_down_mds_set(&olddown); |
1adf2230 AA |
2316 | mdsmap->get_down_mds_set(&down); |
2317 | for (const auto& r : down) { | |
11fdf7f2 TL |
2318 | if (oldmap.have_inst(r) && olddown.count(r) == 0) { |
2319 | messenger->mark_down_addrs(oldmap.get_addrs(r)); | |
1adf2230 AA |
2320 | handle_mds_failure(r); |
2321 | } | |
2322 | } | |
2323 | ||
2324 | // did someone fail? | |
2325 | // did their addr/inst change? | |
2326 | set<mds_rank_t> up; | |
2327 | mdsmap->get_up_mds_set(up); | |
2328 | for (const auto& r : up) { | |
2329 | auto& info = mdsmap->get_info(r); | |
11fdf7f2 TL |
2330 | if (oldmap.have_inst(r)) { |
2331 | auto& oldinfo = oldmap.get_info(r); | |
1adf2230 | 2332 | if (info.inc != oldinfo.inc) { |
11fdf7f2 | 2333 | messenger->mark_down_addrs(oldinfo.get_addrs()); |
1adf2230 AA |
2334 | if (info.state == MDSMap::STATE_REPLAY || |
2335 | info.state == MDSMap::STATE_RESOLVE) { | |
2336 | restart.insert(r); | |
2337 | handle_mds_failure(r); | |
2338 | } else { | |
11fdf7f2 | 2339 | ceph_assert(info.state == MDSMap::STATE_STARTING || |
1adf2230 AA |
2340 | info.state == MDSMap::STATE_ACTIVE); |
2341 | // -> stopped (missing) -> starting -> active | |
2342 | restart.insert(r); | |
2343 | mdcache->migrator->handle_mds_failure_or_stop(r); | |
11fdf7f2 TL |
2344 | if (mdsmap->get_tableserver() == whoami) |
2345 | snapserver->handle_mds_failure_or_stop(r); | |
1adf2230 AA |
2346 | } |
2347 | } | |
2348 | } else { | |
2349 | if (info.state == MDSMap::STATE_REPLAY || | |
2350 | info.state == MDSMap::STATE_RESOLVE) { | |
2351 | // -> starting/creating (missing) -> active (missing) -> replay -> resolve | |
2352 | restart.insert(r); | |
2353 | handle_mds_failure(r); | |
2354 | } else { | |
11fdf7f2 | 2355 | ceph_assert(info.state == MDSMap::STATE_CREATING || |
1adf2230 AA |
2356 | info.state == MDSMap::STATE_STARTING || |
2357 | info.state == MDSMap::STATE_ACTIVE); | |
2358 | } | |
2359 | } | |
2360 | } | |
2361 | } | |
2362 | ||
7c673cae FG |
2363 | // did it change? |
2364 | if (oldstate != state) { | |
2365 | dout(1) << "handle_mds_map state change " | |
2366 | << ceph_mds_state_name(oldstate) << " --> " | |
2367 | << ceph_mds_state_name(state) << dendl; | |
11fdf7f2 | 2368 | beacon.set_want_state(*mdsmap, state); |
7c673cae FG |
2369 | |
2370 | if (oldstate == MDSMap::STATE_STANDBY_REPLAY) { | |
2371 | dout(10) << "Monitor activated us! Deactivating replay loop" << dendl; | |
20effc67 | 2372 | ceph_assert (state == MDSMap::STATE_REPLAY); |
7c673cae FG |
2373 | } else { |
2374 | // did i just recover? | |
2375 | if ((is_active() || is_clientreplay()) && | |
2376 | (oldstate == MDSMap::STATE_CREATING || | |
2377 | oldstate == MDSMap::STATE_REJOIN || | |
2378 | oldstate == MDSMap::STATE_RECONNECT)) | |
2379 | recovery_done(oldstate); | |
2380 | ||
2381 | if (is_active()) { | |
2382 | active_start(); | |
2383 | } else if (is_any_replay()) { | |
2384 | replay_start(); | |
2385 | } else if (is_resolve()) { | |
2386 | resolve_start(); | |
2387 | } else if (is_reconnect()) { | |
2388 | reconnect_start(); | |
2389 | } else if (is_rejoin()) { | |
2390 | rejoin_start(); | |
2391 | } else if (is_clientreplay()) { | |
2392 | clientreplay_start(); | |
2393 | } else if (is_creating()) { | |
2394 | boot_create(); | |
2395 | } else if (is_starting()) { | |
2396 | boot_start(); | |
2397 | } else if (is_stopping()) { | |
11fdf7f2 | 2398 | ceph_assert(oldstate == MDSMap::STATE_ACTIVE); |
7c673cae FG |
2399 | stopping_start(); |
2400 | } | |
2401 | } | |
2402 | } | |
2403 | ||
2404 | // RESOLVE | |
2405 | // is someone else newly resolving? | |
1adf2230 | 2406 | if (state >= MDSMap::STATE_RESOLVE) { |
11fdf7f2 TL |
2407 | // recover snaptable |
2408 | if (mdsmap->get_tableserver() == whoami) { | |
2409 | if (oldstate < MDSMap::STATE_RESOLVE) { | |
2410 | set<mds_rank_t> s; | |
2411 | mdsmap->get_mds_set_lower_bound(s, MDSMap::STATE_RESOLVE); | |
2412 | snapserver->finish_recovery(s); | |
2413 | } else { | |
2414 | set<mds_rank_t> old_set, new_set; | |
2415 | oldmap.get_mds_set_lower_bound(old_set, MDSMap::STATE_RESOLVE); | |
2416 | mdsmap->get_mds_set_lower_bound(new_set, MDSMap::STATE_RESOLVE); | |
2417 | for (const auto& r : new_set) { | |
2418 | if (r == whoami) | |
2419 | continue; // not me | |
2420 | if (!old_set.count(r) || restart.count(r)) { // newly so? | |
2421 | snapserver->handle_mds_recovery(r); | |
2422 | } | |
2423 | } | |
2424 | } | |
2425 | } | |
2426 | ||
2427 | if ((!oldmap.is_resolving() || !restart.empty()) && mdsmap->is_resolving()) { | |
7c673cae FG |
2428 | set<mds_rank_t> resolve; |
2429 | mdsmap->get_mds_set(resolve, MDSMap::STATE_RESOLVE); | |
2430 | dout(10) << " resolve set is " << resolve << dendl; | |
2431 | calc_recovery_set(); | |
2432 | mdcache->send_resolves(); | |
2433 | } | |
2434 | } | |
2435 | ||
2436 | // REJOIN | |
2437 | // is everybody finally rejoining? | |
1adf2230 | 2438 | if (state >= MDSMap::STATE_REJOIN) { |
7c673cae | 2439 | // did we start? |
11fdf7f2 | 2440 | if (!oldmap.is_rejoining() && mdsmap->is_rejoining()) |
7c673cae FG |
2441 | rejoin_joint_start(); |
2442 | ||
2443 | // did we finish? | |
11fdf7f2 TL |
2444 | if (g_conf()->mds_dump_cache_after_rejoin && |
2445 | oldmap.is_rejoining() && !mdsmap->is_rejoining()) | |
7c673cae FG |
2446 | mdcache->dump_cache(); // for DEBUG only |
2447 | ||
d2e6a577 FG |
2448 | if (oldstate >= MDSMap::STATE_REJOIN || |
2449 | oldstate == MDSMap::STATE_STARTING) { | |
7c673cae FG |
2450 | // ACTIVE|CLIENTREPLAY|REJOIN => we can discover from them. |
2451 | set<mds_rank_t> olddis, dis; | |
11fdf7f2 | 2452 | oldmap.get_mds_set_lower_bound(olddis, MDSMap::STATE_REJOIN); |
1adf2230 AA |
2453 | mdsmap->get_mds_set_lower_bound(dis, MDSMap::STATE_REJOIN); |
2454 | for (const auto& r : dis) { | |
2455 | if (r == whoami) | |
2456 | continue; // not me | |
2457 | if (!olddis.count(r) || restart.count(r)) { // newly so? | |
2458 | mdcache->kick_discovers(r); | |
2459 | mdcache->kick_open_ino_peers(r); | |
7c673cae | 2460 | } |
1adf2230 | 2461 | } |
7c673cae FG |
2462 | } |
2463 | } | |
2464 | ||
11fdf7f2 | 2465 | if (oldmap.is_degraded() && !cluster_degraded && state >= MDSMap::STATE_ACTIVE) { |
7c673cae FG |
2466 | dout(1) << "cluster recovered." << dendl; |
2467 | auto it = waiting_for_active_peer.find(MDS_RANK_NONE); | |
2468 | if (it != waiting_for_active_peer.end()) { | |
2469 | queue_waiters(it->second); | |
2470 | waiting_for_active_peer.erase(it); | |
2471 | } | |
2472 | } | |
2473 | ||
20effc67 TL |
2474 | // did someone leave a "bootstrapping" state? We can't connect until then to |
2475 | // allow messenger "myname" updates. | |
2476 | { | |
2477 | std::vector<mds_rank_t> erase; | |
2478 | for (auto& [rank, queue] : waiting_for_bootstrapping_peer) { | |
2479 | auto state = mdsmap->get_state(rank); | |
2480 | if (state > MDSMap::STATE_REPLAY) { | |
2481 | queue_waiters(queue); | |
2482 | erase.push_back(rank); | |
2483 | } | |
2484 | } | |
2485 | for (const auto& rank : erase) { | |
2486 | waiting_for_bootstrapping_peer.erase(rank); | |
2487 | } | |
2488 | } | |
2489 | // for testing... | |
2490 | if (unlikely(g_conf().get_val<bool>("mds_connect_bootstrapping"))) { | |
2491 | std::set<mds_rank_t> bootstrapping; | |
2492 | mdsmap->get_mds_set(bootstrapping, MDSMap::STATE_REPLAY); | |
2493 | mdsmap->get_mds_set(bootstrapping, MDSMap::STATE_CREATING); | |
2494 | mdsmap->get_mds_set(bootstrapping, MDSMap::STATE_STARTING); | |
2495 | for (const auto& rank : bootstrapping) { | |
2496 | auto m = make_message<MMDSMap>(monc->get_fsid(), *mdsmap); | |
2497 | send_message_mds(std::move(m), rank); | |
2498 | } | |
2499 | } | |
2500 | ||
7c673cae | 2501 | // did someone go active? |
1adf2230 AA |
2502 | if (state >= MDSMap::STATE_CLIENTREPLAY && |
2503 | oldstate >= MDSMap::STATE_CLIENTREPLAY) { | |
7c673cae | 2504 | set<mds_rank_t> oldactive, active; |
11fdf7f2 | 2505 | oldmap.get_mds_set_lower_bound(oldactive, MDSMap::STATE_CLIENTREPLAY); |
1adf2230 AA |
2506 | mdsmap->get_mds_set_lower_bound(active, MDSMap::STATE_CLIENTREPLAY); |
2507 | for (const auto& r : active) { | |
2508 | if (r == whoami) | |
2509 | continue; // not me | |
2510 | if (!oldactive.count(r) || restart.count(r)) // newly so? | |
2511 | handle_mds_recovery(r); | |
7c673cae FG |
2512 | } |
2513 | } | |
2514 | ||
11fdf7f2 | 2515 | if (is_clientreplay() || is_active() || is_stopping()) { |
7c673cae FG |
2516 | // did anyone stop? |
2517 | set<mds_rank_t> oldstopped, stopped; | |
11fdf7f2 | 2518 | oldmap.get_stopped_mds_set(oldstopped); |
7c673cae | 2519 | mdsmap->get_stopped_mds_set(stopped); |
1adf2230 | 2520 | for (const auto& r : stopped) |
11fdf7f2 | 2521 | if (oldstopped.count(r) == 0) { // newly so? |
1adf2230 | 2522 | mdcache->migrator->handle_mds_failure_or_stop(r); |
11fdf7f2 TL |
2523 | if (mdsmap->get_tableserver() == whoami) |
2524 | snapserver->handle_mds_failure_or_stop(r); | |
2525 | } | |
7c673cae FG |
2526 | } |
2527 | ||
2528 | { | |
11fdf7f2 | 2529 | map<epoch_t,MDSContext::vec >::iterator p = waiting_for_mdsmap.begin(); |
7c673cae | 2530 | while (p != waiting_for_mdsmap.end() && p->first <= mdsmap->get_epoch()) { |
11fdf7f2 | 2531 | MDSContext::vec ls; |
7c673cae FG |
2532 | ls.swap(p->second); |
2533 | waiting_for_mdsmap.erase(p++); | |
91327a77 | 2534 | queue_waiters(ls); |
7c673cae FG |
2535 | } |
2536 | } | |
2537 | ||
2538 | if (is_active()) { | |
2539 | // Before going active, set OSD epoch barrier to latest (so that | |
2540 | // we don't risk handing out caps to clients with old OSD maps that | |
2541 | // might not include barriers from the previous incarnation of this MDS) | |
2542 | set_osd_epoch_barrier(objecter->with_osdmap( | |
2543 | std::mem_fn(&OSDMap::get_epoch))); | |
7c673cae | 2544 | |
11fdf7f2 TL |
2545 | /* Now check if we should hint to the OSD that a read may follow */ |
2546 | if (mdsmap->has_standby_replay(whoami)) | |
2547 | mdlog->set_write_iohint(0); | |
2548 | else | |
2549 | mdlog->set_write_iohint(CEPH_OSD_OP_FLAG_FADVISE_DONTNEED); | |
7c673cae FG |
2550 | } |
2551 | ||
11fdf7f2 | 2552 | if (oldmap.get_max_mds() != mdsmap->get_max_mds()) { |
7c673cae FG |
2553 | purge_queue.update_op_limit(*mdsmap); |
2554 | } | |
eafe8130 | 2555 | |
9f95a23c TL |
2556 | if (mdsmap->get_inline_data_enabled() && !oldmap.get_inline_data_enabled()) |
2557 | dout(0) << "WARNING: inline_data support has been deprecated and will be removed in a future release" << dendl; | |
2558 | ||
f6b5b4d7 | 2559 | mdcache->handle_mdsmap(*mdsmap, oldmap); |
f67539c2 TL |
2560 | |
2561 | if (metric_aggregator != nullptr) { | |
2562 | metric_aggregator->notify_mdsmap(*mdsmap); | |
2563 | } | |
2564 | metrics_handler.notify_mdsmap(*mdsmap); | |
7c673cae FG |
2565 | } |
2566 | ||
2567 | void MDSRank::handle_mds_recovery(mds_rank_t who) | |
2568 | { | |
2569 | dout(5) << "handle_mds_recovery mds." << who << dendl; | |
2570 | ||
2571 | mdcache->handle_mds_recovery(who); | |
2572 | ||
7c673cae FG |
2573 | queue_waiters(waiting_for_active_peer[who]); |
2574 | waiting_for_active_peer.erase(who); | |
2575 | } | |
2576 | ||
2577 | void MDSRank::handle_mds_failure(mds_rank_t who) | |
2578 | { | |
2579 | if (who == whoami) { | |
2580 | dout(5) << "handle_mds_failure for myself; not doing anything" << dendl; | |
2581 | return; | |
2582 | } | |
2583 | dout(5) << "handle_mds_failure mds." << who << dendl; | |
2584 | ||
2585 | mdcache->handle_mds_failure(who); | |
2586 | ||
11fdf7f2 TL |
2587 | if (mdsmap->get_tableserver() == whoami) |
2588 | snapserver->handle_mds_failure_or_stop(who); | |
2589 | ||
7c673cae | 2590 | snapclient->handle_mds_failure(who); |
f67539c2 TL |
2591 | |
2592 | scrubstack->handle_mds_failure(who); | |
7c673cae FG |
2593 | } |
2594 | ||
9f95a23c TL |
2595 | void MDSRankDispatcher::handle_asok_command( |
2596 | std::string_view command, | |
2597 | const cmdmap_t& cmdmap, | |
2598 | Formatter *f, | |
2599 | const bufferlist &inbl, | |
2600 | std::function<void(int,const std::string&,bufferlist&)> on_finish) | |
7c673cae | 2601 | { |
9f95a23c | 2602 | int r = 0; |
f67539c2 | 2603 | CachedStackStringStream css; |
9f95a23c | 2604 | bufferlist outbl; |
7c673cae | 2605 | if (command == "dump_ops_in_flight" || |
9f95a23c | 2606 | command == "ops") { |
7c673cae | 2607 | if (!op_tracker.dump_ops_in_flight(f)) { |
f67539c2 | 2608 | *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable"; |
7c673cae FG |
2609 | } |
2610 | } else if (command == "dump_blocked_ops") { | |
2611 | if (!op_tracker.dump_ops_in_flight(f, true)) { | |
f67539c2 | 2612 | *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable"; |
7c673cae | 2613 | } |
1e59de90 TL |
2614 | } else if (command == "dump_blocked_ops_count") { |
2615 | if (!op_tracker.dump_ops_in_flight(f, true, {""}, true)) { | |
2616 | *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable"; | |
2617 | } | |
7c673cae FG |
2618 | } else if (command == "dump_historic_ops") { |
2619 | if (!op_tracker.dump_historic_ops(f)) { | |
f67539c2 | 2620 | *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable"; |
7c673cae FG |
2621 | } |
2622 | } else if (command == "dump_historic_ops_by_duration") { | |
2623 | if (!op_tracker.dump_historic_ops(f, true)) { | |
f67539c2 | 2624 | *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable"; |
7c673cae FG |
2625 | } |
2626 | } else if (command == "osdmap barrier") { | |
2627 | int64_t target_epoch = 0; | |
9f95a23c | 2628 | bool got_val = cmd_getval(cmdmap, "target_epoch", target_epoch); |
7c673cae FG |
2629 | |
2630 | if (!got_val) { | |
f67539c2 TL |
2631 | *css << "no target epoch given"; |
2632 | r = -CEPHFS_EINVAL; | |
9f95a23c TL |
2633 | goto out; |
2634 | } | |
2635 | { | |
2636 | std::lock_guard l(mds_lock); | |
2637 | set_osd_epoch_barrier(target_epoch); | |
7c673cae | 2638 | } |
f67539c2 TL |
2639 | boost::system::error_code ec; |
2640 | dout(4) << __func__ << ": possibly waiting for OSD epoch " << target_epoch << dendl; | |
2641 | objecter->wait_for_map(target_epoch, ceph::async::use_blocked[ec]); | |
9f95a23c TL |
2642 | } else if (command == "session ls" || |
2643 | command == "client ls") { | |
11fdf7f2 | 2644 | std::lock_guard l(mds_lock); |
adb31ebb | 2645 | bool cap_dump = false; |
9f95a23c | 2646 | std::vector<std::string> filter_args; |
adb31ebb | 2647 | cmd_getval(cmdmap, "cap_dump", cap_dump); |
9f95a23c | 2648 | cmd_getval(cmdmap, "filters", filter_args); |
adb31ebb | 2649 | |
9f95a23c | 2650 | SessionFilter filter; |
f67539c2 | 2651 | r = filter.parse(filter_args, css.get()); |
9f95a23c TL |
2652 | if (r != 0) { |
2653 | goto out; | |
2654 | } | |
adb31ebb | 2655 | dump_sessions(filter, f, cap_dump); |
9f95a23c TL |
2656 | } else if (command == "session evict" || |
2657 | command == "client evict") { | |
2658 | std::lock_guard l(mds_lock); | |
2659 | std::vector<std::string> filter_args; | |
2660 | cmd_getval(cmdmap, "filters", filter_args); | |
7c673cae | 2661 | |
9f95a23c | 2662 | SessionFilter filter; |
f67539c2 | 2663 | r = filter.parse(filter_args, css.get()); |
9f95a23c | 2664 | if (r != 0) { |
f67539c2 | 2665 | r = -CEPHFS_EINVAL; |
9f95a23c TL |
2666 | goto out; |
2667 | } | |
2668 | evict_clients(filter, on_finish); | |
2669 | return; | |
2670 | } else if (command == "session kill") { | |
7c673cae | 2671 | std::string client_id; |
9f95a23c | 2672 | if (!cmd_getval(cmdmap, "client_id", client_id)) { |
f67539c2 TL |
2673 | *css << "Invalid client_id specified"; |
2674 | r = -CEPHFS_ENOENT; | |
9f95a23c | 2675 | goto out; |
7c673cae | 2676 | } |
9f95a23c | 2677 | std::lock_guard l(mds_lock); |
31f18b77 | 2678 | bool evicted = evict_client(strtol(client_id.c_str(), 0, 10), true, |
f67539c2 | 2679 | g_conf()->mds_session_blocklist_on_evict, *css); |
31f18b77 | 2680 | if (!evicted) { |
f67539c2 TL |
2681 | dout(15) << css->strv() << dendl; |
2682 | r = -CEPHFS_ENOENT; | |
7c673cae | 2683 | } |
9f95a23c TL |
2684 | } else if (command == "session config" || |
2685 | command == "client config") { | |
92f5a8d4 TL |
2686 | int64_t client_id; |
2687 | std::string option; | |
2688 | std::string value; | |
2689 | ||
9f95a23c TL |
2690 | cmd_getval(cmdmap, "client_id", client_id); |
2691 | cmd_getval(cmdmap, "option", option); | |
2692 | bool got_value = cmd_getval(cmdmap, "value", value); | |
92f5a8d4 | 2693 | |
9f95a23c | 2694 | std::lock_guard l(mds_lock); |
f67539c2 | 2695 | r = config_client(client_id, !got_value, option, value, *css); |
9f95a23c TL |
2696 | } else if (command == "scrub start" || |
2697 | command == "scrub_start") { | |
f67539c2 TL |
2698 | if (whoami != 0) { |
2699 | *css << "Not rank 0"; | |
2700 | r = -CEPHFS_EXDEV; | |
2701 | goto out; | |
2702 | } | |
2703 | ||
7c673cae | 2704 | string path; |
9f95a23c | 2705 | string tag; |
7c673cae | 2706 | vector<string> scrubop_vec; |
9f95a23c TL |
2707 | cmd_getval(cmdmap, "scrubops", scrubop_vec); |
2708 | cmd_getval(cmdmap, "path", path); | |
2709 | cmd_getval(cmdmap, "tag", tag); | |
11fdf7f2 | 2710 | |
9f95a23c TL |
2711 | finisher->queue( |
2712 | new LambdaContext( | |
2713 | [this, on_finish, f, path, tag, scrubop_vec](int r) { | |
2714 | command_scrub_start( | |
2715 | f, path, tag, scrubop_vec, | |
2716 | new LambdaContext( | |
2717 | [on_finish](int r) { | |
2718 | bufferlist outbl; | |
2719 | on_finish(r, {}, outbl); | |
2720 | })); | |
2721 | })); | |
2722 | return; | |
2723 | } else if (command == "scrub abort") { | |
f67539c2 TL |
2724 | if (whoami != 0) { |
2725 | *css << "Not rank 0"; | |
2726 | r = -CEPHFS_EXDEV; | |
2727 | goto out; | |
2728 | } | |
2729 | ||
9f95a23c TL |
2730 | finisher->queue( |
2731 | new LambdaContext( | |
2732 | [this, on_finish, f](int r) { | |
2733 | command_scrub_abort( | |
2734 | f, | |
2735 | new LambdaContext( | |
2736 | [on_finish, f](int r) { | |
2737 | bufferlist outbl; | |
2738 | f->open_object_section("result"); | |
2739 | f->dump_int("return_code", r); | |
2740 | f->close_section(); | |
2741 | on_finish(r, {}, outbl); | |
2742 | })); | |
2743 | })); | |
2744 | return; | |
2745 | } else if (command == "scrub pause") { | |
f67539c2 TL |
2746 | if (whoami != 0) { |
2747 | *css << "Not rank 0"; | |
2748 | r = -CEPHFS_EXDEV; | |
2749 | goto out; | |
2750 | } | |
2751 | ||
9f95a23c TL |
2752 | finisher->queue( |
2753 | new LambdaContext( | |
2754 | [this, on_finish, f](int r) { | |
2755 | command_scrub_pause( | |
2756 | f, | |
2757 | new LambdaContext( | |
2758 | [on_finish, f](int r) { | |
2759 | bufferlist outbl; | |
2760 | f->open_object_section("result"); | |
2761 | f->dump_int("return_code", r); | |
2762 | f->close_section(); | |
2763 | on_finish(r, {}, outbl); | |
2764 | })); | |
2765 | })); | |
2766 | return; | |
2767 | } else if (command == "scrub resume") { | |
f67539c2 TL |
2768 | if (whoami != 0) { |
2769 | *css << "Not rank 0"; | |
2770 | r = -CEPHFS_EXDEV; | |
2771 | goto out; | |
2772 | } | |
9f95a23c TL |
2773 | command_scrub_resume(f); |
2774 | } else if (command == "scrub status") { | |
2775 | command_scrub_status(f); | |
7c673cae | 2776 | } else if (command == "tag path") { |
f67539c2 TL |
2777 | if (whoami != 0) { |
2778 | *css << "Not rank 0"; | |
2779 | r = -CEPHFS_EXDEV; | |
2780 | goto out; | |
2781 | } | |
7c673cae | 2782 | string path; |
9f95a23c | 2783 | cmd_getval(cmdmap, "path", path); |
7c673cae | 2784 | string tag; |
9f95a23c | 2785 | cmd_getval(cmdmap, "tag", tag); |
7c673cae FG |
2786 | command_tag_path(f, path, tag); |
2787 | } else if (command == "flush_path") { | |
2788 | string path; | |
9f95a23c | 2789 | cmd_getval(cmdmap, "path", path); |
7c673cae FG |
2790 | command_flush_path(f, path); |
2791 | } else if (command == "flush journal") { | |
2792 | command_flush_journal(f); | |
2793 | } else if (command == "get subtrees") { | |
2794 | command_get_subtrees(f); | |
2795 | } else if (command == "export dir") { | |
2796 | string path; | |
9f95a23c | 2797 | if(!cmd_getval(cmdmap, "path", path)) { |
f67539c2 TL |
2798 | *css << "malformed path"; |
2799 | r = -CEPHFS_EINVAL; | |
9f95a23c | 2800 | goto out; |
7c673cae FG |
2801 | } |
2802 | int64_t rank; | |
9f95a23c | 2803 | if(!cmd_getval(cmdmap, "rank", rank)) { |
f67539c2 TL |
2804 | *css << "malformed rank"; |
2805 | r = -CEPHFS_EINVAL; | |
9f95a23c | 2806 | goto out; |
7c673cae FG |
2807 | } |
2808 | command_export_dir(f, path, (mds_rank_t)rank); | |
2809 | } else if (command == "dump cache") { | |
11fdf7f2 | 2810 | std::lock_guard l(mds_lock); |
20effc67 TL |
2811 | int64_t timeout = 0; |
2812 | cmd_getval(cmdmap, "timeout", timeout); | |
2813 | auto mds_beacon_interval = g_conf().get_val<double>("mds_beacon_interval"); | |
2814 | if (timeout <= 0) | |
2815 | timeout = mds_beacon_interval / 2; | |
2816 | else if (timeout > mds_beacon_interval) | |
2817 | timeout = mds_beacon_interval; | |
7c673cae | 2818 | string path; |
9f95a23c | 2819 | if (!cmd_getval(cmdmap, "path", path)) { |
20effc67 | 2820 | r = mdcache->dump_cache(f, timeout); |
7c673cae | 2821 | } else { |
20effc67 | 2822 | r = mdcache->dump_cache(path, timeout); |
31f18b77 | 2823 | } |
9f95a23c TL |
2824 | } else if (command == "cache drop") { |
2825 | int64_t timeout = 0; | |
2826 | cmd_getval(cmdmap, "timeout", timeout); | |
2827 | finisher->queue( | |
2828 | new LambdaContext( | |
2829 | [this, on_finish, f, timeout](int r) { | |
2830 | command_cache_drop( | |
2831 | timeout, f, | |
2832 | new LambdaContext( | |
2833 | [on_finish](int r) { | |
2834 | bufferlist outbl; | |
2835 | on_finish(r, {}, outbl); | |
2836 | })); | |
2837 | })); | |
2838 | return; | |
181888fb | 2839 | } else if (command == "cache status") { |
11fdf7f2 | 2840 | std::lock_guard l(mds_lock); |
f64942e4 | 2841 | mdcache->cache_status(f); |
7c673cae | 2842 | } else if (command == "dump tree") { |
f67539c2 | 2843 | command_dump_tree(cmdmap, *css, f); |
28e407b8 | 2844 | } else if (command == "dump loads") { |
11fdf7f2 | 2845 | std::lock_guard l(mds_lock); |
1e59de90 TL |
2846 | int64_t depth = -1; |
2847 | bool got = cmd_getval(cmdmap, "depth", depth); | |
2848 | if (!got || depth < 0) { | |
2849 | dout(10) << "no depth limit when dirfrags dump_load" << dendl; | |
2850 | } | |
2851 | r = balancer->dump_loads(f, depth); | |
11fdf7f2 TL |
2852 | } else if (command == "dump snaps") { |
2853 | std::lock_guard l(mds_lock); | |
2854 | string server; | |
9f95a23c | 2855 | cmd_getval(cmdmap, "server", server); |
11fdf7f2 TL |
2856 | if (server == "--server") { |
2857 | if (mdsmap->get_tableserver() == whoami) { | |
2858 | snapserver->dump(f); | |
2859 | } else { | |
f67539c2 TL |
2860 | r = -CEPHFS_EXDEV; |
2861 | *css << "Not snapserver"; | |
11fdf7f2 TL |
2862 | } |
2863 | } else { | |
9f95a23c | 2864 | r = snapclient->dump_cache(f); |
11fdf7f2 | 2865 | } |
7c673cae | 2866 | } else if (command == "force_readonly") { |
11fdf7f2 | 2867 | std::lock_guard l(mds_lock); |
7c673cae FG |
2868 | mdcache->force_readonly(); |
2869 | } else if (command == "dirfrag split") { | |
f67539c2 | 2870 | command_dirfrag_split(cmdmap, *css); |
7c673cae | 2871 | } else if (command == "dirfrag merge") { |
f67539c2 | 2872 | command_dirfrag_merge(cmdmap, *css); |
7c673cae | 2873 | } else if (command == "dirfrag ls") { |
f67539c2 | 2874 | command_dirfrag_ls(cmdmap, *css, f); |
11fdf7f2 TL |
2875 | } else if (command == "openfiles ls") { |
2876 | command_openfiles_ls(f); | |
2877 | } else if (command == "dump inode") { | |
f67539c2 | 2878 | command_dump_inode(f, cmdmap, *css); |
9f95a23c TL |
2879 | } else if (command == "damage ls") { |
2880 | std::lock_guard l(mds_lock); | |
2881 | damage_table.dump(f); | |
2882 | } else if (command == "damage rm") { | |
2883 | std::lock_guard l(mds_lock); | |
2884 | damage_entry_id_t id = 0; | |
2885 | if (!cmd_getval(cmdmap, "damage_id", (int64_t&)id)) { | |
f67539c2 | 2886 | r = -CEPHFS_EINVAL; |
9f95a23c TL |
2887 | goto out; |
2888 | } | |
2889 | damage_table.erase(id); | |
7c673cae | 2890 | } else { |
f67539c2 | 2891 | r = -CEPHFS_ENOSYS; |
7c673cae | 2892 | } |
9f95a23c | 2893 | out: |
f67539c2 | 2894 | on_finish(r, css->str(), outbl); |
7c673cae FG |
2895 | } |
2896 | ||
7c673cae FG |
2897 | /** |
2898 | * This function drops the mds_lock, so don't do anything with | |
2899 | * MDSRank after calling it (we could have gone into shutdown): just | |
2900 | * send your result back to the calling client and finish. | |
2901 | */ | |
9f95a23c TL |
2902 | void MDSRankDispatcher::evict_clients( |
2903 | const SessionFilter &filter, | |
2904 | std::function<void(int,const std::string&,bufferlist&)> on_finish) | |
7c673cae | 2905 | { |
9f95a23c | 2906 | bufferlist outbl; |
7c673cae | 2907 | if (is_any_replay()) { |
f67539c2 | 2908 | on_finish(-CEPHFS_EAGAIN, "MDS is replaying log", outbl); |
7c673cae FG |
2909 | return; |
2910 | } | |
2911 | ||
11fdf7f2 TL |
2912 | std::vector<Session*> victims; |
2913 | const auto& sessions = sessionmap.get_sessions(); | |
2914 | for (const auto& p : sessions) { | |
7c673cae FG |
2915 | if (!p.first.is_client()) { |
2916 | continue; | |
2917 | } | |
2918 | ||
2919 | Session *s = p.second; | |
2920 | ||
9f95a23c TL |
2921 | if (filter.match(*s, std::bind(&Server::waiting_for_reconnect, server, |
2922 | std::placeholders::_1))) { | |
7c673cae FG |
2923 | victims.push_back(s); |
2924 | } | |
2925 | } | |
2926 | ||
2927 | dout(20) << __func__ << " matched " << victims.size() << " sessions" << dendl; | |
2928 | ||
2929 | if (victims.empty()) { | |
9f95a23c | 2930 | on_finish(0, {}, outbl); |
7c673cae FG |
2931 | return; |
2932 | } | |
2933 | ||
9f95a23c TL |
2934 | C_GatherBuilder gather(g_ceph_context, |
2935 | new LambdaContext([on_finish](int r) { | |
2936 | bufferlist bl; | |
2937 | on_finish(r, {}, bl); | |
2938 | })); | |
7c673cae | 2939 | for (const auto s : victims) { |
f67539c2 | 2940 | CachedStackStringStream css; |
11fdf7f2 | 2941 | evict_client(s->get_client().v, false, |
f67539c2 | 2942 | g_conf()->mds_session_blocklist_on_evict, *css, gather.new_sub()); |
7c673cae FG |
2943 | } |
2944 | gather.activate(); | |
2945 | } | |
2946 | ||
adb31ebb | 2947 | void MDSRankDispatcher::dump_sessions(const SessionFilter &filter, Formatter *f, bool cap_dump) const |
7c673cae FG |
2948 | { |
2949 | // Dump sessions, decorated with recovery/replay status | |
2950 | f->open_array_section("sessions"); | |
92f5a8d4 TL |
2951 | for (auto& [name, s] : sessionmap.get_sessions()) { |
2952 | if (!name.is_client()) { | |
7c673cae FG |
2953 | continue; |
2954 | } | |
2955 | ||
7c673cae FG |
2956 | if (!filter.match(*s, std::bind(&Server::waiting_for_reconnect, server, std::placeholders::_1))) { |
2957 | continue; | |
2958 | } | |
2959 | ||
adb31ebb TL |
2960 | f->open_object_section("session"); |
2961 | s->dump(f, cap_dump); | |
2962 | f->close_section(); | |
7c673cae | 2963 | } |
92f5a8d4 | 2964 | f->close_section(); // sessions |
7c673cae FG |
2965 | } |
2966 | ||
11fdf7f2 TL |
2967 | void MDSRank::command_scrub_start(Formatter *f, |
2968 | std::string_view path, std::string_view tag, | |
2969 | const vector<string>& scrubop_vec, Context *on_finish) | |
7c673cae FG |
2970 | { |
2971 | bool force = false; | |
2972 | bool recursive = false; | |
2973 | bool repair = false; | |
11fdf7f2 TL |
2974 | for (auto &op : scrubop_vec) { |
2975 | if (op == "force") | |
7c673cae | 2976 | force = true; |
11fdf7f2 | 2977 | else if (op == "recursive") |
7c673cae | 2978 | recursive = true; |
11fdf7f2 | 2979 | else if (op == "repair") |
7c673cae FG |
2980 | repair = true; |
2981 | } | |
11fdf7f2 TL |
2982 | |
2983 | std::lock_guard l(mds_lock); | |
2984 | mdcache->enqueue_scrub(path, tag, force, recursive, repair, f, on_finish); | |
7c673cae FG |
2985 | // scrub_dentry() finishers will dump the data for us; we're done! |
2986 | } | |
2987 | ||
2988 | void MDSRank::command_tag_path(Formatter *f, | |
11fdf7f2 | 2989 | std::string_view path, std::string_view tag) |
7c673cae FG |
2990 | { |
2991 | C_SaferCond scond; | |
2992 | { | |
11fdf7f2 | 2993 | std::lock_guard l(mds_lock); |
7c673cae FG |
2994 | mdcache->enqueue_scrub(path, tag, true, true, false, f, &scond); |
2995 | } | |
2996 | scond.wait(); | |
2997 | } | |
2998 | ||
11fdf7f2 TL |
2999 | void MDSRank::command_scrub_abort(Formatter *f, Context *on_finish) { |
3000 | std::lock_guard l(mds_lock); | |
3001 | scrubstack->scrub_abort(on_finish); | |
3002 | } | |
3003 | ||
3004 | void MDSRank::command_scrub_pause(Formatter *f, Context *on_finish) { | |
3005 | std::lock_guard l(mds_lock); | |
3006 | scrubstack->scrub_pause(on_finish); | |
3007 | } | |
3008 | ||
3009 | void MDSRank::command_scrub_resume(Formatter *f) { | |
9f95a23c | 3010 | std::lock_guard l(mds_lock); |
11fdf7f2 TL |
3011 | int r = scrubstack->scrub_resume(); |
3012 | ||
3013 | f->open_object_section("result"); | |
3014 | f->dump_int("return_code", r); | |
3015 | f->close_section(); | |
3016 | } | |
3017 | ||
3018 | void MDSRank::command_scrub_status(Formatter *f) { | |
9f95a23c | 3019 | std::lock_guard l(mds_lock); |
11fdf7f2 TL |
3020 | scrubstack->scrub_status(f); |
3021 | } | |
3022 | ||
3023 | void MDSRank::command_flush_path(Formatter *f, std::string_view path) | |
7c673cae FG |
3024 | { |
3025 | C_SaferCond scond; | |
3026 | { | |
11fdf7f2 | 3027 | std::lock_guard l(mds_lock); |
7c673cae FG |
3028 | mdcache->flush_dentry(path, &scond); |
3029 | } | |
3030 | int r = scond.wait(); | |
3031 | f->open_object_section("results"); | |
3032 | f->dump_int("return_code", r); | |
3033 | f->close_section(); // results | |
3034 | } | |
3035 | ||
f64942e4 AA |
3036 | // synchronous wrapper around "journal flush" asynchronous context |
3037 | // execution. | |
3038 | void MDSRank::command_flush_journal(Formatter *f) { | |
3039 | ceph_assert(f != NULL); | |
7c673cae | 3040 | |
f64942e4 | 3041 | C_SaferCond cond; |
f67539c2 | 3042 | CachedStackStringStream css; |
7c673cae | 3043 | { |
11fdf7f2 | 3044 | std::lock_guard locker(mds_lock); |
f67539c2 | 3045 | C_Flush_Journal *flush_journal = new C_Flush_Journal(mdcache, mdlog, this, css.get(), &cond); |
f64942e4 | 3046 | flush_journal->send(); |
7c673cae | 3047 | } |
f64942e4 | 3048 | int r = cond.wait(); |
7c673cae | 3049 | |
f64942e4 | 3050 | f->open_object_section("result"); |
f67539c2 | 3051 | f->dump_string("message", css->strv()); |
f64942e4 AA |
3052 | f->dump_int("return_code", r); |
3053 | f->close_section(); | |
7c673cae FG |
3054 | } |
3055 | ||
7c673cae FG |
3056 | void MDSRank::command_get_subtrees(Formatter *f) |
3057 | { | |
11fdf7f2 TL |
3058 | ceph_assert(f != NULL); |
3059 | std::lock_guard l(mds_lock); | |
7c673cae | 3060 | |
11fdf7f2 TL |
3061 | std::vector<CDir*> subtrees; |
3062 | mdcache->get_subtrees(subtrees); | |
7c673cae FG |
3063 | |
3064 | f->open_array_section("subtrees"); | |
11fdf7f2 | 3065 | for (const auto& dir : subtrees) { |
7c673cae FG |
3066 | f->open_object_section("subtree"); |
3067 | { | |
3068 | f->dump_bool("is_auth", dir->is_auth()); | |
3069 | f->dump_int("auth_first", dir->get_dir_auth().first); | |
f67539c2 TL |
3070 | f->dump_int("auth_second", dir->get_dir_auth().second); { |
3071 | mds_rank_t export_pin = dir->inode->get_export_pin(false); | |
3072 | f->dump_int("export_pin", export_pin >= 0 ? export_pin : -1); | |
3073 | f->dump_bool("distributed_ephemeral_pin", export_pin == MDS_RANK_EPHEMERAL_DIST); | |
3074 | f->dump_bool("random_ephemeral_pin", export_pin == MDS_RANK_EPHEMERAL_RAND); | |
3075 | } | |
3076 | f->dump_int("export_pin_target", dir->get_export_pin(false)); | |
7c673cae FG |
3077 | f->open_object_section("dir"); |
3078 | dir->dump(f); | |
3079 | f->close_section(); | |
3080 | } | |
3081 | f->close_section(); | |
3082 | } | |
3083 | f->close_section(); | |
3084 | } | |
3085 | ||
3086 | ||
3087 | void MDSRank::command_export_dir(Formatter *f, | |
11fdf7f2 | 3088 | std::string_view path, |
7c673cae FG |
3089 | mds_rank_t target) |
3090 | { | |
3091 | int r = _command_export_dir(path, target); | |
3092 | f->open_object_section("results"); | |
3093 | f->dump_int("return_code", r); | |
3094 | f->close_section(); // results | |
3095 | } | |
3096 | ||
3097 | int MDSRank::_command_export_dir( | |
11fdf7f2 | 3098 | std::string_view path, |
7c673cae FG |
3099 | mds_rank_t target) |
3100 | { | |
11fdf7f2 | 3101 | std::lock_guard l(mds_lock); |
94b18763 | 3102 | filepath fp(path); |
7c673cae FG |
3103 | |
3104 | if (target == whoami || !mdsmap->is_up(target) || !mdsmap->is_in(target)) { | |
3105 | derr << "bad MDS target " << target << dendl; | |
f67539c2 | 3106 | return -CEPHFS_ENOENT; |
7c673cae FG |
3107 | } |
3108 | ||
3109 | CInode *in = mdcache->cache_traverse(fp); | |
3110 | if (!in) { | |
20effc67 | 3111 | derr << "bad path '" << path << "'" << dendl; |
f67539c2 | 3112 | return -CEPHFS_ENOENT; |
7c673cae FG |
3113 | } |
3114 | CDir *dir = in->get_dirfrag(frag_t()); | |
3115 | if (!dir || !(dir->is_auth())) { | |
3116 | derr << "bad export_dir path dirfrag frag_t() or dir not auth" << dendl; | |
f67539c2 | 3117 | return -CEPHFS_EINVAL; |
7c673cae FG |
3118 | } |
3119 | ||
3120 | mdcache->migrator->export_dir(dir, target); | |
3121 | return 0; | |
3122 | } | |
3123 | ||
11fdf7f2 TL |
3124 | void MDSRank::command_dump_tree(const cmdmap_t &cmdmap, std::ostream &ss, Formatter *f) |
3125 | { | |
3126 | std::string root; | |
3127 | int64_t depth; | |
9f95a23c | 3128 | cmd_getval(cmdmap, "root", root); |
20effc67 TL |
3129 | if (root.empty()) { |
3130 | root = "/"; | |
3131 | } | |
9f95a23c | 3132 | if (!cmd_getval(cmdmap, "depth", depth)) |
11fdf7f2 TL |
3133 | depth = -1; |
3134 | std::lock_guard l(mds_lock); | |
3135 | CInode *in = mdcache->cache_traverse(filepath(root.c_str())); | |
3136 | if (!in) { | |
3137 | ss << "root inode is not in cache"; | |
3138 | return; | |
3139 | } | |
3140 | f->open_array_section("inodes"); | |
3141 | mdcache->dump_tree(in, 0, depth, f); | |
3142 | f->close_section(); | |
3143 | } | |
3144 | ||
7c673cae FG |
3145 | CDir *MDSRank::_command_dirfrag_get( |
3146 | const cmdmap_t &cmdmap, | |
3147 | std::ostream &ss) | |
3148 | { | |
3149 | std::string path; | |
9f95a23c | 3150 | bool got = cmd_getval(cmdmap, "path", path); |
7c673cae FG |
3151 | if (!got) { |
3152 | ss << "missing path argument"; | |
3153 | return NULL; | |
3154 | } | |
3155 | ||
3156 | std::string frag_str; | |
9f95a23c | 3157 | if (!cmd_getval(cmdmap, "frag", frag_str)) { |
7c673cae FG |
3158 | ss << "missing frag argument"; |
3159 | return NULL; | |
3160 | } | |
3161 | ||
3162 | CInode *in = mdcache->cache_traverse(filepath(path.c_str())); | |
3163 | if (!in) { | |
3164 | // TODO really we should load something in if it's not in cache, | |
3165 | // but the infrastructure is harder, and we might still be unable | |
3166 | // to act on it if someone else is auth. | |
3167 | ss << "directory '" << path << "' inode not in cache"; | |
3168 | return NULL; | |
3169 | } | |
3170 | ||
3171 | frag_t fg; | |
3172 | ||
3173 | if (!fg.parse(frag_str.c_str())) { | |
3174 | ss << "frag " << frag_str << " failed to parse"; | |
3175 | return NULL; | |
3176 | } | |
3177 | ||
3178 | CDir *dir = in->get_dirfrag(fg); | |
3179 | if (!dir) { | |
11fdf7f2 | 3180 | ss << "frag " << in->ino() << "/" << fg << " not in cache (" |
7c673cae FG |
3181 | "use `dirfrag ls` to see if it should exist)"; |
3182 | return NULL; | |
3183 | } | |
3184 | ||
3185 | if (!dir->is_auth()) { | |
3186 | ss << "frag " << dir->dirfrag() << " not auth (auth = " | |
3187 | << dir->authority() << ")"; | |
3188 | return NULL; | |
3189 | } | |
3190 | ||
3191 | return dir; | |
3192 | } | |
3193 | ||
3194 | bool MDSRank::command_dirfrag_split( | |
3195 | cmdmap_t cmdmap, | |
3196 | std::ostream &ss) | |
3197 | { | |
11fdf7f2 | 3198 | std::lock_guard l(mds_lock); |
7c673cae | 3199 | int64_t by = 0; |
9f95a23c | 3200 | if (!cmd_getval(cmdmap, "bits", by)) { |
7c673cae FG |
3201 | ss << "missing bits argument"; |
3202 | return false; | |
3203 | } | |
3204 | ||
3205 | if (by <= 0) { | |
3206 | ss << "must split by >0 bits"; | |
3207 | return false; | |
3208 | } | |
3209 | ||
3210 | CDir *dir = _command_dirfrag_get(cmdmap, ss); | |
3211 | if (!dir) { | |
3212 | return false; | |
3213 | } | |
3214 | ||
3215 | mdcache->split_dir(dir, by); | |
3216 | ||
3217 | return true; | |
3218 | } | |
3219 | ||
3220 | bool MDSRank::command_dirfrag_merge( | |
3221 | cmdmap_t cmdmap, | |
3222 | std::ostream &ss) | |
3223 | { | |
11fdf7f2 | 3224 | std::lock_guard l(mds_lock); |
7c673cae | 3225 | std::string path; |
9f95a23c | 3226 | bool got = cmd_getval(cmdmap, "path", path); |
7c673cae FG |
3227 | if (!got) { |
3228 | ss << "missing path argument"; | |
3229 | return false; | |
3230 | } | |
3231 | ||
3232 | std::string frag_str; | |
9f95a23c | 3233 | if (!cmd_getval(cmdmap, "frag", frag_str)) { |
7c673cae FG |
3234 | ss << "missing frag argument"; |
3235 | return false; | |
3236 | } | |
3237 | ||
3238 | CInode *in = mdcache->cache_traverse(filepath(path.c_str())); | |
3239 | if (!in) { | |
3240 | ss << "directory '" << path << "' inode not in cache"; | |
3241 | return false; | |
3242 | } | |
3243 | ||
3244 | frag_t fg; | |
3245 | if (!fg.parse(frag_str.c_str())) { | |
3246 | ss << "frag " << frag_str << " failed to parse"; | |
3247 | return false; | |
3248 | } | |
3249 | ||
3250 | mdcache->merge_dir(in, fg); | |
3251 | ||
3252 | return true; | |
3253 | } | |
3254 | ||
3255 | bool MDSRank::command_dirfrag_ls( | |
3256 | cmdmap_t cmdmap, | |
3257 | std::ostream &ss, | |
3258 | Formatter *f) | |
3259 | { | |
11fdf7f2 | 3260 | std::lock_guard l(mds_lock); |
7c673cae | 3261 | std::string path; |
9f95a23c | 3262 | bool got = cmd_getval(cmdmap, "path", path); |
7c673cae FG |
3263 | if (!got) { |
3264 | ss << "missing path argument"; | |
3265 | return false; | |
3266 | } | |
3267 | ||
3268 | CInode *in = mdcache->cache_traverse(filepath(path.c_str())); | |
3269 | if (!in) { | |
3270 | ss << "directory inode not in cache"; | |
3271 | return false; | |
3272 | } | |
3273 | ||
3274 | f->open_array_section("frags"); | |
11fdf7f2 | 3275 | frag_vec_t leaves; |
7c673cae FG |
3276 | // NB using get_leaves_under instead of get_dirfrags to give |
3277 | // you the list of what dirfrags may exist, not which are in cache | |
11fdf7f2 TL |
3278 | in->dirfragtree.get_leaves_under(frag_t(), leaves); |
3279 | for (const auto& leaf : leaves) { | |
7c673cae | 3280 | f->open_object_section("frag"); |
11fdf7f2 TL |
3281 | f->dump_int("value", leaf.value()); |
3282 | f->dump_int("bits", leaf.bits()); | |
3283 | CachedStackStringStream css; | |
3284 | *css << std::hex << leaf.value() << "/" << std::dec << leaf.bits(); | |
3285 | f->dump_string("str", css->strv()); | |
7c673cae FG |
3286 | f->close_section(); |
3287 | } | |
3288 | f->close_section(); | |
3289 | ||
3290 | return true; | |
3291 | } | |
3292 | ||
11fdf7f2 TL |
3293 | void MDSRank::command_openfiles_ls(Formatter *f) |
3294 | { | |
3295 | std::lock_guard l(mds_lock); | |
3296 | mdcache->dump_openfiles(f); | |
3297 | } | |
3298 | ||
3299 | void MDSRank::command_dump_inode(Formatter *f, const cmdmap_t &cmdmap, std::ostream &ss) | |
3300 | { | |
3301 | std::lock_guard l(mds_lock); | |
3302 | int64_t number; | |
9f95a23c | 3303 | bool got = cmd_getval(cmdmap, "number", number); |
11fdf7f2 TL |
3304 | if (!got) { |
3305 | ss << "missing inode number"; | |
3306 | return; | |
3307 | } | |
3308 | ||
3309 | bool success = mdcache->dump_inode(f, number); | |
3310 | if (!success) { | |
3311 | ss << "dump inode failed, wrong inode number or the inode is not cached"; | |
3312 | } | |
3313 | } | |
3314 | ||
7c673cae FG |
3315 | void MDSRank::dump_status(Formatter *f) const |
3316 | { | |
20effc67 | 3317 | f->dump_string("fs_name", std::string(mdsmap->get_fs_name())); |
7c673cae FG |
3318 | if (state == MDSMap::STATE_REPLAY || |
3319 | state == MDSMap::STATE_STANDBY_REPLAY) { | |
3320 | mdlog->dump_replay_status(f); | |
3321 | } else if (state == MDSMap::STATE_RESOLVE) { | |
3322 | mdcache->dump_resolve_status(f); | |
3323 | } else if (state == MDSMap::STATE_RECONNECT) { | |
3324 | server->dump_reconnect_status(f); | |
3325 | } else if (state == MDSMap::STATE_REJOIN) { | |
3326 | mdcache->dump_rejoin_status(f); | |
3327 | } else if (state == MDSMap::STATE_CLIENTREPLAY) { | |
3328 | dump_clientreplay_status(f); | |
3329 | } | |
94b18763 | 3330 | f->dump_float("rank_uptime", get_uptime().count()); |
7c673cae FG |
3331 | } |
3332 | ||
3333 | void MDSRank::dump_clientreplay_status(Formatter *f) const | |
3334 | { | |
3335 | f->open_object_section("clientreplay_status"); | |
3336 | f->dump_unsigned("clientreplay_queue", replay_queue.size()); | |
3337 | f->dump_unsigned("active_replay", mdcache->get_num_client_requests()); | |
3338 | f->close_section(); | |
3339 | } | |
3340 | ||
3341 | void MDSRankDispatcher::update_log_config() | |
3342 | { | |
20effc67 TL |
3343 | auto parsed_options = clog->parse_client_options(g_ceph_context); |
3344 | dout(10) << __func__ << " log_to_monitors " << parsed_options.log_to_monitors << dendl; | |
7c673cae FG |
3345 | } |
3346 | ||
3347 | void MDSRank::create_logger() | |
3348 | { | |
3349 | dout(10) << "create_logger" << dendl; | |
3350 | { | |
3351 | PerfCountersBuilder mds_plb(g_ceph_context, "mds", l_mds_first, l_mds_last); | |
3352 | ||
91327a77 AA |
3353 | // super useful (high prio) perf stats |
3354 | mds_plb.add_u64_counter(l_mds_request, "request", "Requests", "req", | |
3355 | PerfCountersBuilder::PRIO_CRITICAL); | |
3356 | mds_plb.add_time_avg(l_mds_reply_latency, "reply_latency", "Reply latency", "rlat", | |
3357 | PerfCountersBuilder::PRIO_CRITICAL); | |
3358 | mds_plb.add_u64(l_mds_inodes, "inodes", "Inodes", "inos", | |
3359 | PerfCountersBuilder::PRIO_CRITICAL); | |
3360 | mds_plb.add_u64_counter(l_mds_forward, "forward", "Forwarding request", "fwd", | |
3361 | PerfCountersBuilder::PRIO_INTERESTING); | |
3362 | mds_plb.add_u64(l_mds_caps, "caps", "Capabilities", "caps", | |
3363 | PerfCountersBuilder::PRIO_INTERESTING); | |
3364 | mds_plb.add_u64_counter(l_mds_exported_inodes, "exported_inodes", "Exported inodes", | |
3365 | "exi", PerfCountersBuilder::PRIO_INTERESTING); | |
3366 | mds_plb.add_u64_counter(l_mds_imported_inodes, "imported_inodes", "Imported inodes", | |
3367 | "imi", PerfCountersBuilder::PRIO_INTERESTING); | |
33c7a0ef TL |
3368 | mds_plb.add_u64_counter(l_mds_slow_reply, "slow_reply", "Slow replies", "slr", |
3369 | PerfCountersBuilder::PRIO_INTERESTING); | |
91327a77 | 3370 | |
f67539c2 TL |
3371 | // caps msg stats |
3372 | mds_plb.add_u64_counter(l_mdss_handle_client_caps, "handle_client_caps", | |
3373 | "Client caps msg", "hcc", PerfCountersBuilder::PRIO_INTERESTING); | |
3374 | mds_plb.add_u64_counter(l_mdss_handle_client_caps_dirty, "handle_client_caps_dirty", | |
3375 | "Client dirty caps msg", "hccd", PerfCountersBuilder::PRIO_INTERESTING); | |
3376 | mds_plb.add_u64_counter(l_mdss_handle_client_cap_release, "handle_client_cap_release", | |
3377 | "Client cap release msg", "hccr", PerfCountersBuilder::PRIO_INTERESTING); | |
3378 | mds_plb.add_u64_counter(l_mdss_process_request_cap_release, "process_request_cap_release", | |
3379 | "Process request cap release", "prcr", PerfCountersBuilder::PRIO_INTERESTING); | |
3380 | mds_plb.add_u64_counter(l_mdss_ceph_cap_op_revoke, "ceph_cap_op_revoke", | |
3381 | "Revoke caps", "crev", PerfCountersBuilder::PRIO_INTERESTING); | |
3382 | mds_plb.add_u64_counter(l_mdss_ceph_cap_op_grant, "ceph_cap_op_grant", | |
3383 | "Grant caps", "cgra", PerfCountersBuilder::PRIO_INTERESTING); | |
3384 | mds_plb.add_u64_counter(l_mdss_ceph_cap_op_trunc, "ceph_cap_op_trunc", | |
3385 | "caps truncate notify", "ctru", PerfCountersBuilder::PRIO_INTERESTING); | |
3386 | mds_plb.add_u64_counter(l_mdss_ceph_cap_op_flushsnap_ack, "ceph_cap_op_flushsnap_ack", | |
3387 | "caps truncate notify", "cfsa", PerfCountersBuilder::PRIO_INTERESTING); | |
3388 | mds_plb.add_u64_counter(l_mdss_ceph_cap_op_flush_ack, "ceph_cap_op_flush_ack", | |
3389 | "caps truncate notify", "cfa", PerfCountersBuilder::PRIO_INTERESTING); | |
3390 | mds_plb.add_u64_counter(l_mdss_handle_inode_file_caps, "handle_inode_file_caps", | |
3391 | "Inter mds caps msg", "hifc", PerfCountersBuilder::PRIO_INTERESTING); | |
3392 | ||
91327a77 AA |
3393 | // useful dir/inode/subtree stats |
3394 | mds_plb.set_prio_default(PerfCountersBuilder::PRIO_USEFUL); | |
eafe8130 TL |
3395 | mds_plb.add_u64(l_mds_root_rfiles, "root_rfiles", "root inode rfiles"); |
3396 | mds_plb.add_u64(l_mds_root_rbytes, "root_rbytes", "root inode rbytes"); | |
3397 | mds_plb.add_u64(l_mds_root_rsnaps, "root_rsnaps", "root inode rsnaps"); | |
1e59de90 TL |
3398 | mds_plb.add_u64_counter(l_mds_dir_fetch_complete, |
3399 | "dir_fetch_complete", "Fetch complete dirfrag"); | |
3400 | mds_plb.add_u64_counter(l_mds_dir_fetch_keys, | |
3401 | "dir_fetch_keys", "Fetch keys from dirfrag"); | |
7c673cae FG |
3402 | mds_plb.add_u64_counter(l_mds_dir_commit, "dir_commit", "Directory commit"); |
3403 | mds_plb.add_u64_counter(l_mds_dir_split, "dir_split", "Directory split"); | |
3404 | mds_plb.add_u64_counter(l_mds_dir_merge, "dir_merge", "Directory merge"); | |
7c673cae FG |
3405 | mds_plb.add_u64(l_mds_inodes_pinned, "inodes_pinned", "Inodes pinned"); |
3406 | mds_plb.add_u64(l_mds_inodes_expired, "inodes_expired", "Inodes expired"); | |
91327a77 AA |
3407 | mds_plb.add_u64(l_mds_inodes_with_caps, "inodes_with_caps", |
3408 | "Inodes with capabilities"); | |
7c673cae | 3409 | mds_plb.add_u64(l_mds_subtrees, "subtrees", "Subtrees"); |
91327a77 | 3410 | mds_plb.add_u64(l_mds_load_cent, "load_cent", "Load per cent"); |
11fdf7f2 TL |
3411 | mds_plb.add_u64_counter(l_mds_openino_dir_fetch, "openino_dir_fetch", |
3412 | "OpenIno incomplete directory fetchings"); | |
7c673cae | 3413 | |
91327a77 AA |
3414 | // low prio stats |
3415 | mds_plb.set_prio_default(PerfCountersBuilder::PRIO_DEBUGONLY); | |
3416 | mds_plb.add_u64_counter(l_mds_reply, "reply", "Replies"); | |
3417 | mds_plb.add_u64(l_mds_inodes_top, "inodes_top", "Inodes on top"); | |
3418 | mds_plb.add_u64(l_mds_inodes_bottom, "inodes_bottom", "Inodes on bottom"); | |
3419 | mds_plb.add_u64( | |
3420 | l_mds_inodes_pin_tail, "inodes_pin_tail", "Inodes on pin tail"); | |
7c673cae FG |
3421 | mds_plb.add_u64_counter(l_mds_traverse, "traverse", "Traverses"); |
3422 | mds_plb.add_u64_counter(l_mds_traverse_hit, "traverse_hit", "Traverse hits"); | |
3423 | mds_plb.add_u64_counter(l_mds_traverse_forward, "traverse_forward", | |
91327a77 | 3424 | "Traverse forwards"); |
7c673cae | 3425 | mds_plb.add_u64_counter(l_mds_traverse_discover, "traverse_discover", |
91327a77 | 3426 | "Traverse directory discovers"); |
7c673cae | 3427 | mds_plb.add_u64_counter(l_mds_traverse_dir_fetch, "traverse_dir_fetch", |
91327a77 | 3428 | "Traverse incomplete directory content fetchings"); |
7c673cae | 3429 | mds_plb.add_u64_counter(l_mds_traverse_remote_ino, "traverse_remote_ino", |
91327a77 | 3430 | "Traverse remote dentries"); |
7c673cae | 3431 | mds_plb.add_u64_counter(l_mds_traverse_lock, "traverse_lock", |
91327a77 | 3432 | "Traverse locks"); |
7c673cae | 3433 | mds_plb.add_u64(l_mds_dispatch_queue_len, "q", "Dispatch queue length"); |
7c673cae | 3434 | mds_plb.add_u64_counter(l_mds_exported, "exported", "Exports"); |
7c673cae | 3435 | mds_plb.add_u64_counter(l_mds_imported, "imported", "Imports"); |
11fdf7f2 TL |
3436 | mds_plb.add_u64_counter(l_mds_openino_backtrace_fetch, "openino_backtrace_fetch", |
3437 | "OpenIno backtrace fetchings"); | |
3438 | mds_plb.add_u64_counter(l_mds_openino_peer_discover, "openino_peer_discover", | |
3439 | "OpenIno peer inode discovers"); | |
91327a77 | 3440 | |
f67539c2 TL |
3441 | // scrub stats |
3442 | mds_plb.add_u64(l_mds_scrub_backtrace_fetch, "scrub_backtrace_fetch", | |
3443 | "Scrub backtrace fetchings"); | |
3444 | mds_plb.add_u64(l_mds_scrub_set_tag, "scrub_set_tag", | |
3445 | "Scrub set tags"); | |
3446 | mds_plb.add_u64(l_mds_scrub_backtrace_repaired, "scrub_backtrace_repaired", | |
3447 | "Scrub backtraces repaired"); | |
3448 | mds_plb.add_u64(l_mds_scrub_inotable_repaired, "scrub_inotable_repaired", | |
3449 | "Scrub inotable repaired"); | |
3450 | mds_plb.add_u64(l_mds_scrub_dir_inodes, "scrub_dir_inodes", | |
3451 | "Scrub directory inodes"); | |
3452 | mds_plb.add_u64(l_mds_scrub_dir_base_inodes, "scrub_dir_base_inodes", | |
3453 | "Scrub directory base inodes"); | |
3454 | mds_plb.add_u64(l_mds_scrub_dirfrag_rstats, "scrub_dirfrag_rstats", | |
3455 | "Scrub dirfrags rstates"); | |
3456 | mds_plb.add_u64(l_mds_scrub_file_inodes, "scrub_file_inodes", | |
3457 | "Scrub file inodes"); | |
3458 | ||
7c673cae FG |
3459 | logger = mds_plb.create_perf_counters(); |
3460 | g_ceph_context->get_perfcounters_collection()->add(logger); | |
3461 | } | |
3462 | ||
3463 | { | |
3464 | PerfCountersBuilder mdm_plb(g_ceph_context, "mds_mem", l_mdm_first, l_mdm_last); | |
b32b8144 FG |
3465 | mdm_plb.add_u64(l_mdm_ino, "ino", "Inodes", "ino", |
3466 | PerfCountersBuilder::PRIO_INTERESTING); | |
91327a77 AA |
3467 | mdm_plb.add_u64(l_mdm_dn, "dn", "Dentries", "dn", |
3468 | PerfCountersBuilder::PRIO_INTERESTING); | |
3469 | ||
3470 | mdm_plb.set_prio_default(PerfCountersBuilder::PRIO_USEFUL); | |
7c673cae FG |
3471 | mdm_plb.add_u64_counter(l_mdm_inoa, "ino+", "Inodes opened"); |
3472 | mdm_plb.add_u64_counter(l_mdm_inos, "ino-", "Inodes closed"); | |
3473 | mdm_plb.add_u64(l_mdm_dir, "dir", "Directories"); | |
3474 | mdm_plb.add_u64_counter(l_mdm_dira, "dir+", "Directories opened"); | |
3475 | mdm_plb.add_u64_counter(l_mdm_dirs, "dir-", "Directories closed"); | |
7c673cae FG |
3476 | mdm_plb.add_u64_counter(l_mdm_dna, "dn+", "Dentries opened"); |
3477 | mdm_plb.add_u64_counter(l_mdm_dns, "dn-", "Dentries closed"); | |
3478 | mdm_plb.add_u64(l_mdm_cap, "cap", "Capabilities"); | |
3479 | mdm_plb.add_u64_counter(l_mdm_capa, "cap+", "Capabilities added"); | |
3480 | mdm_plb.add_u64_counter(l_mdm_caps, "cap-", "Capabilities removed"); | |
7c673cae | 3481 | mdm_plb.add_u64(l_mdm_heap, "heap", "Heap size"); |
91327a77 AA |
3482 | |
3483 | mdm_plb.set_prio_default(PerfCountersBuilder::PRIO_DEBUGONLY); | |
3484 | mdm_plb.add_u64(l_mdm_rss, "rss", "RSS"); | |
3485 | ||
7c673cae FG |
3486 | mlogger = mdm_plb.create_perf_counters(); |
3487 | g_ceph_context->get_perfcounters_collection()->add(mlogger); | |
3488 | } | |
3489 | ||
3490 | mdlog->create_logger(); | |
3491 | server->create_logger(); | |
3492 | purge_queue.create_logger(); | |
3493 | sessionmap.register_perfcounters(); | |
3494 | mdcache->register_perfcounters(); | |
3495 | } | |
3496 | ||
3497 | void MDSRank::check_ops_in_flight() | |
3498 | { | |
11fdf7f2 | 3499 | string summary; |
7c673cae FG |
3500 | vector<string> warnings; |
3501 | int slow = 0; | |
11fdf7f2 TL |
3502 | if (op_tracker.check_ops_in_flight(&summary, warnings, &slow)) { |
3503 | clog->warn() << summary; | |
3504 | for (const auto& warning : warnings) { | |
3505 | clog->warn() << warning; | |
7c673cae FG |
3506 | } |
3507 | } | |
3508 | ||
3509 | // set mds slow request count | |
3510 | mds_slow_req_count = slow; | |
3511 | return; | |
3512 | } | |
3513 | ||
3514 | void MDSRankDispatcher::handle_osd_map() | |
3515 | { | |
11fdf7f2 TL |
3516 | if (is_active() && |
3517 | mdsmap->get_tableserver() == whoami) { | |
7c673cae FG |
3518 | snapserver->check_osd_map(true); |
3519 | } | |
3520 | ||
3521 | server->handle_osd_map(); | |
3522 | ||
3523 | purge_queue.update_op_limit(*mdsmap); | |
3524 | ||
a4b75251 TL |
3525 | // it's ok if replay state is reached via standby-replay, the |
3526 | // reconnect state will journal blocklisted clients (journal | |
3527 | // is opened for writing in `replay_done` before moving to | |
3528 | // up:resolve). | |
2a845540 | 3529 | if (!is_any_replay()) { |
a4b75251 TL |
3530 | std::set<entity_addr_t> newly_blocklisted; |
3531 | objecter->consume_blocklist_events(&newly_blocklisted); | |
3532 | auto epoch = objecter->with_osdmap([](const OSDMap &o){return o.get_epoch();}); | |
3533 | apply_blocklist(newly_blocklisted, epoch); | |
31f18b77 FG |
3534 | } |
3535 | ||
7c673cae FG |
3536 | // By default the objecter only requests OSDMap updates on use, |
3537 | // we would like to always receive the latest maps in order to | |
3538 | // apply policy based on the FULL flag. | |
3539 | objecter->maybe_request_map(); | |
3540 | } | |
3541 | ||
92f5a8d4 TL |
3542 | int MDSRank::config_client(int64_t session_id, bool remove, |
3543 | const std::string& option, const std::string& value, | |
3544 | std::ostream& ss) | |
3545 | { | |
3546 | Session *session = sessionmap.get_session(entity_name_t(CEPH_ENTITY_TYPE_CLIENT, session_id)); | |
3547 | if (!session) { | |
3548 | ss << "session " << session_id << " not in sessionmap!"; | |
f67539c2 | 3549 | return -CEPHFS_ENOENT; |
92f5a8d4 TL |
3550 | } |
3551 | ||
3552 | if (option == "timeout") { | |
3553 | if (remove) { | |
3554 | auto it = session->info.client_metadata.find("timeout"); | |
3555 | if (it == session->info.client_metadata.end()) { | |
3556 | ss << "Nonexistent config: " << option; | |
f67539c2 | 3557 | return -CEPHFS_ENODATA; |
92f5a8d4 TL |
3558 | } |
3559 | session->info.client_metadata.erase(it); | |
3560 | } else { | |
3561 | char *end; | |
3562 | strtoul(value.c_str(), &end, 0); | |
3563 | if (*end) { | |
3564 | ss << "Invalid config for timeout: " << value; | |
f67539c2 | 3565 | return -CEPHFS_EINVAL; |
92f5a8d4 TL |
3566 | } |
3567 | session->info.client_metadata[option] = value; | |
3568 | } | |
3569 | //sessionmap._mark_dirty(session, true); | |
3570 | } else { | |
3571 | ss << "Invalid config option: " << option; | |
f67539c2 | 3572 | return -CEPHFS_EINVAL; |
92f5a8d4 TL |
3573 | } |
3574 | ||
3575 | return 0; | |
3576 | } | |
3577 | ||
31f18b77 | 3578 | bool MDSRank::evict_client(int64_t session_id, |
f67539c2 | 3579 | bool wait, bool blocklist, std::ostream& err_ss, |
31f18b77 | 3580 | Context *on_killed) |
7c673cae | 3581 | { |
9f95a23c | 3582 | ceph_assert(ceph_mutex_is_locked_by_me(mds_lock)); |
31f18b77 FG |
3583 | |
3584 | // Mutually exclusive args | |
11fdf7f2 | 3585 | ceph_assert(!(wait && on_killed != nullptr)); |
31f18b77 | 3586 | |
7c673cae FG |
3587 | if (is_any_replay()) { |
3588 | err_ss << "MDS is replaying log"; | |
3589 | return false; | |
3590 | } | |
3591 | ||
31f18b77 FG |
3592 | Session *session = sessionmap.get_session( |
3593 | entity_name_t(CEPH_ENTITY_TYPE_CLIENT, session_id)); | |
7c673cae FG |
3594 | if (!session) { |
3595 | err_ss << "session " << session_id << " not in sessionmap!"; | |
3596 | return false; | |
3597 | } | |
7c673cae | 3598 | |
a8e16298 TL |
3599 | auto& addr = session->info.inst.addr; |
3600 | { | |
11fdf7f2 | 3601 | CachedStackStringStream css; |
f67539c2 | 3602 | *css << "Evicting " << (blocklist ? "(and blocklisting) " : "") |
11fdf7f2 TL |
3603 | << "client session " << session_id << " (" << addr << ")"; |
3604 | dout(1) << css->strv() << dendl; | |
3605 | clog->info() << css->strv(); | |
a8e16298 TL |
3606 | } |
3607 | ||
f67539c2 TL |
3608 | dout(4) << "Preparing blocklist command... (wait=" << wait << ")" << dendl; |
3609 | CachedStackStringStream css; | |
3610 | *css << "{\"prefix\":\"osd blocklist\", \"blocklistop\":\"add\","; | |
3611 | *css << "\"addr\":\""; | |
3612 | *css << addr; | |
3613 | *css << "\"}"; | |
3614 | std::vector<std::string> cmd = {css->str()}; | |
31f18b77 | 3615 | |
91327a77 | 3616 | auto kill_client_session = [this, session_id, wait, on_killed](){ |
9f95a23c | 3617 | ceph_assert(ceph_mutex_is_locked_by_me(mds_lock)); |
31f18b77 FG |
3618 | Session *session = sessionmap.get_session( |
3619 | entity_name_t(CEPH_ENTITY_TYPE_CLIENT, session_id)); | |
3620 | if (session) { | |
91327a77 | 3621 | if (on_killed || !wait) { |
31f18b77 FG |
3622 | server->kill_session(session, on_killed); |
3623 | } else { | |
3624 | C_SaferCond on_safe; | |
3625 | server->kill_session(session, &on_safe); | |
3626 | ||
9f95a23c | 3627 | mds_lock.unlock(); |
31f18b77 | 3628 | on_safe.wait(); |
9f95a23c | 3629 | mds_lock.lock(); |
31f18b77 FG |
3630 | } |
3631 | } else { | |
3632 | dout(1) << "session " << session_id << " was removed while we waited " | |
f67539c2 | 3633 | "for blocklist" << dendl; |
31f18b77 FG |
3634 | |
3635 | // Even though it wasn't us that removed it, kick our completion | |
3636 | // as the session has been removed. | |
3637 | if (on_killed) { | |
3638 | on_killed->complete(0); | |
3639 | } | |
3640 | } | |
3641 | }; | |
3642 | ||
f67539c2 | 3643 | auto apply_blocklist = [this, cmd](std::function<void ()> fn){ |
9f95a23c | 3644 | ceph_assert(ceph_mutex_is_locked_by_me(mds_lock)); |
31f18b77 | 3645 | |
f67539c2 | 3646 | Context *on_blocklist_done = new LambdaContext([this, fn](int r) { |
31f18b77 | 3647 | objecter->wait_for_latest_osdmap( |
f67539c2 | 3648 | lambdafy((new C_OnFinisher( |
9f95a23c | 3649 | new LambdaContext([this, fn](int r) { |
11fdf7f2 | 3650 | std::lock_guard l(mds_lock); |
31f18b77 FG |
3651 | auto epoch = objecter->with_osdmap([](const OSDMap &o){ |
3652 | return o.get_epoch(); | |
3653 | }); | |
3654 | ||
3655 | set_osd_epoch_barrier(epoch); | |
3656 | ||
3657 | fn(); | |
3658 | }), finisher) | |
f67539c2 | 3659 | ))); |
31f18b77 FG |
3660 | }); |
3661 | ||
f67539c2 TL |
3662 | dout(4) << "Sending mon blocklist command: " << cmd[0] << dendl; |
3663 | monc->start_mon_command(cmd, {}, nullptr, nullptr, on_blocklist_done); | |
31f18b77 FG |
3664 | }; |
3665 | ||
31f18b77 | 3666 | if (wait) { |
f67539c2 | 3667 | if (blocklist) { |
91327a77 | 3668 | C_SaferCond inline_ctx; |
f67539c2 | 3669 | apply_blocklist([&inline_ctx](){inline_ctx.complete(0);}); |
9f95a23c | 3670 | mds_lock.unlock(); |
91327a77 | 3671 | inline_ctx.wait(); |
9f95a23c | 3672 | mds_lock.lock(); |
31f18b77 FG |
3673 | } |
3674 | ||
3675 | // We dropped mds_lock, so check that session still exists | |
3676 | session = sessionmap.get_session(entity_name_t(CEPH_ENTITY_TYPE_CLIENT, | |
11fdf7f2 | 3677 | session_id)); |
31f18b77 FG |
3678 | if (!session) { |
3679 | dout(1) << "session " << session_id << " was removed while we waited " | |
f67539c2 | 3680 | "for blocklist" << dendl; |
1e59de90 | 3681 | client_eviction_dump = true; |
31f18b77 FG |
3682 | return true; |
3683 | } | |
91327a77 | 3684 | kill_client_session(); |
7c673cae | 3685 | } else { |
f67539c2 TL |
3686 | if (blocklist) { |
3687 | apply_blocklist(kill_client_session); | |
31f18b77 | 3688 | } else { |
91327a77 | 3689 | kill_client_session(); |
31f18b77 | 3690 | } |
7c673cae | 3691 | } |
31f18b77 | 3692 | |
1e59de90 | 3693 | client_eviction_dump = true; |
7c673cae FG |
3694 | return true; |
3695 | } | |
3696 | ||
7c673cae FG |
3697 | MDSRankDispatcher::MDSRankDispatcher( |
3698 | mds_rank_t whoami_, | |
a4b75251 | 3699 | ceph::fair_mutex &mds_lock_, |
7c673cae | 3700 | LogChannelRef &clog_, |
a4b75251 | 3701 | CommonSafeTimer<ceph::fair_mutex> &timer_, |
7c673cae | 3702 | Beacon &beacon_, |
11fdf7f2 | 3703 | std::unique_ptr<MDSMap> &mdsmap_, |
7c673cae FG |
3704 | Messenger *msgr, |
3705 | MonClient *monc_, | |
9f95a23c | 3706 | MgrClient *mgrc, |
7c673cae | 3707 | Context *respawn_hook_, |
f67539c2 TL |
3708 | Context *suicide_hook_, |
3709 | boost::asio::io_context& ioc) | |
20effc67 | 3710 | : MDSRank(whoami_, mds_lock_, clog_, timer_, beacon_, mdsmap_, |
f67539c2 | 3711 | msgr, monc_, mgrc, respawn_hook_, suicide_hook_, ioc) |
92f5a8d4 | 3712 | { |
9f95a23c | 3713 | g_conf().add_observer(this); |
7c673cae FG |
3714 | } |
3715 | ||
f64942e4 AA |
3716 | void MDSRank::command_cache_drop(uint64_t timeout, Formatter *f, Context *on_finish) { |
3717 | dout(20) << __func__ << dendl; | |
3718 | ||
11fdf7f2 | 3719 | std::lock_guard locker(mds_lock); |
f64942e4 AA |
3720 | C_Drop_Cache *request = new C_Drop_Cache(server, mdcache, mdlog, this, |
3721 | timeout, f, on_finish); | |
3722 | request->send(); | |
3723 | } | |
3724 | ||
7c673cae FG |
3725 | epoch_t MDSRank::get_osd_epoch() const |
3726 | { | |
3727 | return objecter->with_osdmap(std::mem_fn(&OSDMap::get_epoch)); | |
3728 | } | |
3729 | ||
92f5a8d4 TL |
3730 | const char** MDSRankDispatcher::get_tracked_conf_keys() const |
3731 | { | |
3732 | static const char* KEYS[] = { | |
3733 | "clog_to_graylog", | |
3734 | "clog_to_graylog_host", | |
3735 | "clog_to_graylog_port", | |
3736 | "clog_to_monitors", | |
3737 | "clog_to_syslog", | |
3738 | "clog_to_syslog_facility", | |
3739 | "clog_to_syslog_level", | |
3740 | "fsid", | |
3741 | "host", | |
3742 | "mds_bal_fragment_dirs", | |
3743 | "mds_bal_fragment_interval", | |
20effc67 | 3744 | "mds_bal_fragment_size_max", |
92f5a8d4 TL |
3745 | "mds_cache_memory_limit", |
3746 | "mds_cache_mid", | |
3747 | "mds_cache_reservation", | |
92f5a8d4 TL |
3748 | "mds_cache_trim_decay_rate", |
3749 | "mds_cap_revoke_eviction_timeout", | |
3750 | "mds_dump_cache_threshold_file", | |
3751 | "mds_dump_cache_threshold_formatter", | |
3752 | "mds_enable_op_tracker", | |
f6b5b4d7 TL |
3753 | "mds_export_ephemeral_random", |
3754 | "mds_export_ephemeral_random_max", | |
3755 | "mds_export_ephemeral_distributed", | |
92f5a8d4 TL |
3756 | "mds_health_cache_threshold", |
3757 | "mds_inject_migrator_session_race", | |
3758 | "mds_log_pause", | |
3759 | "mds_max_export_size", | |
3760 | "mds_max_purge_files", | |
9f95a23c | 3761 | "mds_forward_all_requests_to_auth", |
92f5a8d4 TL |
3762 | "mds_max_purge_ops", |
3763 | "mds_max_purge_ops_per_pg", | |
9f95a23c | 3764 | "mds_max_snaps_per_dir", |
92f5a8d4 TL |
3765 | "mds_op_complaint_time", |
3766 | "mds_op_history_duration", | |
3767 | "mds_op_history_size", | |
3768 | "mds_op_log_threshold", | |
3769 | "mds_recall_max_decay_rate", | |
3770 | "mds_recall_warning_decay_rate", | |
3771 | "mds_request_load_average_decay_rate", | |
3772 | "mds_session_cache_liveness_decay_rate", | |
33c7a0ef | 3773 | "mds_heartbeat_reset_grace", |
f67539c2 | 3774 | "mds_heartbeat_grace", |
adb31ebb TL |
3775 | "mds_session_cap_acquisition_decay_rate", |
3776 | "mds_max_caps_per_client", | |
3777 | "mds_session_cap_acquisition_throttle", | |
3778 | "mds_session_max_caps_throttle_ratio", | |
3779 | "mds_cap_acquisition_throttle_retry_request_time", | |
f67539c2 | 3780 | "mds_alternate_name_max", |
20effc67 TL |
3781 | "mds_dir_max_entries", |
3782 | "mds_symlink_recovery", | |
1e59de90 TL |
3783 | "mds_extraordinary_events_dump_interval", |
3784 | "mds_inject_rename_corrupt_dentry_first", | |
3785 | "mds_inject_journal_corrupt_dentry_first", | |
92f5a8d4 TL |
3786 | NULL |
3787 | }; | |
3788 | return KEYS; | |
3789 | } | |
3790 | ||
3791 | void MDSRankDispatcher::handle_conf_change(const ConfigProxy& conf, const std::set<std::string>& changed) | |
3792 | { | |
3793 | // XXX with or without mds_lock! | |
3794 | ||
33c7a0ef TL |
3795 | if (changed.count("mds_heartbeat_reset_grace")) { |
3796 | _heartbeat_reset_grace = conf.get_val<uint64_t>("mds_heartbeat_reset_grace"); | |
3797 | } | |
f67539c2 TL |
3798 | if (changed.count("mds_heartbeat_grace")) { |
3799 | heartbeat_grace = conf.get_val<double>("mds_heartbeat_grace"); | |
3800 | } | |
92f5a8d4 TL |
3801 | if (changed.count("mds_op_complaint_time") || changed.count("mds_op_log_threshold")) { |
3802 | op_tracker.set_complaint_and_threshold(conf->mds_op_complaint_time, conf->mds_op_log_threshold); | |
3803 | } | |
3804 | if (changed.count("mds_op_history_size") || changed.count("mds_op_history_duration")) { | |
3805 | op_tracker.set_history_size_and_duration(conf->mds_op_history_size, conf->mds_op_history_duration); | |
3806 | } | |
3807 | if (changed.count("mds_enable_op_tracker")) { | |
3808 | op_tracker.set_tracking(conf->mds_enable_op_tracker); | |
3809 | } | |
1e59de90 TL |
3810 | if (changed.count("mds_extraordinary_events_dump_interval")) { |
3811 | reset_event_flags(); | |
3812 | extraordinary_events_dump_interval = conf.get_val<std::chrono::seconds> | |
3813 | ("mds_extraordinary_events_dump_interval").count(); | |
3814 | ||
3815 | //Enable the logging only during low level debugging | |
3816 | if (extraordinary_events_dump_interval) { | |
3817 | uint64_t log_level, gather_level; | |
3818 | std::string debug_mds = g_conf().get_val<std::string>("debug_mds"); | |
3819 | auto delim = debug_mds.find("/"); | |
3820 | std::istringstream(debug_mds.substr(0, delim)) >> log_level; | |
3821 | std::istringstream(debug_mds.substr(delim + 1)) >> gather_level; | |
3822 | ||
3823 | if (log_level < 10 && gather_level >= 10) { | |
3824 | dout(0) << __func__ << " Enabling in-memory log dump..." << dendl; | |
3825 | std::scoped_lock lock(mds_lock); | |
3826 | schedule_inmemory_logger(); | |
3827 | } | |
3828 | else { | |
3829 | dout(0) << __func__ << " Enabling in-memory log dump failed. debug_mds=" << log_level | |
3830 | << "/" << gather_level << dendl; | |
3831 | extraordinary_events_dump_interval = 0; | |
3832 | } | |
3833 | } | |
3834 | else { | |
3835 | //The user set mds_extraordinary_events_dump_interval = 0 | |
3836 | dout(0) << __func__ << " In-memory log dump disabled" << dendl; | |
3837 | } | |
3838 | } | |
92f5a8d4 TL |
3839 | if (changed.count("clog_to_monitors") || |
3840 | changed.count("clog_to_syslog") || | |
3841 | changed.count("clog_to_syslog_level") || | |
3842 | changed.count("clog_to_syslog_facility") || | |
3843 | changed.count("clog_to_graylog") || | |
3844 | changed.count("clog_to_graylog_host") || | |
3845 | changed.count("clog_to_graylog_port") || | |
3846 | changed.count("host") || | |
3847 | changed.count("fsid")) { | |
3848 | update_log_config(); | |
3849 | } | |
1e59de90 TL |
3850 | if (changed.count("mds_inject_journal_corrupt_dentry_first")) { |
3851 | inject_journal_corrupt_dentry_first = g_conf().get_val<double>("mds_inject_journal_corrupt_dentry_first"); | |
3852 | } | |
92f5a8d4 | 3853 | |
9f95a23c | 3854 | finisher->queue(new LambdaContext([this, changed](int) { |
92f5a8d4 TL |
3855 | std::scoped_lock lock(mds_lock); |
3856 | ||
f6b5b4d7 TL |
3857 | dout(10) << "flushing conf change to components: " << changed << dendl; |
3858 | ||
92f5a8d4 TL |
3859 | if (changed.count("mds_log_pause") && !g_conf()->mds_log_pause) { |
3860 | mdlog->kick_submitter(); | |
3861 | } | |
3862 | sessionmap.handle_conf_change(changed); | |
3863 | server->handle_conf_change(changed); | |
3864 | mdcache->handle_conf_change(changed, *mdsmap); | |
3865 | purge_queue.handle_conf_change(changed, *mdsmap); | |
3866 | })); | |
3867 | } | |
9f95a23c TL |
3868 | |
3869 | void MDSRank::get_task_status(std::map<std::string, std::string> *status) { | |
3870 | dout(20) << __func__ << dendl; | |
3871 | ||
3872 | // scrub summary for now.. | |
3873 | std::string_view scrub_summary = scrubstack->scrub_summary(); | |
f91f0fd5 TL |
3874 | if (!ScrubStack::is_idle(scrub_summary)) { |
3875 | send_status = true; | |
3876 | status->emplace(SCRUB_STATUS_KEY, std::move(scrub_summary)); | |
3877 | } | |
9f95a23c TL |
3878 | } |
3879 | ||
3880 | void MDSRank::schedule_update_timer_task() { | |
3881 | dout(20) << __func__ << dendl; | |
3882 | ||
3883 | timer.add_event_after(g_conf().get_val<double>("mds_task_status_update_interval"), | |
3884 | new LambdaContext([this](int) { | |
3885 | send_task_status(); | |
3886 | })); | |
3887 | } | |
3888 | ||
3889 | void MDSRank::send_task_status() { | |
3890 | std::map<std::string, std::string> status; | |
3891 | get_task_status(&status); | |
3892 | ||
f91f0fd5 TL |
3893 | if (send_status) { |
3894 | if (status.empty()) { | |
3895 | send_status = false; | |
3896 | } | |
9f95a23c | 3897 | |
f91f0fd5 | 3898 | dout(20) << __func__ << ": updating " << status.size() << " status keys" << dendl; |
9f95a23c TL |
3899 | int r = mgrc->service_daemon_update_task_status(std::move(status)); |
3900 | if (r < 0) { | |
3901 | derr << ": failed to update service daemon status: " << cpp_strerror(r) << dendl; | |
3902 | } | |
f91f0fd5 | 3903 | |
9f95a23c TL |
3904 | } |
3905 | ||
3906 | schedule_update_timer_task(); | |
3907 | } | |
1e59de90 TL |
3908 | |
3909 | void MDSRank::schedule_inmemory_logger() { | |
3910 | dout(20) << __func__ << dendl; | |
3911 | timer.add_event_after(extraordinary_events_dump_interval, | |
3912 | new LambdaContext([this]() { | |
3913 | inmemory_logger(); | |
3914 | })); | |
3915 | } | |
3916 | ||
3917 | void MDSRank::inmemory_logger() { | |
3918 | if (client_eviction_dump || | |
3919 | beacon.missed_beacon_ack_dump || | |
3920 | beacon.missed_internal_heartbeat_dump) { | |
3921 | //dump the in-memory logs if any of these events occured recently | |
3922 | dout(0) << __func__ << " client_eviction_dump "<< client_eviction_dump | |
3923 | << ", missed_beacon_ack_dump " << beacon.missed_beacon_ack_dump | |
3924 | << ", missed_internal_heartbeat_dump " << beacon.missed_internal_heartbeat_dump | |
3925 | << dendl; | |
3926 | reset_event_flags(); | |
3927 | g_ceph_context->_log->dump_recent(); | |
3928 | } | |
3929 | ||
3930 | //reschedule if it's enabled | |
3931 | if (extraordinary_events_dump_interval) { | |
3932 | schedule_inmemory_logger(); | |
3933 | } | |
3934 | } | |
3935 | ||
3936 | void MDSRank::reset_event_flags() { | |
3937 | client_eviction_dump = false; | |
3938 | beacon.missed_beacon_ack_dump = false; | |
3939 | beacon.missed_internal_heartbeat_dump = false; | |
3940 | } |