]>
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 | ||
22 | class MOSDFailure : public PaxosServiceMessage { | |
23 | ||
24 | static const int HEAD_VERSION = 3; | |
25 | static const int COMPAT_VERSION = 3; | |
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; | |
35 | entity_inst_t target_osd; | |
d2e6a577 FG |
36 | __u8 flags = 0; |
37 | epoch_t epoch = 0; | |
38 | int32_t failed_for = 0; // known to be failed since at least this long | |
7c673cae FG |
39 | |
40 | MOSDFailure() : PaxosServiceMessage(MSG_OSD_FAILURE, 0, HEAD_VERSION) { } | |
41 | MOSDFailure(const uuid_d &fs, const entity_inst_t& f, int duration, epoch_t e) | |
42 | : PaxosServiceMessage(MSG_OSD_FAILURE, e, HEAD_VERSION, COMPAT_VERSION), | |
43 | fsid(fs), target_osd(f), | |
44 | flags(FLAG_FAILED), | |
45 | epoch(e), failed_for(duration) { } | |
46 | MOSDFailure(const uuid_d &fs, const entity_inst_t& f, int duration, | |
47 | epoch_t e, __u8 extra_flags) | |
48 | : PaxosServiceMessage(MSG_OSD_FAILURE, e, HEAD_VERSION, COMPAT_VERSION), | |
49 | fsid(fs), target_osd(f), | |
50 | flags(extra_flags), | |
51 | epoch(e), failed_for(duration) { } | |
52 | private: | |
53 | ~MOSDFailure() override {} | |
54 | ||
55 | public: | |
56 | entity_inst_t get_target() { return target_osd; } | |
57 | bool if_osd_failed() const { | |
58 | return flags & FLAG_FAILED; | |
59 | } | |
60 | bool is_immediate() const { | |
61 | return flags & FLAG_IMMEDIATE; | |
62 | } | |
63 | epoch_t get_epoch() const { return epoch; } | |
64 | ||
65 | void decode_payload() override { | |
66 | bufferlist::iterator p = payload.begin(); | |
67 | paxos_decode(p); | |
68 | ::decode(fsid, p); | |
69 | ::decode(target_osd, p); | |
70 | ::decode(epoch, p); | |
71 | ::decode(flags, p); | |
72 | ::decode(failed_for, p); | |
73 | } | |
74 | ||
75 | void encode_payload(uint64_t features) override { | |
76 | paxos_encode(); | |
77 | ::encode(fsid, payload); | |
78 | ::encode(target_osd, payload, features); | |
79 | ::encode(epoch, payload); | |
80 | ::encode(flags, payload); | |
81 | ::encode(failed_for, payload); | |
82 | } | |
83 | ||
84 | const char *get_type_name() const override { return "osd_failure"; } | |
85 | void print(ostream& out) const override { | |
86 | out << "osd_failure(" | |
87 | << (if_osd_failed() ? "failed " : "recovered ") | |
88 | << (is_immediate() ? "immediate " : "timeout ") | |
89 | << target_osd << " for " << failed_for << "sec e" << epoch | |
90 | << " v" << version << ")"; | |
91 | } | |
92 | }; | |
93 | ||
94 | #endif |