]>
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) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | ||
16 | #ifndef CEPH_MOSDFAILURE_H | |
17 | #define CEPH_MOSDFAILURE_H | |
18 | ||
19 | #include "messages/PaxosServiceMessage.h" | |
20 | ||
21 | ||
f67539c2 | 22 | class MOSDFailure final : public PaxosServiceMessage { |
11fdf7f2 TL |
23 | private: |
24 | static constexpr int HEAD_VERSION = 4; | |
25 | static constexpr int COMPAT_VERSION = 4; | |
7c673cae FG |
26 | |
27 | public: | |
28 | enum { | |
29 | FLAG_ALIVE = 0, // use this on its own to mark as "I'm still alive" | |
30 | FLAG_FAILED = 1, // if set, failure; if not, recovery | |
31 | FLAG_IMMEDIATE = 2, // known failure, not a timeout | |
32 | }; | |
33 | ||
34 | uuid_d fsid; | |
11fdf7f2 TL |
35 | int32_t target_osd; |
36 | entity_addrvec_t target_addrs; | |
d2e6a577 | 37 | __u8 flags = 0; |
11fdf7f2 | 38 | epoch_t epoch = 0; |
d2e6a577 | 39 | int32_t failed_for = 0; // known to be failed since at least this long |
7c673cae | 40 | |
9f95a23c | 41 | MOSDFailure() : PaxosServiceMessage(MSG_OSD_FAILURE, 0, HEAD_VERSION) { } |
11fdf7f2 TL |
42 | MOSDFailure(const uuid_d &fs, int osd, const entity_addrvec_t& av, |
43 | int duration, epoch_t e) | |
9f95a23c | 44 | : PaxosServiceMessage(MSG_OSD_FAILURE, e, HEAD_VERSION, COMPAT_VERSION), |
11fdf7f2 TL |
45 | fsid(fs), |
46 | target_osd(osd), | |
47 | target_addrs(av), | |
7c673cae FG |
48 | flags(FLAG_FAILED), |
49 | epoch(e), failed_for(duration) { } | |
11fdf7f2 TL |
50 | MOSDFailure(const uuid_d &fs, int osd, const entity_addrvec_t& av, |
51 | int duration, | |
7c673cae | 52 | epoch_t e, __u8 extra_flags) |
9f95a23c | 53 | : PaxosServiceMessage(MSG_OSD_FAILURE, e, HEAD_VERSION, COMPAT_VERSION), |
11fdf7f2 TL |
54 | fsid(fs), |
55 | target_osd(osd), | |
56 | target_addrs(av), | |
7c673cae FG |
57 | flags(extra_flags), |
58 | epoch(e), failed_for(duration) { } | |
59 | private: | |
f67539c2 | 60 | ~MOSDFailure() final {} |
7c673cae | 61 | |
11fdf7f2 TL |
62 | public: |
63 | int get_target_osd() { return target_osd; } | |
64 | const entity_addrvec_t& get_target_addrs() { return target_addrs; } | |
7c673cae FG |
65 | bool if_osd_failed() const { |
66 | return flags & FLAG_FAILED; | |
67 | } | |
68 | bool is_immediate() const { | |
69 | return flags & FLAG_IMMEDIATE; | |
70 | } | |
71 | epoch_t get_epoch() const { return epoch; } | |
72 | ||
73 | void decode_payload() override { | |
f67539c2 | 74 | using ceph::decode; |
11fdf7f2 | 75 | auto p = payload.cbegin(); |
7c673cae | 76 | paxos_decode(p); |
11fdf7f2 TL |
77 | decode(fsid, p); |
78 | if (header.version < 4) { | |
79 | entity_inst_t i; | |
80 | decode(i, p); | |
81 | target_osd = i.name.num(); | |
82 | target_addrs.v.push_back(i.addr); | |
83 | } else { | |
84 | decode(target_osd, p); | |
85 | decode(target_addrs, p); | |
86 | } | |
87 | decode(epoch, p); | |
88 | decode(flags, p); | |
89 | decode(failed_for, p); | |
7c673cae FG |
90 | } |
91 | ||
92 | void encode_payload(uint64_t features) override { | |
11fdf7f2 | 93 | using ceph::encode; |
7c673cae | 94 | paxos_encode(); |
11fdf7f2 TL |
95 | if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) { |
96 | header.version = 3; | |
97 | header.compat_version = 3; | |
98 | encode(fsid, payload); | |
99 | encode(entity_inst_t(entity_name_t::OSD(target_osd), | |
100 | target_addrs.legacy_addr()), payload, features); | |
101 | encode(epoch, payload); | |
102 | encode(flags, payload); | |
103 | encode(failed_for, payload); | |
104 | return; | |
105 | } | |
106 | header.version = HEAD_VERSION; | |
107 | header.compat_version = COMPAT_VERSION; | |
108 | encode(fsid, payload); | |
109 | encode(target_osd, payload, features); | |
110 | encode(target_addrs, payload, features); | |
111 | encode(epoch, payload); | |
112 | encode(flags, payload); | |
113 | encode(failed_for, payload); | |
7c673cae FG |
114 | } |
115 | ||
11fdf7f2 | 116 | std::string_view get_type_name() const override { return "osd_failure"; } |
f67539c2 | 117 | void print(std::ostream& out) const override { |
7c673cae FG |
118 | out << "osd_failure(" |
119 | << (if_osd_failed() ? "failed " : "recovered ") | |
120 | << (is_immediate() ? "immediate " : "timeout ") | |
11fdf7f2 TL |
121 | << "osd." << target_osd << " " << target_addrs |
122 | << " for " << failed_for << "sec e" << epoch | |
7c673cae FG |
123 | << " v" << version << ")"; |
124 | } | |
9f95a23c TL |
125 | private: |
126 | template<class T, typename... Args> | |
127 | friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); | |
7c673cae FG |
128 | }; |
129 | ||
130 | #endif |