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 PaxosServiceMessage
{
24 static constexpr int HEAD_VERSION
= 4;
25 static constexpr int COMPAT_VERSION
= 4;
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
36 entity_addrvec_t target_addrs
;
39 int32_t failed_for
= 0; // known to be failed since at least this long
41 MOSDFailure() : PaxosServiceMessage(MSG_OSD_FAILURE
, 0, HEAD_VERSION
) { }
42 MOSDFailure(const uuid_d
&fs
, int osd
, const entity_addrvec_t
& av
,
43 int duration
, epoch_t e
)
44 : PaxosServiceMessage(MSG_OSD_FAILURE
, e
, HEAD_VERSION
, COMPAT_VERSION
),
49 epoch(e
), failed_for(duration
) { }
50 MOSDFailure(const uuid_d
&fs
, int osd
, const entity_addrvec_t
& av
,
52 epoch_t e
, __u8 extra_flags
)
53 : PaxosServiceMessage(MSG_OSD_FAILURE
, e
, HEAD_VERSION
, COMPAT_VERSION
),
58 epoch(e
), failed_for(duration
) { }
60 ~MOSDFailure() override
{}
63 int get_target_osd() { return target_osd
; }
64 const entity_addrvec_t
& get_target_addrs() { return target_addrs
; }
65 bool if_osd_failed() const {
66 return flags
& FLAG_FAILED
;
68 bool is_immediate() const {
69 return flags
& FLAG_IMMEDIATE
;
71 epoch_t
get_epoch() const { return epoch
; }
73 void decode_payload() override
{
74 auto p
= payload
.cbegin();
77 if (header
.version
< 4) {
80 target_osd
= i
.name
.num();
81 target_addrs
.v
.push_back(i
.addr
);
83 decode(target_osd
, p
);
84 decode(target_addrs
, p
);
88 decode(failed_for
, p
);
91 void encode_payload(uint64_t features
) override
{
94 if (!HAVE_FEATURE(features
, SERVER_NAUTILUS
)) {
96 header
.compat_version
= 3;
97 encode(fsid
, payload
);
98 encode(entity_inst_t(entity_name_t::OSD(target_osd
),
99 target_addrs
.legacy_addr()), payload
, features
);
100 encode(epoch
, payload
);
101 encode(flags
, payload
);
102 encode(failed_for
, payload
);
105 header
.version
= HEAD_VERSION
;
106 header
.compat_version
= COMPAT_VERSION
;
107 encode(fsid
, payload
);
108 encode(target_osd
, payload
, features
);
109 encode(target_addrs
, payload
, features
);
110 encode(epoch
, payload
);
111 encode(flags
, payload
);
112 encode(failed_for
, payload
);
115 std::string_view
get_type_name() const override
{ return "osd_failure"; }
116 void print(ostream
& out
) const override
{
117 out
<< "osd_failure("
118 << (if_osd_failed() ? "failed " : "recovered ")
119 << (is_immediate() ? "immediate " : "timeout ")
120 << "osd." << target_osd
<< " " << target_addrs
121 << " for " << failed_for
<< "sec e" << epoch
122 << " v" << version
<< ")";
125 template<class T
, typename
... Args
>
126 friend boost::intrusive_ptr
<T
> ceph::make_message(Args
&&... args
);