1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
16 #ifndef CEPH_MOSDFAILURE_H
17 #define CEPH_MOSDFAILURE_H
19 #include "messages/PaxosServiceMessage.h"
22 class MOSDFailure
: public MessageInstance
<MOSDFailure
, PaxosServiceMessage
> {
26 static constexpr int HEAD_VERSION
= 4;
27 static constexpr int COMPAT_VERSION
= 4;
31 FLAG_ALIVE
= 0, // use this on its own to mark as "I'm still alive"
32 FLAG_FAILED
= 1, // if set, failure; if not, recovery
33 FLAG_IMMEDIATE
= 2, // known failure, not a timeout
38 entity_addrvec_t target_addrs
;
41 int32_t failed_for
= 0; // known to be failed since at least this long
43 MOSDFailure() : MessageInstance(MSG_OSD_FAILURE
, 0, HEAD_VERSION
) { }
44 MOSDFailure(const uuid_d
&fs
, int osd
, const entity_addrvec_t
& av
,
45 int duration
, epoch_t e
)
46 : MessageInstance(MSG_OSD_FAILURE
, e
, HEAD_VERSION
, COMPAT_VERSION
),
51 epoch(e
), failed_for(duration
) { }
52 MOSDFailure(const uuid_d
&fs
, int osd
, const entity_addrvec_t
& av
,
54 epoch_t e
, __u8 extra_flags
)
55 : MessageInstance(MSG_OSD_FAILURE
, e
, HEAD_VERSION
, COMPAT_VERSION
),
60 epoch(e
), failed_for(duration
) { }
62 ~MOSDFailure() override
{}
65 int get_target_osd() { return target_osd
; }
66 const entity_addrvec_t
& get_target_addrs() { return target_addrs
; }
67 bool if_osd_failed() const {
68 return flags
& FLAG_FAILED
;
70 bool is_immediate() const {
71 return flags
& FLAG_IMMEDIATE
;
73 epoch_t
get_epoch() const { return epoch
; }
75 void decode_payload() override
{
76 auto p
= payload
.cbegin();
79 if (header
.version
< 4) {
82 target_osd
= i
.name
.num();
83 target_addrs
.v
.push_back(i
.addr
);
85 decode(target_osd
, p
);
86 decode(target_addrs
, p
);
90 decode(failed_for
, p
);
93 void encode_payload(uint64_t features
) override
{
96 if (!HAVE_FEATURE(features
, SERVER_NAUTILUS
)) {
98 header
.compat_version
= 3;
99 encode(fsid
, payload
);
100 encode(entity_inst_t(entity_name_t::OSD(target_osd
),
101 target_addrs
.legacy_addr()), payload
, features
);
102 encode(epoch
, payload
);
103 encode(flags
, payload
);
104 encode(failed_for
, payload
);
107 header
.version
= HEAD_VERSION
;
108 header
.compat_version
= COMPAT_VERSION
;
109 encode(fsid
, payload
);
110 encode(target_osd
, payload
, features
);
111 encode(target_addrs
, payload
, features
);
112 encode(epoch
, payload
);
113 encode(flags
, payload
);
114 encode(failed_for
, payload
);
117 std::string_view
get_type_name() const override
{ return "osd_failure"; }
118 void print(ostream
& out
) const override
{
119 out
<< "osd_failure("
120 << (if_osd_failed() ? "failed " : "recovered ")
121 << (is_immediate() ? "immediate " : "timeout ")
122 << "osd." << target_osd
<< " " << target_addrs
123 << " for " << failed_for
<< "sec e" << epoch
124 << " v" << version
<< ")";