]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MRecoveryReserve.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / messages / MRecoveryReserve.h
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 #ifndef CEPH_MRECOVERY_H
16 #define CEPH_MRECOVERY_H
17
18 #include "msg/Message.h"
19 #include "messages/MOSDPeeringOp.h"
20
21 class MRecoveryReserve : public MessageInstance<MRecoveryReserve, MOSDPeeringOp> {
22 public:
23 friend factory;
24 private:
25 static constexpr int HEAD_VERSION = 3;
26 static constexpr int COMPAT_VERSION = 2;
27 public:
28 spg_t pgid;
29 epoch_t query_epoch;
30 enum {
31 REQUEST = 0, // primary->replica: please reserve slot
32 GRANT = 1, // replica->primary: ok, i reserved it
33 RELEASE = 2, // primary->replica: release the slot i reserved before
34 REVOKE = 3, // replica->primary: i'm taking back the slot i gave you
35 };
36 uint32_t type;
37 uint32_t priority = 0;
38
39 spg_t get_spg() const {
40 return pgid;
41 }
42 epoch_t get_map_epoch() const {
43 return query_epoch;
44 }
45 epoch_t get_min_epoch() const {
46 return query_epoch;
47 }
48
49 PGPeeringEvent *get_event() override {
50 switch (type) {
51 case REQUEST:
52 return new PGPeeringEvent(
53 query_epoch,
54 query_epoch,
55 RequestRecoveryPrio(priority));
56 case GRANT:
57 return new PGPeeringEvent(
58 query_epoch,
59 query_epoch,
60 RemoteRecoveryReserved());
61 case RELEASE:
62 return new PGPeeringEvent(
63 query_epoch,
64 query_epoch,
65 RecoveryDone());
66 case REVOKE:
67 return new PGPeeringEvent(
68 query_epoch,
69 query_epoch,
70 DeferRecovery(0.0));
71 default:
72 ceph_abort();
73 }
74 }
75
76 MRecoveryReserve()
77 : MessageInstance(MSG_OSD_RECOVERY_RESERVE, HEAD_VERSION, COMPAT_VERSION),
78 query_epoch(0), type(-1) {}
79 MRecoveryReserve(int type,
80 spg_t pgid,
81 epoch_t query_epoch,
82 unsigned prio = 0)
83 : MessageInstance(MSG_OSD_RECOVERY_RESERVE, HEAD_VERSION, COMPAT_VERSION),
84 pgid(pgid), query_epoch(query_epoch),
85 type(type), priority(prio) {}
86
87 std::string_view get_type_name() const override {
88 return "MRecoveryReserve";
89 }
90
91 void inner_print(ostream& out) const override {
92 switch (type) {
93 case REQUEST:
94 out << "REQUEST";
95 break;
96 case GRANT:
97 out << "GRANT";
98 break;
99 case RELEASE:
100 out << "RELEASE";
101 break;
102 case REVOKE:
103 out << "REVOKE";
104 break;
105 }
106 if (type == REQUEST) out << " prio: " << priority;
107 }
108
109 void decode_payload() override {
110 auto p = payload.cbegin();
111 decode(pgid.pgid, p);
112 decode(query_epoch, p);
113 decode(type, p);
114 decode(pgid.shard, p);
115 if (header.version >= 3) {
116 decode(priority, p);
117 }
118 }
119
120 void encode_payload(uint64_t features) override {
121 using ceph::encode;
122 encode(pgid.pgid, payload);
123 encode(query_epoch, payload);
124 encode(type, payload);
125 encode(pgid.shard, payload);
126 encode(priority, payload);
127 }
128 };
129
130 #endif