]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MOSDPGNotify.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / messages / MOSDPGNotify.h
CommitLineData
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#ifndef CEPH_MOSDPGPEERNOTIFY_H
16#define CEPH_MOSDPGPEERNOTIFY_H
17
18#include "msg/Message.h"
19
20#include "osd/osd_types.h"
21
22/*
23 * PGNotify - notify primary of my PGs and versions.
24 */
25
9f95a23c 26class MOSDPGNotify : public Message {
11fdf7f2 27private:
9f95a23c 28 static constexpr int HEAD_VERSION = 7;
11fdf7f2 29 static constexpr int COMPAT_VERSION = 6;
7c673cae 30
d2e6a577 31 epoch_t epoch = 0;
7c673cae
FG
32 /// query_epoch is the epoch of the query being responded to, or
33 /// the current epoch if this is not being sent in response to a
34 /// query. This allows the recipient to disregard responses to old
35 /// queries.
9f95a23c
TL
36 using pg_list_t = std::vector<pg_notify_t>;
37 pg_list_t pg_list;
7c673cae
FG
38
39 public:
40 version_t get_epoch() const { return epoch; }
9f95a23c 41 const pg_list_t& get_pg_list() const {
7c673cae
FG
42 return pg_list;
43 }
44
45 MOSDPGNotify()
9f95a23c
TL
46 : MOSDPGNotify(0, {})
47 {}
48 MOSDPGNotify(epoch_t e, pg_list_t&& l)
49 : Message{MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION},
50 epoch(e),
51 pg_list(std::move(l)) {
7c673cae
FG
52 set_priority(CEPH_MSG_PRIO_HIGH);
53 }
54private:
55 ~MOSDPGNotify() override {}
56
57public:
11fdf7f2 58 std::string_view get_type_name() const override { return "PGnot"; }
7c673cae
FG
59
60 void encode_payload(uint64_t features) override {
11fdf7f2 61 using ceph::encode;
9f95a23c 62 header.version = HEAD_VERSION;
11fdf7f2 63 encode(epoch, payload);
9f95a23c
TL
64 if (!HAVE_FEATURE(features, SERVER_OCTOPUS)) {
65 // pretend to be vector<pair<pg_notify_t,PastIntervals>>
66 header.version = 6;
67 encode((uint32_t)pg_list.size(), payload);
68 for (auto& i : pg_list) {
69 encode(i, payload); // this embeds a dup (ignored) PastIntervals
70 encode(i.past_intervals, payload);
71 }
72 return;
73 }
11fdf7f2 74 encode(pg_list, payload);
7c673cae
FG
75 }
76
77 void decode_payload() override {
11fdf7f2
TL
78 auto p = payload.cbegin();
79 decode(epoch, p);
9f95a23c
TL
80 if (header.version == 6) {
81 // decode legacy vector<pair<pg_notify_t,PastIntervals>>
82 uint32_t num;
83 decode(num, p);
84 pg_list.resize(num);
85 for (unsigned i = 0; i < num; ++i) {
86 decode(pg_list[i], p);
87 decode(pg_list[i].past_intervals, p);
88 }
89 return;
90 }
11fdf7f2 91 decode(pg_list, p);
7c673cae
FG
92 }
93 void print(ostream& out) const override {
94 out << "pg_notify(";
95 for (auto i = pg_list.begin();
96 i != pg_list.end();
97 ++i) {
98 if (i != pg_list.begin())
99 out << " ";
9f95a23c 100 out << *i;
7c673cae
FG
101 }
102 out << " epoch " << epoch
103 << ")";
104 }
9f95a23c
TL
105private:
106 template<class T, typename... Args>
107 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
7c673cae
FG
108};
109
110#endif