]> git.proxmox.com Git - ceph.git/blame - ceph/src/mon/CreatingPGs.h
bump version to 12.2.5-pve1
[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>
8#include "include/encoding.h"
9
10struct creating_pgs_t {
11 epoch_t last_scan_epoch = 0;
31f18b77
FG
12
13 /// pgs we are currently creating
7c673cae 14 std::map<pg_t, std::pair<epoch_t, utime_t> > pgs;
31f18b77
FG
15
16 struct create_info {
17 epoch_t created;
18 utime_t modified;
19 uint64_t start = 0;
20 uint64_t end = 0;
21 bool done() const {
22 return start >= end;
23 }
24 void encode(bufferlist& bl) const {
25 ::encode(created, bl);
26 ::encode(modified, bl);
27 ::encode(start, bl);
28 ::encode(end, bl);
29 }
30 void decode(bufferlist::iterator& p) {
31 ::decode(created, p);
32 ::decode(modified, p);
33 ::decode(start, p);
34 ::decode(end, p);
35 }
36 };
37
38 /// queue of pgs we still need to create (poolid -> <created, set of ps>)
39 map<int64_t,create_info> queue;
40
41 /// pools that exist in the osdmap for which at least one pg has been created
7c673cae 42 std::set<int64_t> created_pools;
31f18b77
FG
43
44 bool create_pool(int64_t poolid, uint32_t pg_num,
45 epoch_t created, utime_t modified) {
46 if (created_pools.count(poolid) == 0) {
47 auto& c = queue[poolid];
48 c.created = created;
49 c.modified = modified;
50 c.end = pg_num;
51 created_pools.insert(poolid);
52 return true;
53 } else {
54 return false;
55 }
56 }
57 unsigned remove_pool(int64_t removed_pool) {
58 const unsigned total = pgs.size();
59 auto first = pgs.lower_bound(pg_t{0, (uint64_t)removed_pool});
60 auto last = pgs.lower_bound(pg_t{0, (uint64_t)removed_pool + 1});
61 pgs.erase(first, last);
62 created_pools.erase(removed_pool);
181888fb 63 queue.erase(removed_pool);
31f18b77
FG
64 return total - pgs.size();
65 }
7c673cae 66 void encode(bufferlist& bl) const {
31f18b77 67 ENCODE_START(2, 1, bl);
7c673cae
FG
68 ::encode(last_scan_epoch, bl);
69 ::encode(pgs, bl);
70 ::encode(created_pools, bl);
31f18b77 71 ::encode(queue, bl);
7c673cae
FG
72 ENCODE_FINISH(bl);
73 }
74 void decode(bufferlist::iterator& bl) {
31f18b77 75 DECODE_START(2, bl);
7c673cae
FG
76 ::decode(last_scan_epoch, bl);
77 ::decode(pgs, bl);
78 ::decode(created_pools, bl);
31f18b77
FG
79 if (struct_v >= 2)
80 ::decode(queue, bl);
7c673cae
FG
81 DECODE_FINISH(bl);
82 }
83 void dump(ceph::Formatter *f) const {
7c673cae 84 f->dump_unsigned("last_scan_epoch", last_scan_epoch);
31f18b77 85 f->open_array_section("creating_pgs");
7c673cae
FG
86 for (auto& pg : pgs) {
87 f->open_object_section("pg");
88 f->dump_stream("pgid") << pg.first;
89 f->dump_unsigned("epoch", pg.second.first);
90 f->dump_stream("ctime") << pg.second.second;
91 f->close_section();
92 }
93 f->close_section();
31f18b77
FG
94 f->open_array_section("queue");
95 for (auto& p : queue) {
96 f->open_object_section("pool");
97 f->dump_unsigned("pool", p.first);
98 f->dump_unsigned("created", p.second.created);
99 f->dump_stream("modified") << p.second.modified;
100 f->dump_unsigned("ps_start", p.second.start);
101 f->dump_unsigned("ps_end", p.second.end);
102 f->close_section();
103 }
104 f->close_section();
7c673cae
FG
105 f->open_array_section("created_pools");
106 for (auto pool : created_pools) {
107 f->dump_unsigned("pool", pool);
108 }
109 f->close_section();
110 }
111 static void generate_test_instances(list<creating_pgs_t*>& o) {
112 auto c = new creating_pgs_t;
113 c->last_scan_epoch = 17;
114 c->pgs.emplace(pg_t{42, 2}, make_pair(31, utime_t{891, 113}));
115 c->pgs.emplace(pg_t{44, 2}, make_pair(31, utime_t{891, 113}));
116 c->created_pools = {0, 1};
117 o.push_back(c);
118 c = new creating_pgs_t;
119 c->last_scan_epoch = 18;
120 c->pgs.emplace(pg_t{42, 3}, make_pair(31, utime_t{891, 113}));
121 c->created_pools = {};
122 o.push_back(c);
123 }
124};
31f18b77 125WRITE_CLASS_ENCODER(creating_pgs_t::create_info);
7c673cae 126WRITE_CLASS_ENCODER(creating_pgs_t);