~ubuntu-branches/ubuntu/raring/ceph/raring

« back to all changes in this revision

Viewing changes to src/mon/PGMap.cc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-08 15:54:37 UTC
  • mfrom: (1.1.8) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20120608155437-gy3j9k6wzv7w4gn9
Tags: 0.44.1-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - d/control: Switch from libcryptopp to libnss as libcryptopp
    is not seeded.
  - d/control,d/rules: Move from python-support to dh_python2.
  - d/patches/manpage_updates*.patch: cherry picked upstream manpage
    updates warning about lack of encryption, per MIR review.
  - d/rules,d/control: Drop radosgw since libfcgi is not in main and
    the code may not be suitable for LTS.
  - d/rules,d/control: Drop tcmalloc since google perftools is not
    in main yet.
  - d/rules,d/control: Drop ceph-fuse entirely per MIR review
    recommendation.
* d/patches/fix-radosgw-tests.patch: Cherry picked patch from upstream
  VCS to fixup tests to conditionally use radosgw if enabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 
2
// vim: ts=8 sw=2 smarttab
1
3
 
2
4
#include "PGMap.h"
3
5
 
4
6
#define DOUT_SUBSYS mon
5
7
#include "common/debug.h"
6
8
 
 
9
#include "common/Formatter.h"
 
10
 
 
11
// --
 
12
 
 
13
void PGMap::Incremental::encode(bufferlist &bl) const
 
14
{
 
15
  __u8 v = 3;
 
16
  ::encode(v, bl);
 
17
  ::encode(version, bl);
 
18
  ::encode(pg_stat_updates, bl);
 
19
  ::encode(osd_stat_updates, bl);
 
20
  ::encode(osd_stat_rm, bl);
 
21
  ::encode(osdmap_epoch, bl);
 
22
  ::encode(pg_scan, bl);
 
23
  ::encode(full_ratio, bl);
 
24
  ::encode(nearfull_ratio, bl);
 
25
  ::encode(pg_remove, bl);
 
26
}
 
27
 
 
28
void PGMap::Incremental::decode(bufferlist::iterator &bl)
 
29
{
 
30
  __u8 v;
 
31
  ::decode(v, bl);
 
32
  ::decode(version, bl);
 
33
  if (v < 3) {
 
34
    pg_stat_updates.clear();
 
35
    __u32 n;
 
36
    ::decode(n, bl);
 
37
    while (n--) {
 
38
      old_pg_t opgid;
 
39
      ::decode(opgid, bl);
 
40
      pg_t pgid = opgid;
 
41
      ::decode(pg_stat_updates[pgid], bl);
 
42
    }
 
43
  } else {
 
44
    ::decode(pg_stat_updates, bl);
 
45
  }
 
46
  ::decode(osd_stat_updates, bl);
 
47
  ::decode(osd_stat_rm, bl);
 
48
  ::decode(osdmap_epoch, bl);
 
49
  ::decode(pg_scan, bl);
 
50
  if (v >= 2) {
 
51
    ::decode(full_ratio, bl);
 
52
    ::decode(nearfull_ratio, bl);
 
53
  }
 
54
  if (v < 3) {
 
55
    pg_remove.clear();
 
56
    __u32 n;
 
57
    ::decode(n, bl);
 
58
    while (n--) {
 
59
      old_pg_t opgid;
 
60
      ::decode(opgid, bl);
 
61
      pg_remove.insert(pg_t(opgid));
 
62
    }
 
63
  } else {
 
64
    ::decode(pg_remove, bl);
 
65
  }
 
66
}
 
67
 
 
68
void PGMap::Incremental::dump(Formatter *f) const
 
69
{
 
70
  f->dump_unsigned("version", version);
 
71
  f->dump_unsigned("osdmap_epoch", osdmap_epoch);
 
72
  f->dump_unsigned("pg_scan_epoch", pg_scan);
 
73
  f->dump_float("full_ratio", full_ratio);
 
74
  f->dump_float("nearfull_ratio", nearfull_ratio);
 
75
 
 
76
  f->open_array_section("pg_stat_updates");
 
77
  for (map<pg_t,pg_stat_t>::const_iterator p = pg_stat_updates.begin(); p != pg_stat_updates.end(); ++p) {
 
78
    f->open_object_section("pg_stat");
 
79
    f->dump_stream("pgid") << p->first;
 
80
    p->second.dump(f);
 
81
    f->close_section();
 
82
  }
 
83
  f->close_section();
 
84
 
 
85
  f->open_array_section("osd_stat_updates");
 
86
  for (map<int,osd_stat_t>::const_iterator p = osd_stat_updates.begin(); p != osd_stat_updates.end(); ++p) {
 
87
    f->open_object_section("osd_stat");
 
88
    f->dump_int("osd", p->first);
 
89
    p->second.dump(f);
 
90
    f->close_section();
 
91
  }
 
92
  f->close_section();
 
93
 
 
94
  f->open_array_section("osd_stat_removals");
 
95
  for (set<int>::const_iterator p = osd_stat_rm.begin(); p != osd_stat_rm.end(); ++p)
 
96
    f->dump_int("osd", *p);
 
97
  f->close_section();
 
98
 
 
99
  f->open_array_section("pg_removals");
 
100
  for (set<pg_t>::const_iterator p = pg_remove.begin(); p != pg_remove.end(); ++p)
 
101
    f->dump_stream("pgid") << *p;
 
102
  f->close_section();
 
103
}
 
104
 
 
105
void PGMap::Incremental::generate_test_instances(list<PGMap::Incremental*>& o)
 
106
{
 
107
  o.push_back(new Incremental);
 
108
  o.push_back(new Incremental);
 
109
  o.back()->version = 1;
 
110
  o.push_back(new Incremental);
 
111
  o.back()->version = 2;
 
112
  o.back()->pg_stat_updates[pg_t(1,2,3)] = pg_stat_t();
 
113
  o.back()->osd_stat_updates[5] = osd_stat_t();
 
114
  o.push_back(new Incremental);
 
115
  o.back()->version = 3;
 
116
  o.back()->osdmap_epoch = 1;
 
117
  o.back()->pg_scan = 2;
 
118
  o.back()->full_ratio = .2;
 
119
  o.back()->nearfull_ratio = .3;
 
120
  o.back()->pg_stat_updates[pg_t(4,5,6)] = pg_stat_t();
 
121
  o.back()->osd_stat_updates[6] = osd_stat_t();
 
122
  o.back()->pg_remove.insert(pg_t(1,2,3));
 
123
  o.back()->osd_stat_rm.insert(5);
 
124
}
 
125
 
 
126
 
 
127
// --
 
128
 
7
129
void PGMap::apply_incremental(const Incremental& inc)
8
130
{
9
131
  assert(inc.version == version+1);
111
233
  }
112
234
}
113
235
 
114
 
void PGMap::stat_zero()
 
236
void PGMap::calc_stats()
115
237
{
 
238
  num_pg_by_state.clear();
116
239
  num_pg = 0;
117
 
  num_pg_by_state.clear();
118
240
  num_osd = 0;
119
241
  pg_pool_sum.clear();
120
242
  pg_sum = pool_stat_t();
121
243
  osd_sum = osd_stat_t();
 
244
 
 
245
  for (hash_map<pg_t,pg_stat_t>::iterator p = pg_stat.begin();
 
246
       p != pg_stat.end();
 
247
       ++p) {
 
248
    stat_pg_add(p->first, p->second);
 
249
  }
 
250
  for (hash_map<int,osd_stat_t>::iterator p = osd_stat.begin();
 
251
       p != osd_stat.end();
 
252
       ++p)
 
253
    stat_osd_add(p->second);
 
254
 
 
255
  redo_full_sets();
122
256
}
123
257
 
124
258
void PGMap::stat_pg_add(const pg_t &pgid, const pg_stat_t &s)
136
270
  num_pg--;
137
271
  if (--num_pg_by_state[s.state] == 0)
138
272
    num_pg_by_state.erase(s.state);
139
 
  pg_pool_sum[pgid.pool()].sub(s);
 
273
 
 
274
  pool_stat_t& ps = pg_pool_sum[pgid.pool()];
 
275
  ps.sub(s);
 
276
  if (ps.is_zero())
 
277
    pg_pool_sum.erase(pgid.pool());
 
278
 
140
279
  pg_sum.sub(s);
141
280
  if (s.state & PG_STATE_CREATING)
142
281
    creating_pgs.erase(pgid);
167
306
  return min;
168
307
}
169
308
 
170
 
void PGMap::encode(bufferlist &bl)
 
309
void PGMap::encode(bufferlist &bl) const
171
310
{
172
311
  __u8 v = 3;
173
312
  ::encode(v, bl);
205
344
    ::decode(full_ratio, bl);
206
345
    ::decode(nearfull_ratio, bl);
207
346
  }
208
 
  stat_zero();
209
 
  for (hash_map<pg_t,pg_stat_t>::iterator p = pg_stat.begin();
210
 
       p != pg_stat.end();
211
 
       ++p) {
212
 
    stat_pg_add(p->first, p->second);
213
 
  }
214
 
  for (hash_map<int,osd_stat_t>::iterator p = osd_stat.begin();
215
 
       p != osd_stat.end();
216
 
       ++p)
217
 
    stat_osd_add(p->second);
218
 
  
219
 
  redo_full_sets();
 
347
 
 
348
  calc_stats();
220
349
}
221
350
 
222
351
void PGMap::dump(Formatter *f) const
286
415
  f->close_section();
287
416
}
288
417
 
289
 
 
290
 
void PGMap::dump(ostream& ss) const
 
418
void PGMap::dump_pg_stats_plain(ostream& ss,
 
419
                                const hash_map<pg_t, pg_stat_t>& pg_stats) const
291
420
{
292
 
  ss << "version " << version << std::endl;
293
 
  ss << "last_osdmap_epoch " << last_osdmap_epoch << std::endl;
294
 
  ss << "last_pg_scan " << last_pg_scan << std::endl;
295
 
  ss << "full_ratio " << full_ratio << std::endl;
296
 
  ss << "nearfull_ratio " << nearfull_ratio << std::endl;
297
 
  ss << "pg_stat\tobjects\tmip\tdegr\tunf\tkb\tbytes\tlog\tdisklog\tstate\tv\treported\tup\tacting\tlast_scrub" << std::endl;
298
 
  for (hash_map<pg_t,pg_stat_t>::const_iterator i = pg_stat.begin();
299
 
       i != pg_stat.end(); ++i) {
 
421
  ss << "pg_stat\tobjects\tmip\tdegr\tunf\tbytes\tlog\tdisklog\tstate\tstate_stamp\tv\treported\tup\tacting\tlast_scrub\tscrub_stamp" << std::endl;
 
422
  for (hash_map<pg_t, pg_stat_t>::const_iterator i = pg_stats.begin();
 
423
       i != pg_stats.end(); ++i) {
300
424
    const pg_stat_t &st(i->second);
301
425
    ss << i->first
302
426
       << "\t" << st.stats.sum.num_objects
308
432
       << "\t" << st.log_size
309
433
       << "\t" << st.ondisk_log_size
310
434
       << "\t" << pg_state_string(st.state)
 
435
       << "\t" << st.last_change
311
436
       << "\t" << st.version
312
437
       << "\t" << st.reported
313
438
       << "\t" << st.up
315
440
       << "\t" << st.last_scrub << "\t" << st.last_scrub_stamp
316
441
       << std::endl;
317
442
  }
 
443
}
 
444
 
 
445
void PGMap::dump(ostream& ss) const
 
446
{
 
447
  ss << "version " << version << std::endl;
 
448
  ss << "last_osdmap_epoch " << last_osdmap_epoch << std::endl;
 
449
  ss << "last_pg_scan " << last_pg_scan << std::endl;
 
450
  ss << "full_ratio " << full_ratio << std::endl;
 
451
  ss << "nearfull_ratio " << nearfull_ratio << std::endl;
 
452
  dump_pg_stats_plain(ss, pg_stat);
318
453
  for (hash_map<int,pool_stat_t>::const_iterator p = pg_pool_sum.begin();
319
454
       p != pg_pool_sum.end();
320
455
       p++)
354
489
     << std::endl;
355
490
}
356
491
 
 
492
void PGMap::get_stuck_stats(PGMap::StuckPG type, utime_t cutoff,
 
493
                            hash_map<pg_t, pg_stat_t>& stuck_pgs) const
 
494
{
 
495
  for (hash_map<pg_t, pg_stat_t>::const_iterator i = pg_stat.begin();
 
496
       i != pg_stat.end();
 
497
       ++i) {
 
498
    utime_t val;
 
499
    switch (type) {
 
500
    case STUCK_INACTIVE:
 
501
      if (i->second.state & PG_STATE_ACTIVE)
 
502
        continue;
 
503
      val = i->second.last_active;
 
504
      break;
 
505
    case STUCK_UNCLEAN:
 
506
      if (i->second.state & PG_STATE_CLEAN)
 
507
        continue;
 
508
      val = i->second.last_clean;
 
509
      break;
 
510
    case STUCK_STALE:
 
511
      if ((i->second.state & PG_STATE_STALE) == 0)
 
512
        continue;
 
513
      val = i->second.last_unstale;
 
514
      break;
 
515
    default:
 
516
      assert(0 == "invalid type");
 
517
    }
 
518
 
 
519
    if (val < cutoff) {
 
520
      stuck_pgs[i->first] = i->second;
 
521
    }
 
522
  }
 
523
}
 
524
 
 
525
void PGMap::dump_stuck(Formatter *f, PGMap::StuckPG type, utime_t cutoff) const
 
526
{
 
527
  hash_map<pg_t, pg_stat_t> stuck_pg_stats;
 
528
  get_stuck_stats(type, cutoff, stuck_pg_stats);
 
529
  f->open_array_section("stuck_pg_stats");
 
530
  for (hash_map<pg_t,pg_stat_t>::const_iterator i = stuck_pg_stats.begin();
 
531
       i != stuck_pg_stats.end();
 
532
       ++i) {
 
533
    f->open_object_section("pg_stat");
 
534
    f->dump_stream("pgid") << i->first;
 
535
    i->second.dump(f);
 
536
    f->close_section();
 
537
  }
 
538
  f->close_section();
 
539
}
 
540
 
 
541
void PGMap::dump_stuck_plain(ostream& ss, PGMap::StuckPG type, utime_t cutoff) const
 
542
{
 
543
  hash_map<pg_t, pg_stat_t> stuck_pg_stats;
 
544
  get_stuck_stats(type, cutoff, stuck_pg_stats);
 
545
  dump_pg_stats_plain(ss, stuck_pg_stats);
 
546
}
 
547
 
357
548
void PGMap::state_summary(ostream& ss) const
358
549
{
359
550
  for (hash_map<int,int>::const_iterator p = num_pg_by_state.begin();
406
597
    out << "; " << ssr.str();
407
598
}
408
599
 
 
600
void PGMap::generate_test_instances(list<PGMap*>& o)
 
601
{
 
602
  o.push_back(new PGMap);
 
603
  o.push_back(new PGMap);
 
604
  list<Incremental*> inc;
 
605
  Incremental::generate_test_instances(inc);
 
606
  inc.pop_front();
 
607
  while (!inc.empty()) {
 
608
    o.back()->apply_incremental(*inc.front());
 
609
    delete inc.front();
 
610
    inc.pop_front();
 
611
  }
 
612
}