]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/mon/PGMap.cc
60de6b7ddae91d146682e9e252b59ba8ba40c9a2
1 // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 Inktank <info@inktank.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License version 2, as published by the Free Software
11 * Foundation. See file COPYING.
14 #include "mon/PGMap.h"
15 #include "gtest/gtest.h"
17 #include "include/stringify.h"
19 TEST(pgmap
, min_last_epoch_clean
)
22 PGMap::Incremental inc
;
26 ps
.last_epoch_clean
= 999;
27 inc
.pg_stat_updates
[pg_t(9,9)] = ps
;
29 inc
.update_stat(0, 123, os
);
30 pg_map
.apply_incremental(g_ceph_context
, inc
);
31 ASSERT_EQ(123u, pg_map
.get_min_last_epoch_clean());
33 inc
= PGMap::Incremental();
35 inc
.update_stat(1, 222, os
);
36 pg_map
.apply_incremental(g_ceph_context
, inc
);
37 ASSERT_EQ(123u, pg_map
.get_min_last_epoch_clean());
39 inc
= PGMap::Incremental();
41 inc
.update_stat(0, 222, os
);
42 pg_map
.apply_incremental(g_ceph_context
, inc
);
43 ASSERT_EQ(222u, pg_map
.get_min_last_epoch_clean());
45 inc
= PGMap::Incremental();
47 inc
.update_stat(0, 333, os
);
48 inc
.update_stat(1, 333, os
);
49 pg_map
.apply_incremental(g_ceph_context
, inc
);
50 ASSERT_EQ(333u, pg_map
.get_min_last_epoch_clean());
52 ps
.last_epoch_clean
= 222;
53 inc
= PGMap::Incremental();
55 inc
.pg_stat_updates
[pg_t(1,1)] = ps
;
56 pg_map
.apply_incremental(g_ceph_context
, inc
);
57 ASSERT_EQ(222u, pg_map
.get_min_last_epoch_clean());
59 ps
.last_epoch_clean
= 223;
60 inc
= PGMap::Incremental();
62 inc
.pg_stat_updates
[pg_t(1,1)] = ps
;
63 pg_map
.apply_incremental(g_ceph_context
, inc
);
64 ASSERT_EQ(223u, pg_map
.get_min_last_epoch_clean());
66 ps
.last_epoch_clean
= 224;
67 inc
= PGMap::Incremental();
69 inc
.pg_stat_updates
[pg_t(2,2)] = ps
;
70 pg_map
.apply_incremental(g_ceph_context
, inc
);
71 ASSERT_EQ(223u, pg_map
.get_min_last_epoch_clean());
73 ps
.last_epoch_clean
= 225;
74 inc
= PGMap::Incremental();
76 inc
.pg_stat_updates
[pg_t(1,1)] = ps
;
77 pg_map
.apply_incremental(g_ceph_context
, inc
);
78 ASSERT_EQ(224u, pg_map
.get_min_last_epoch_clean());
82 TEST(pgmap
, calc_stats
)
87 PGMap::Incremental inc
;
91 ps
.last_epoch_clean
= 999;
92 inc
.pg_stat_updates
[pg_t(9,9)] = ps
;
94 inc
.update_stat(0, 123, os
);
95 pg_map
.apply_incremental(g_ceph_context
, inc
);
96 ASSERT_EQ(123u, pg_map
.get_min_last_epoch_clean());
101 PGMap::Incremental inc
;
105 ps
.last_epoch_clean
= 999;
106 inc
.pg_stat_updates
[pg_t(9,9)] = ps
;
108 inc
.update_stat(0, 321, os
);
109 pg_map
.apply_incremental(g_ceph_context
, inc
);
110 ASSERT_EQ(321u, pg_map
.get_min_last_epoch_clean());
111 bufferlist::iterator p
= bl
.begin();
113 ASSERT_EQ(123u, pg_map
.get_min_last_epoch_clean());
118 class CheckTextTable
: public TextTable
{
120 CheckTextTable(bool verbose
) {
121 for (int i
= 0; i
< 4; i
++) {
122 define_column("", TextTable::LEFT
, TextTable::LEFT
);
125 for (int i
= 0; i
< 4; i
++) {
126 define_column("", TextTable::LEFT
, TextTable::LEFT
);
130 const string
& get(unsigned r
, unsigned c
) const {
131 assert(r
< row
.size());
132 assert(c
< row
[r
].size());
137 // copied from PGMap.cc
138 string
percentify(float a
) {
143 ss
<< std::fixed
<< std::setprecision(2) << a
;
148 // dump_object_stat_sum() is called by "ceph df" command
149 // with table, without formatter, verbose = true, not empty, avail > 0
150 TEST(pgmap
, dump_object_stat_sum_0
)
153 CheckTextTable
tbl(verbose
);
154 object_stat_sum_t sum
;
155 sum
.num_bytes
= 42 * 1024 * 1024;
156 sum
.num_objects
= 42;
157 sum
.num_objects_degraded
= 13; // there are 13 missings + not_yet_backfilled
158 sum
.num_objects_dirty
= 2;
164 sum
.calc_copies(3); // assuming we have 3 copies for each obj
165 // nominal amount of space available for new objects in this pool
166 uint64_t avail
= 2016 * 1024 * 1024;
168 pool
.quota_max_objects
= 2000;
169 pool
.quota_max_bytes
= 2000 * 1024 * 1024;
171 pool
.type
= pg_pool_t::TYPE_REPLICATED
;
172 PGMap::dump_object_stat_sum(tbl
, nullptr, sum
, avail
,
173 pool
.get_size(), verbose
, &pool
);
174 ASSERT_EQ(stringify(si_t(sum
.num_bytes
)), tbl
.get(0, 0));
176 (static_cast<float>(sum
.num_object_copies
- sum
.num_objects_degraded
) /
177 sum
.num_object_copies
);
178 float used_bytes
= sum
.num_bytes
* copies_rate
;
179 float used_percent
= used_bytes
/ (used_bytes
+ avail
) * 100;
181 ASSERT_EQ(stringify(si_t(sum
.num_bytes
)), tbl
.get(0, col
++));
182 ASSERT_EQ(percentify(used_percent
), tbl
.get(0, col
++));
183 ASSERT_EQ(stringify(si_t(avail
)), tbl
.get(0, col
++));
184 ASSERT_EQ(stringify(sum
.num_objects
), tbl
.get(0, col
++));
185 ASSERT_EQ(stringify(si_t(sum
.num_objects_dirty
)), tbl
.get(0, col
++));
186 ASSERT_EQ(stringify(si_t(sum
.num_rd
)), tbl
.get(0, col
++));
187 ASSERT_EQ(stringify(si_t(sum
.num_wr
)), tbl
.get(0, col
++));
188 // we can use pool.size for raw_used_rate if it is a replica pool
189 uint64_t raw_bytes_used
= sum
.num_bytes
* pool
.get_size() * copies_rate
;
190 ASSERT_EQ(stringify(si_t(raw_bytes_used
)), tbl
.get(0, col
++));
193 // with table, without formatter, verbose = true, empty, avail > 0
194 TEST(pgmap
, dump_object_stat_sum_1
)
197 CheckTextTable
tbl(verbose
);
198 object_stat_sum_t sum
; // zero by default
199 ASSERT_TRUE(sum
.is_zero());
200 // nominal amount of space available for new objects in this pool
201 uint64_t avail
= 2016 * 1024 * 1024;
203 pool
.quota_max_objects
= 2000;
204 pool
.quota_max_bytes
= 2000 * 1024 * 1024;
206 pool
.type
= pg_pool_t::TYPE_REPLICATED
;
207 PGMap::dump_object_stat_sum(tbl
, nullptr, sum
, avail
,
208 pool
.get_size(), verbose
, &pool
);
209 ASSERT_EQ(stringify(si_t(0)), tbl
.get(0, 0));
211 ASSERT_EQ(stringify(si_t(0)), tbl
.get(0, col
++));
212 ASSERT_EQ(percentify(0), tbl
.get(0, col
++));
213 ASSERT_EQ(stringify(si_t(avail
)), tbl
.get(0, col
++));
214 ASSERT_EQ(stringify(0), tbl
.get(0, col
++));
215 ASSERT_EQ(stringify(si_t(0)), tbl
.get(0, col
++));
216 ASSERT_EQ(stringify(si_t(0)), tbl
.get(0, col
++));
217 ASSERT_EQ(stringify(si_t(0)), tbl
.get(0, col
++));
218 ASSERT_EQ(stringify(si_t(0)), tbl
.get(0, col
++));
221 // with table, without formatter, verbose = false, empty, avail = 0
222 TEST(pgmap
, dump_object_stat_sum_2
)
224 bool verbose
= false;
225 CheckTextTable
tbl(verbose
);
226 object_stat_sum_t sum
; // zero by default
227 ASSERT_TRUE(sum
.is_zero());
228 // nominal amount of space available for new objects in this pool
231 pool
.quota_max_objects
= 2000;
232 pool
.quota_max_bytes
= 2000 * 1024 * 1024;
234 pool
.type
= pg_pool_t::TYPE_REPLICATED
;
236 PGMap::dump_object_stat_sum(tbl
, nullptr, sum
, avail
,
237 pool
.get_size(), verbose
, &pool
);
238 ASSERT_EQ(stringify(si_t(0)), tbl
.get(0, 0));
240 ASSERT_EQ(stringify(si_t(0)), tbl
.get(0, col
++));
241 ASSERT_EQ(percentify(0), tbl
.get(0, col
++));
242 ASSERT_EQ(stringify(si_t(avail
)), tbl
.get(0, col
++));
243 ASSERT_EQ(stringify(0), tbl
.get(0, col
++));