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