]>
git.proxmox.com Git - ceph.git/blob - 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
8 #include "include/encoding.h"
10 struct creating_pgs_t
{
11 epoch_t last_scan_epoch
= 0;
13 /// pgs we are currently creating
14 std::map
<pg_t
, std::pair
<epoch_t
, utime_t
> > pgs
;
24 void encode(bufferlist
& bl
) const {
25 ::encode(created
, bl
);
26 ::encode(modified
, bl
);
30 void decode(bufferlist::iterator
& p
) {
32 ::decode(modified
, p
);
38 /// queue of pgs we still need to create (poolid -> <created, set of ps>)
39 map
<int64_t,create_info
> queue
;
41 /// pools that exist in the osdmap for which at least one pg has been created
42 std::set
<int64_t> created_pools
;
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
];
49 c
.modified
= modified
;
51 created_pools
.insert(poolid
);
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();
65 void encode(bufferlist
& bl
) const {
66 ENCODE_START(2, 1, bl
);
67 ::encode(last_scan_epoch
, bl
);
69 ::encode(created_pools
, bl
);
73 void decode(bufferlist::iterator
& bl
) {
75 ::decode(last_scan_epoch
, bl
);
77 ::decode(created_pools
, bl
);
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
;
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
);
104 f
->open_array_section("created_pools");
105 for (auto pool
: created_pools
) {
106 f
->dump_unsigned("pool", pool
);
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};
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
= {};
124 WRITE_CLASS_ENCODER(creating_pgs_t::create_info
);
125 WRITE_CLASS_ENCODER(creating_pgs_t
);