]> git.proxmox.com Git - ceph.git/blame - ceph/src/mon/CreatingPGs.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / mon / CreatingPGs.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#pragma once
5
6#include <map>
7#include <set>
11fdf7f2 8
7c673cae 9#include "include/encoding.h"
11fdf7f2
TL
10#include "include/utime.h"
11
12#include "osd/osd_types.h"
7c673cae
FG
13
14struct creating_pgs_t {
15 epoch_t last_scan_epoch = 0;
31f18b77 16
9f95a23c
TL
17 struct pg_create_info {
18 epoch_t create_epoch;
19 utime_t create_stamp;
20
21 // NOTE: pre-octopus instances of this class will have a
22 // zeroed-out history
23 vector<int> up;
24 int up_primary = -1;
25 vector<int> acting;
26 int acting_primary = -1;
27 pg_history_t history;
28 PastIntervals past_intervals;
29
30 void encode(bufferlist& bl, uint64_t features) const {
31 using ceph::encode;
32 if (!HAVE_FEATURE(features, SERVER_OCTOPUS)) {
33 // was pair<epoch_t,utime_t> prior to octopus
34 encode(create_epoch, bl);
35 encode(create_stamp, bl);
36 return;
37 }
38 ENCODE_START(1, 1, bl);
39 encode(create_epoch, bl);
40 encode(create_stamp, bl);
41 encode(up, bl);
42 encode(up_primary, bl);
43 encode(acting, bl);
44 encode(acting_primary, bl);
45 encode(history, bl);
46 encode(past_intervals, bl);
47 ENCODE_FINISH(bl);
48 }
49 void decode_legacy(bufferlist::const_iterator& p) {
50 using ceph::decode;
51 decode(create_epoch, p);
52 decode(create_stamp, p);
53 }
54 void decode(bufferlist::const_iterator& p) {
55 using ceph::decode;
56 DECODE_START(1, p);
57 decode(create_epoch, p);
58 decode(create_stamp, p);
59 decode(up, p);
60 decode(up_primary, p);
61 decode(acting, p);
62 decode(acting_primary, p);
63 decode(history, p);
64 decode(past_intervals, p);
65 DECODE_FINISH(p);
66 }
67 void dump(Formatter *f) const {
68 f->dump_unsigned("create_epoch", create_epoch);
69 f->dump_stream("create_stamp") << create_stamp;
70 f->open_array_section("up");
71 for (auto& i : up) {
72 f->dump_unsigned("osd", i);
73 }
74 f->close_section();
75 f->dump_int("up_primary", up_primary);
76 f->open_array_section("acting");
77 for (auto& i : acting) {
78 f->dump_unsigned("osd", i);
79 }
80 f->close_section();
81 f->dump_int("acting_primary", up_primary);
82 f->dump_object("pg_history", history);
83 f->dump_object("past_intervals", past_intervals);
84 }
85
86 pg_create_info() {}
87 pg_create_info(epoch_t e, utime_t t)
88 : create_epoch(e),
89 create_stamp(t) {
90 // NOTE: we don't initialize the other fields here; see
91 // OSDMonitor::update_pending_pgs()
92 }
93 };
94
31f18b77 95 /// pgs we are currently creating
9f95a23c 96 std::map<pg_t, pg_create_info> pgs;
31f18b77 97
9f95a23c 98 struct pool_create_info {
31f18b77
FG
99 epoch_t created;
100 utime_t modified;
101 uint64_t start = 0;
102 uint64_t end = 0;
103 bool done() const {
104 return start >= end;
105 }
106 void encode(bufferlist& bl) const {
11fdf7f2
TL
107 using ceph::encode;
108 encode(created, bl);
109 encode(modified, bl);
110 encode(start, bl);
111 encode(end, bl);
31f18b77 112 }
11fdf7f2
TL
113 void decode(bufferlist::const_iterator& p) {
114 using ceph::decode;
115 decode(created, p);
116 decode(modified, p);
117 decode(start, p);
118 decode(end, p);
31f18b77
FG
119 }
120 };
121
122 /// queue of pgs we still need to create (poolid -> <created, set of ps>)
9f95a23c 123 map<int64_t,pool_create_info> queue;
31f18b77
FG
124
125 /// pools that exist in the osdmap for which at least one pg has been created
7c673cae 126 std::set<int64_t> created_pools;
31f18b77 127
11fdf7f2
TL
128 bool still_creating_pool(int64_t poolid) {
129 for (auto& i : pgs) {
130 if (i.first.pool() == poolid) {
131 return true;
132 }
133 }
134 if (queue.count(poolid)) {
31f18b77 135 return true;
31f18b77 136 }
11fdf7f2
TL
137 return false;
138 }
139 void create_pool(int64_t poolid, uint32_t pg_num,
140 epoch_t created, utime_t modified) {
141 ceph_assert(created_pools.count(poolid) == 0);
142 auto& c = queue[poolid];
143 c.created = created;
144 c.modified = modified;
145 c.end = pg_num;
146 created_pools.insert(poolid);
31f18b77
FG
147 }
148 unsigned remove_pool(int64_t removed_pool) {
149 const unsigned total = pgs.size();
150 auto first = pgs.lower_bound(pg_t{0, (uint64_t)removed_pool});
151 auto last = pgs.lower_bound(pg_t{0, (uint64_t)removed_pool + 1});
152 pgs.erase(first, last);
153 created_pools.erase(removed_pool);
181888fb 154 queue.erase(removed_pool);
31f18b77
FG
155 return total - pgs.size();
156 }
9f95a23c
TL
157 void encode(bufferlist& bl, uint64_t features) const {
158 unsigned v = 3;
159 if (!HAVE_FEATURE(features, SERVER_OCTOPUS)) {
160 v = 2;
161 }
162 ENCODE_START(v, 1, bl);
11fdf7f2 163 encode(last_scan_epoch, bl);
9f95a23c 164 encode(pgs, bl, features);
11fdf7f2
TL
165 encode(created_pools, bl);
166 encode(queue, bl);
7c673cae
FG
167 ENCODE_FINISH(bl);
168 }
11fdf7f2 169 void decode(bufferlist::const_iterator& bl) {
9f95a23c 170 DECODE_START(3, bl);
11fdf7f2 171 decode(last_scan_epoch, bl);
9f95a23c
TL
172 if (struct_v >= 3) {
173 decode(pgs, bl);
174 } else {
175 // legacy pg encoding
176 pgs.clear();
177 uint32_t num;
178 decode(num, bl);
179 while (num--) {
180 pg_t pgid;
181 decode(pgid, bl);
182 pgs[pgid].decode_legacy(bl);
183 }
184 }
11fdf7f2 185 decode(created_pools, bl);
31f18b77 186 if (struct_v >= 2)
11fdf7f2 187 decode(queue, bl);
7c673cae
FG
188 DECODE_FINISH(bl);
189 }
190 void dump(ceph::Formatter *f) const {
7c673cae 191 f->dump_unsigned("last_scan_epoch", last_scan_epoch);
31f18b77 192 f->open_array_section("creating_pgs");
7c673cae
FG
193 for (auto& pg : pgs) {
194 f->open_object_section("pg");
195 f->dump_stream("pgid") << pg.first;
9f95a23c 196 f->dump_object("pg_create_info", pg.second);
7c673cae
FG
197 f->close_section();
198 }
199 f->close_section();
31f18b77
FG
200 f->open_array_section("queue");
201 for (auto& p : queue) {
202 f->open_object_section("pool");
203 f->dump_unsigned("pool", p.first);
204 f->dump_unsigned("created", p.second.created);
205 f->dump_stream("modified") << p.second.modified;
206 f->dump_unsigned("ps_start", p.second.start);
207 f->dump_unsigned("ps_end", p.second.end);
208 f->close_section();
209 }
210 f->close_section();
7c673cae
FG
211 f->open_array_section("created_pools");
212 for (auto pool : created_pools) {
213 f->dump_unsigned("pool", pool);
214 }
215 f->close_section();
216 }
217 static void generate_test_instances(list<creating_pgs_t*>& o) {
218 auto c = new creating_pgs_t;
219 c->last_scan_epoch = 17;
9f95a23c
TL
220 c->pgs.emplace(pg_t{42, 2}, pg_create_info(31, utime_t{891, 113}));
221 c->pgs.emplace(pg_t{44, 2}, pg_create_info(31, utime_t{891, 113}));
7c673cae
FG
222 c->created_pools = {0, 1};
223 o.push_back(c);
224 c = new creating_pgs_t;
225 c->last_scan_epoch = 18;
9f95a23c 226 c->pgs.emplace(pg_t{42, 3}, pg_create_info(31, utime_t{891, 113}));
7c673cae
FG
227 c->created_pools = {};
228 o.push_back(c);
229 }
230};
9f95a23c
TL
231WRITE_CLASS_ENCODER_FEATURES(creating_pgs_t::pg_create_info)
232WRITE_CLASS_ENCODER(creating_pgs_t::pool_create_info)
233WRITE_CLASS_ENCODER_FEATURES(creating_pgs_t)