]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/mon/PGMap.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / mon / PGMap.cc
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 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2014 Inktank <info@inktank.com>
7 *
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.
12 */
13
14#include "mon/PGMap.h"
15#include "gtest/gtest.h"
16
17#include "include/stringify.h"
18
20effc67 19using namespace std;
7c673cae
FG
20
21namespace {
22 class CheckTextTable : public TextTable {
23 public:
11fdf7f2
TL
24 explicit CheckTextTable(bool verbose) {
25 for (int i = 0; i < 5; i++) {
7c673cae
FG
26 define_column("", TextTable::LEFT, TextTable::LEFT);
27 }
28 if (verbose) {
9f95a23c 29 for (int i = 0; i < 9; i++) {
7c673cae
FG
30 define_column("", TextTable::LEFT, TextTable::LEFT);
31 }
32 }
33 }
34 const string& get(unsigned r, unsigned c) const {
11fdf7f2
TL
35 ceph_assert(r < row.size());
36 ceph_assert(c < row[r].size());
7c673cae
FG
37 return row[r][c];
38 }
39 };
40
41 // copied from PGMap.cc
42 string percentify(float a) {
43 stringstream ss;
44 if (a < 0.01)
45 ss << "0";
46 else
47 ss << std::fixed << std::setprecision(2) << a;
48 return ss.str();
49 }
50}
51
52// dump_object_stat_sum() is called by "ceph df" command
53// with table, without formatter, verbose = true, not empty, avail > 0
54TEST(pgmap, dump_object_stat_sum_0)
55{
56 bool verbose = true;
57 CheckTextTable tbl(verbose);
11fdf7f2
TL
58 pool_stat_t pool_stat;
59 object_stat_sum_t& sum = pool_stat.stats.sum;
7c673cae
FG
60 sum.num_bytes = 42 * 1024 * 1024;
61 sum.num_objects = 42;
62 sum.num_objects_degraded = 13; // there are 13 missings + not_yet_backfilled
63 sum.num_objects_dirty = 2;
64 sum.num_rd = 100;
65 sum.num_rd_kb = 123;
66 sum.num_wr = 101;
67 sum.num_wr_kb = 321;
11fdf7f2
TL
68 pool_stat.num_store_stats = 3;
69 store_statfs_t &statfs = pool_stat.store_stats;
70 statfs.data_stored = 40 * 1024 * 1024;
71 statfs.allocated = 41 * 1024 * 1024 * 2;
72 statfs.data_compressed_allocated = 4334;
73 statfs.data_compressed_original = 1213;
74
75 sum.calc_copies(3); // assuming we have 3 copies for each obj
7c673cae
FG
76 // nominal amount of space available for new objects in this pool
77 uint64_t avail = 2016 * 1024 * 1024;
78 pg_pool_t pool;
79 pool.quota_max_objects = 2000;
80 pool.quota_max_bytes = 2000 * 1024 * 1024;
81 pool.size = 2;
82 pool.type = pg_pool_t::TYPE_REPLICATED;
522d829b 83 pool.tier_of = 0;
11fdf7f2 84 PGMap::dump_object_stat_sum(tbl, nullptr, pool_stat, avail,
522d829b 85 pool.get_size(), verbose, true, true, &pool);
7c673cae
FG
86 float copies_rate =
87 (static_cast<float>(sum.num_object_copies - sum.num_objects_degraded) /
11fdf7f2
TL
88 sum.num_object_copies) * pool.get_size();
89 float used_percent = (float)statfs.allocated /
90 (statfs.allocated + avail) * 100;
91 uint64_t stored = statfs.data_stored / copies_rate;
92
7c673cae 93 unsigned col = 0;
11fdf7f2 94 ASSERT_EQ(stringify(byte_u_t(stored)), tbl.get(0, col++));
9f95a23c
TL
95 ASSERT_EQ(stringify(byte_u_t(stored)), tbl.get(0, col++));
96 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
11fdf7f2
TL
97 ASSERT_EQ(stringify(si_u_t(sum.num_objects)), tbl.get(0, col++));
98 ASSERT_EQ(stringify(byte_u_t(statfs.allocated)), tbl.get(0, col++));
9f95a23c
TL
99 ASSERT_EQ(stringify(byte_u_t(statfs.allocated)), tbl.get(0, col++));
100 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
7c673cae 101 ASSERT_EQ(percentify(used_percent), tbl.get(0, col++));
11fdf7f2
TL
102 ASSERT_EQ(stringify(byte_u_t(avail/copies_rate)), tbl.get(0, col++));
103 ASSERT_EQ(stringify(si_u_t(pool.quota_max_objects)), tbl.get(0, col++));
104 ASSERT_EQ(stringify(byte_u_t(pool.quota_max_bytes)), tbl.get(0, col++));
1adf2230 105 ASSERT_EQ(stringify(si_u_t(sum.num_objects_dirty)), tbl.get(0, col++));
11fdf7f2
TL
106 ASSERT_EQ(stringify(byte_u_t(statfs.data_compressed_allocated)), tbl.get(0, col++));
107 ASSERT_EQ(stringify(byte_u_t(statfs.data_compressed_original)), tbl.get(0, col++));
7c673cae
FG
108}
109
110// with table, without formatter, verbose = true, empty, avail > 0
111TEST(pgmap, dump_object_stat_sum_1)
112{
113 bool verbose = true;
114 CheckTextTable tbl(verbose);
11fdf7f2
TL
115 pool_stat_t pool_stat;
116 object_stat_sum_t& sum = pool_stat.stats.sum; // zero by default
7c673cae
FG
117 ASSERT_TRUE(sum.is_zero());
118 // nominal amount of space available for new objects in this pool
119 uint64_t avail = 2016 * 1024 * 1024;
120 pg_pool_t pool;
121 pool.quota_max_objects = 2000;
122 pool.quota_max_bytes = 2000 * 1024 * 1024;
123 pool.size = 2;
124 pool.type = pg_pool_t::TYPE_REPLICATED;
522d829b 125 pool.tier_of = 0;
11fdf7f2 126 PGMap::dump_object_stat_sum(tbl, nullptr, pool_stat, avail,
522d829b 127 pool.get_size(), verbose, true, true, &pool);
7c673cae 128 unsigned col = 0;
1adf2230 129 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
9f95a23c
TL
130 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
131 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
11fdf7f2
TL
132 ASSERT_EQ(stringify(si_u_t(0)), tbl.get(0, col++));
133 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
9f95a23c
TL
134 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
135 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
7c673cae 136 ASSERT_EQ(percentify(0), tbl.get(0, col++));
1adf2230 137 ASSERT_EQ(stringify(byte_u_t(avail/pool.size)), tbl.get(0, col++));
11fdf7f2
TL
138 ASSERT_EQ(stringify(si_u_t(pool.quota_max_objects)), tbl.get(0, col++));
139 ASSERT_EQ(stringify(byte_u_t(pool.quota_max_bytes)), tbl.get(0, col++));
1adf2230
AA
140 ASSERT_EQ(stringify(si_u_t(0)), tbl.get(0, col++));
141 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
142 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
7c673cae
FG
143}
144
145// with table, without formatter, verbose = false, empty, avail = 0
146TEST(pgmap, dump_object_stat_sum_2)
147{
148 bool verbose = false;
149 CheckTextTable tbl(verbose);
11fdf7f2
TL
150 pool_stat_t pool_stat;
151 object_stat_sum_t& sum = pool_stat.stats.sum; // zero by default
7c673cae
FG
152 ASSERT_TRUE(sum.is_zero());
153 // nominal amount of space available for new objects in this pool
154 uint64_t avail = 0;
155 pg_pool_t pool;
156 pool.quota_max_objects = 2000;
157 pool.quota_max_bytes = 2000 * 1024 * 1024;
158 pool.size = 2;
159 pool.type = pg_pool_t::TYPE_REPLICATED;
160
11fdf7f2 161 PGMap::dump_object_stat_sum(tbl, nullptr, pool_stat, avail,
9f95a23c 162 pool.get_size(), verbose, true, true, &pool);
7c673cae 163 unsigned col = 0;
1adf2230 164 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
11fdf7f2
TL
165 ASSERT_EQ(stringify(si_u_t(0)), tbl.get(0, col++));
166 ASSERT_EQ(stringify(byte_u_t(0)), tbl.get(0, col++));
7c673cae 167 ASSERT_EQ(percentify(0), tbl.get(0, col++));
1adf2230 168 ASSERT_EQ(stringify(byte_u_t(avail/pool.size)), tbl.get(0, col++));
7c673cae 169}