]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MOSDPGPush.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / messages / MOSDPGPush.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) 2013 Inktank Storage, Inc.
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 MOSDPGPUSH_H
16 #define MOSDPGPUSH_H
17
18 #include "MOSDFastDispatchOp.h"
19
20 class MOSDPGPush : public MOSDFastDispatchOp {
21 private:
22 static constexpr int HEAD_VERSION = 4;
23 static constexpr int COMPAT_VERSION = 2;
24
25 public:
26 pg_shard_t from;
27 spg_t pgid;
28 epoch_t map_epoch = 0, min_epoch = 0;
29 std::vector<PushOp> pushes;
30 bool is_repair = false;
31
32 private:
33 uint64_t cost = 0;
34
35 public:
36 void compute_cost(CephContext *cct) {
37 cost = 0;
38 for (auto i = pushes.begin(); i != pushes.end(); ++i) {
39 cost += i->cost(cct);
40 }
41 }
42
43 int get_cost() const override {
44 return cost;
45 }
46
47 epoch_t get_map_epoch() const override {
48 return map_epoch;
49 }
50 epoch_t get_min_epoch() const override {
51 return min_epoch;
52 }
53 spg_t get_spg() const override {
54 return pgid;
55 }
56
57 void set_cost(uint64_t c) {
58 cost = c;
59 }
60
61 MOSDPGPush()
62 : MOSDFastDispatchOp{MSG_OSD_PG_PUSH, HEAD_VERSION, COMPAT_VERSION}
63 {}
64
65 void decode_payload() override {
66 using ceph::decode;
67 auto p = payload.cbegin();
68 decode(pgid.pgid, p);
69 decode(map_epoch, p);
70 decode(pushes, p);
71 decode(cost, p);
72 decode(pgid.shard, p);
73 decode(from, p);
74 if (header.version >= 3) {
75 decode(min_epoch, p);
76 } else {
77 min_epoch = map_epoch;
78 }
79 if (header.version >= 4) {
80 decode(is_repair, p);
81 } else {
82 is_repair = false;
83 }
84 }
85
86 void encode_payload(uint64_t features) override {
87 using ceph::encode;
88 encode(pgid.pgid, payload);
89 encode(map_epoch, payload);
90 encode(pushes, payload, features);
91 encode(cost, payload);
92 encode(pgid.shard, payload);
93 encode(from, payload);
94 encode(min_epoch, payload);
95 encode(is_repair, payload);
96 }
97
98 std::string_view get_type_name() const override { return "MOSDPGPush"; }
99
100 void print(std::ostream& out) const override {
101 out << "MOSDPGPush(" << pgid
102 << " " << map_epoch << "/" << min_epoch
103 << " " << pushes;
104 out << ")";
105 }
106
107 private:
108 template<class T, typename... Args>
109 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
110 };
111
112 #endif