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

« back to all changes in this revision

Viewing changes to src/osd/OSDMap.h

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2012-02-05 10:07:38 UTC
  • mfrom: (1.1.7) (0.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120205100738-00s0bxx93mamy8tk
Tags: 0.41-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <list>
37
37
#include <set>
38
38
#include <map>
 
39
#include <tr1/memory>
39
40
using namespace std;
40
41
 
41
42
#include <ext/hash_set>
105
106
public:
106
107
  class Incremental {
107
108
  public:
108
 
    ceph_fsid_t fsid;
 
109
    uuid_d fsid;
109
110
    epoch_t epoch;   // new epoch; we are a diff from epoch-1 to epoch
110
111
    utime_t modified;
111
112
    int64_t new_pool_max; //incremented by the OSDMonitor on each pool create
153
154
  };
154
155
  
155
156
private:
156
 
  ceph_fsid_t fsid;
 
157
  uuid_d fsid;
157
158
  epoch_t epoch;        // what epoch of the osd cluster descriptor is this
158
159
  utime_t created, modified; // epoch start time
159
160
  int32_t pool_max;     // the largest pool num, ever
190
191
  OSDMap() : epoch(0), 
191
192
             pool_max(-1),
192
193
             flags(0),
193
 
             num_osd(0), max_osd(0) { 
 
194
             num_osd(0), max_osd(0),
 
195
             cluster_snapshot_epoch(0) { 
194
196
    memset(&fsid, 0, sizeof(fsid));
195
197
  }
196
198
 
197
199
  // map info
198
 
  const ceph_fsid_t& get_fsid() const { return fsid; }
199
 
  void set_fsid(ceph_fsid_t& f) { fsid = f; }
 
200
  const uuid_d& get_fsid() const { return fsid; }
 
201
  void set_fsid(uuid_d& f) { fsid = f; }
200
202
 
201
203
  epoch_t get_epoch() const { return epoch; }
202
204
  void inc_epoch() { epoch++; }
213
215
  const utime_t& get_created() const { return created; }
214
216
  const utime_t& get_modified() const { return modified; }
215
217
 
216
 
  bool is_blacklisted(const entity_addr_t& a);
 
218
  bool is_blacklisted(const entity_addr_t& a) const;
217
219
 
218
220
  string get_cluster_snapshot() const {
219
221
    if (cluster_snapshot_epoch == epoch)
231
233
  }
232
234
  int calc_num_osds();
233
235
 
234
 
  void get_all_osds(set<int32_t>& ls) { 
 
236
  void get_all_osds(set<int32_t>& ls) const {
235
237
    for (int i=0; i<max_osd; i++)
236
238
      if (exists(i))
237
239
        ls.insert(i);
256
258
  void set_flag(int f) { flags |= f; }
257
259
  void clear_flag(int f) { flags &= ~f; }
258
260
 
259
 
  int get_state(int o) {
260
 
    assert(o < max_osd);
 
261
  int get_state(int o) const {
 
262
    assert(o < max_osd);
 
263
    return osd_state[o];
 
264
  }
 
265
  int get_state(int o, set<string>& st) const {
 
266
    assert(o < max_osd);
 
267
    unsigned t = osd_state[o];
 
268
    for (unsigned s = 1; t; s <<= 1) {
 
269
      if (t & s) {
 
270
        t &= ~s;
 
271
        st.insert(ceph_osd_state_name(s));
 
272
      }
 
273
    } 
261
274
    return osd_state[o];
262
275
  }
263
276
  void set_state(int o, unsigned s) {
318
331
        return i;
319
332
    return -1;
320
333
  }
321
 
  bool have_inst(int osd) {
 
334
  bool have_inst(int osd) const {
322
335
    return exists(osd) && is_up(osd); 
323
336
  }
324
337
  const entity_addr_t &get_addr(int osd) const {
335
348
    assert(exists(osd));
336
349
    return osd_hb_addr[osd];
337
350
  }
338
 
  entity_inst_t get_inst(int osd) {
 
351
  entity_inst_t get_inst(int osd) const {
339
352
    assert(exists(osd));
340
353
    assert(is_up(osd));
341
354
    return entity_inst_t(entity_name_t::OSD(osd), osd_addr[osd]);
342
355
  }
343
 
  entity_inst_t get_cluster_inst(int osd) {
 
356
  entity_inst_t get_cluster_inst(int osd) const {
344
357
    assert(exists(osd));
345
358
    assert(is_up(osd));
346
359
    if (osd_cluster_addr[osd] == entity_addr_t())
347
360
      return get_inst(osd);
348
361
    return entity_inst_t(entity_name_t::OSD(osd), osd_cluster_addr[osd]);
349
362
  }
350
 
  entity_inst_t get_hb_inst(int osd) {
 
363
  entity_inst_t get_hb_inst(int osd) const {
351
364
    assert(exists(osd));
352
365
    assert(is_up(osd));
353
366
    return entity_inst_t(entity_name_t::OSD(osd), osd_hb_addr[osd]);
388
401
 
389
402
 
390
403
  /****   mapping facilities   ****/
391
 
  int object_locator_to_pg(const object_t& oid, const object_locator_t& loc, pg_t &pg) {
 
404
  int object_locator_to_pg(const object_t& oid, const object_locator_t& loc, pg_t &pg) const {
392
405
    // calculate ps (placement seed)
393
406
    const pg_pool_t *pool = get_pg_pool(loc.get_pool());
394
407
    if (!pool)
406
419
    return 0;
407
420
  }
408
421
 
409
 
  pg_t object_locator_to_pg(const object_t& oid, const object_locator_t& loc) {
 
422
  pg_t object_locator_to_pg(const object_t& oid, const object_locator_t& loc) const {
410
423
    pg_t pg;
411
424
    int ret = object_locator_to_pg(oid, loc, pg);
412
425
    assert(ret == 0);
413
426
    return pg;
414
427
  }
415
428
 
416
 
  object_locator_t file_to_object_locator(const ceph_file_layout& layout) {
 
429
  object_locator_t file_to_object_locator(const ceph_file_layout& layout) const {
417
430
    return object_locator_t(layout.fl_pg_pool, layout.fl_pg_preferred);
418
431
  }
419
432
 
420
433
  // oid -> pg
421
 
  ceph_object_layout file_to_object_layout(object_t oid, ceph_file_layout& layout) {
 
434
  ceph_object_layout file_to_object_layout(object_t oid, ceph_file_layout& layout) const {
422
435
    return make_object_layout(oid, layout.fl_pg_pool,
423
436
                              layout.fl_pg_preferred);
424
437
  }
425
438
 
426
 
  ceph_object_layout make_object_layout(object_t oid, int pg_pool, int preferred=-1) {
 
439
  ceph_object_layout make_object_layout(object_t oid, int pg_pool, int preferred=-1) const {
427
440
    object_locator_t loc(pg_pool);
428
441
    loc.preferred = preferred;
429
442
    
434
447
    return ol;
435
448
  }
436
449
 
437
 
  int get_pg_num(int pg_pool)
 
450
  int get_pg_num(int pg_pool) const
438
451
  {
439
452
    const pg_pool_t *pool = get_pg_pool(pg_pool);
440
453
    return pool->get_pg_num();
442
455
 
443
456
  // pg -> (osd list)
444
457
private:
445
 
  int _pg_to_osds(const pg_pool_t& pool, pg_t pg, vector<int>& osds) {
 
458
  int _pg_to_osds(const pg_pool_t& pool, pg_t pg, vector<int>& osds) const {
446
459
    // map to osds[]
447
460
    ps_t pps = pool.raw_pg_to_pps(pg);  // placement ps
448
461
    unsigned size = pool.get_size();
463
476
  }
464
477
 
465
478
  // pg -> (up osd list)
466
 
  void _raw_to_up_osds(pg_t pg, vector<int>& raw, vector<int>& up) {
 
479
  void _raw_to_up_osds(pg_t pg, vector<int>& raw, vector<int>& up) const {
467
480
    up.clear();
468
481
    for (unsigned i=0; i<raw.size(); i++) {
469
482
      if (!exists(raw[i]) || is_down(raw[i])) 
472
485
    }
473
486
  }
474
487
  
475
 
  bool _raw_to_temp_osds(const pg_pool_t& pool, pg_t pg, vector<int>& raw, vector<int>& temp) {
 
488
  bool _raw_to_temp_osds(const pg_pool_t& pool, pg_t pg, vector<int>& raw, vector<int>& temp) const {
476
489
    pg = pool.raw_pg_to_pg(pg);
477
 
    map<pg_t,vector<int> >::iterator p = pg_temp.find(pg);
 
490
    map<pg_t,vector<int> >::const_iterator p = pg_temp.find(pg);
478
491
    if (p != pg_temp.end()) {
479
492
      temp.clear();
480
493
      for (unsigned i=0; i<p->second.size(); i++) {
488
501
  }
489
502
 
490
503
public:
491
 
  int pg_to_osds(pg_t pg, vector<int>& raw) {
 
504
  int pg_to_osds(pg_t pg, vector<int>& raw) const {
492
505
    const pg_pool_t *pool = get_pg_pool(pg.pool());
493
506
    if (!pool)
494
507
      return 0;
495
508
    return _pg_to_osds(*pool, pg, raw);
496
509
  }
497
510
 
498
 
  int pg_to_acting_osds(pg_t pg, vector<int>& acting) {         // list of osd addr's
 
511
  int pg_to_acting_osds(pg_t pg, vector<int>& acting) const {         // list of osd addr's
499
512
    const pg_pool_t *pool = get_pg_pool(pg.pool());
500
513
    if (!pool)
501
514
      return 0;
515
528
    _raw_to_up_osds(pg, raw, up);
516
529
  }
517
530
  
518
 
  void pg_to_up_acting_osds(pg_t pg, vector<int>& up, vector<int>& acting) {
 
531
  void pg_to_up_acting_osds(pg_t pg, vector<int>& up, vector<int>& acting) const {
519
532
    const pg_pool_t *pool = get_pg_pool(pg.pool());
520
533
    if (!pool)
521
534
      return;
533
546
  }
534
547
 
535
548
  const map<int64_t,pg_pool_t>& get_pools() { return pools; }
536
 
  const char *get_pool_name(int64_t p) {
537
 
    if (pool_name.count(p))
538
 
      return pool_name[p].c_str();
 
549
  const char *get_pool_name(int64_t p) const {
 
550
    map<int64_t, string>::const_iterator i = pool_name.find(p);
 
551
    if (i != pool_name.end())
 
552
      return i->second.c_str();
539
553
    return 0;
540
554
  }
541
555
  bool have_pg_pool(int64_t p) const {
542
556
    return pools.count(p);
543
557
  }
544
 
  const pg_pool_t* get_pg_pool(int64_t p) {
545
 
    if (pools.count(p))
546
 
      return &pools[p];
 
558
  const pg_pool_t* get_pg_pool(int64_t p) const {
 
559
    map<int64_t, pg_pool_t>::const_iterator i = pools.find(p);
 
560
    if (i != pools.end())
 
561
      return &i->second;
547
562
    return NULL;
548
563
  }
549
564
  unsigned get_pg_size(pg_t pg) const {
551
566
    assert(p != pools.end());
552
567
    return p->second.get_size();
553
568
  }
554
 
  int get_pg_type(pg_t pg) {
 
569
  int get_pg_type(pg_t pg) const {
555
570
    assert(pools.count(pg.pool()));
556
 
    pg_pool_t &pool = pools[pg.pool()];
557
 
    return pool.get_type();
 
571
    return pools.find(pg.pool())->second.get_type();
558
572
  }
559
573
 
560
574
 
561
 
  pg_t raw_pg_to_pg(pg_t pg) {
 
575
  pg_t raw_pg_to_pg(pg_t pg) const {
562
576
    assert(pools.count(pg.pool()));
563
 
    pg_pool_t &pool = pools[pg.pool()];
564
 
    return pool.raw_pg_to_pg(pg);
 
577
    return pools.find(pg.pool())->second.raw_pg_to_pg(pg);
565
578
  }
566
579
 
567
580
  // pg -> primary osd
614
627
      return PG_ROLE_MIDDLE;
615
628
  }
616
629
  
617
 
  int get_pg_role(pg_t pg, int osd) {
 
630
  int get_pg_role(pg_t pg, int osd) const {
618
631
    vector<int> group;
619
632
    int nrep = pg_to_osds(pg, group);
620
633
    return calc_pg_role(osd, group, nrep);
637
650
  /*
638
651
   * handy helpers to build simple maps...
639
652
   */
640
 
  void build_simple(CephContext *cct, epoch_t e, ceph_fsid_t &fsid,
641
 
                    int num_osd, int num_dom,
642
 
                    int pg_bits, int pgp_bits, int lpg_bits);
643
 
  void build_simple_from_conf(CephContext *cct, epoch_t e, ceph_fsid_t &fsid,
 
653
  void build_simple(CephContext *cct, epoch_t e, uuid_d &fsid,
 
654
                    int num_osd, int pg_bits, int pgp_bits, int lpg_bits);
 
655
  void build_simple_from_conf(CephContext *cct, epoch_t e, uuid_d &fsid,
644
656
                              int pg_bits, int pgp_bits, int lpg_bits);
645
657
  static void build_simple_crush_map(CephContext *cct, CrushWrapper& crush,
646
 
                map<int, const char*>& poolsets, int num_osd, int num_dom=0);
 
658
                                     map<int, const char*>& poolsets, int num_osd);
647
659
  static void build_simple_crush_map_from_conf(CephContext *cct, CrushWrapper& crush,
648
660
                                               map<int, const char*>& rulesets);
649
661
 
661
673
 
662
674
};
663
675
 
 
676
typedef std::tr1::shared_ptr<const OSDMap> OSDMapRef;
 
677
 
664
678
inline ostream& operator<<(ostream& out, const OSDMap& m) {
665
679
  m.print_summary(out);
666
680
  return out;