]> git.proxmox.com Git - ceph.git/blob - ceph/src/mon/CreatingPGs.h
4ba91575f3cc0d25317dc04b8100963f7974fbfa
[ceph.git] / ceph / src / mon / CreatingPGs.h
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
10 struct creating_pgs_t {
11 epoch_t last_scan_epoch = 0;
12
13 /// pgs we are currently creating
14 std::map<pg_t, std::pair<epoch_t, utime_t> > pgs;
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
42 std::set<int64_t> created_pools;
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);
63 return total - pgs.size();
64 }
65 void encode(bufferlist& bl) const {
66 ENCODE_START(2, 1, bl);
67 ::encode(last_scan_epoch, bl);
68 ::encode(pgs, bl);
69 ::encode(created_pools, bl);
70 ::encode(queue, bl);
71 ENCODE_FINISH(bl);
72 }
73 void decode(bufferlist::iterator& bl) {
74 DECODE_START(2, bl);
75 ::decode(last_scan_epoch, bl);
76 ::decode(pgs, bl);
77 ::decode(created_pools, bl);
78 if (struct_v >= 2)
79 ::decode(queue, bl);
80 DECODE_FINISH(bl);
81 }
82 void dump(ceph::Formatter *f) const {
83 f->dump_unsigned("last_scan_epoch", last_scan_epoch);
84 f->open_array_section("creating_pgs");
85 for (auto& pg : pgs) {
86 f->open_object_section("pg");
87 f->dump_stream("pgid") << pg.first;
88 f->dump_unsigned("epoch", pg.second.first);
89 f->dump_stream("ctime") << pg.second.second;
90 f->close_section();
91 }
92 f->close_section();
93 f->open_array_section("queue");
94 for (auto& p : queue) {
95 f->open_object_section("pool");
96 f->dump_unsigned("pool", p.first);
97 f->dump_unsigned("created", p.second.created);
98 f->dump_stream("modified") << p.second.modified;
99 f->dump_unsigned("ps_start", p.second.start);
100 f->dump_unsigned("ps_end", p.second.end);
101 f->close_section();
102 }
103 f->close_section();
104 f->open_array_section("created_pools");
105 for (auto pool : created_pools) {
106 f->dump_unsigned("pool", pool);
107 }
108 f->close_section();
109 }
110 static void generate_test_instances(list<creating_pgs_t*>& o) {
111 auto c = new creating_pgs_t;
112 c->last_scan_epoch = 17;
113 c->pgs.emplace(pg_t{42, 2}, make_pair(31, utime_t{891, 113}));
114 c->pgs.emplace(pg_t{44, 2}, make_pair(31, utime_t{891, 113}));
115 c->created_pools = {0, 1};
116 o.push_back(c);
117 c = new creating_pgs_t;
118 c->last_scan_epoch = 18;
119 c->pgs.emplace(pg_t{42, 3}, make_pair(31, utime_t{891, 113}));
120 c->created_pools = {};
121 o.push_back(c);
122 }
123 };
124 WRITE_CLASS_ENCODER(creating_pgs_t::create_info);
125 WRITE_CLASS_ENCODER(creating_pgs_t);