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