/
osd_types.h
5038 lines (4465 loc) · 148 KB
/
osd_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
* Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
*
* Author: Loic Dachary <loic@dachary.org>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef CEPH_OSD_TYPES_H
#define CEPH_OSD_TYPES_H
#include <sstream>
#include <stdio.h>
#include <memory>
#include <boost/scoped_ptr.hpp>
#include <boost/optional/optional_io.hpp>
#include <boost/variant.hpp>
#include "include/rados/rados_types.hpp"
#include "include/mempool.h"
#include "msg/msg_types.h"
#include "include/types.h"
#include "include/utime.h"
#include "include/CompatSet.h"
#include "common/histogram.h"
#include "include/interval_set.h"
#include "include/inline_memory.h"
#include "common/Formatter.h"
#include "common/bloom_filter.hpp"
#include "common/hobject.h"
#include "common/snap_types.h"
#include "HitSet.h"
#include "Watch.h"
#include "include/cmp.h"
#include "librados/ListObjectImpl.h"
#include "compressor/Compressor.h"
#include <atomic>
#define CEPH_OSD_ONDISK_MAGIC "ceph osd volume v026"
#define CEPH_OSD_FEATURE_INCOMPAT_BASE CompatSet::Feature(1, "initial feature set(~v.18)")
#define CEPH_OSD_FEATURE_INCOMPAT_PGINFO CompatSet::Feature(2, "pginfo object")
#define CEPH_OSD_FEATURE_INCOMPAT_OLOC CompatSet::Feature(3, "object locator")
#define CEPH_OSD_FEATURE_INCOMPAT_LEC CompatSet::Feature(4, "last_epoch_clean")
#define CEPH_OSD_FEATURE_INCOMPAT_CATEGORIES CompatSet::Feature(5, "categories")
#define CEPH_OSD_FEATURE_INCOMPAT_HOBJECTPOOL CompatSet::Feature(6, "hobjectpool")
#define CEPH_OSD_FEATURE_INCOMPAT_BIGINFO CompatSet::Feature(7, "biginfo")
#define CEPH_OSD_FEATURE_INCOMPAT_LEVELDBINFO CompatSet::Feature(8, "leveldbinfo")
#define CEPH_OSD_FEATURE_INCOMPAT_LEVELDBLOG CompatSet::Feature(9, "leveldblog")
#define CEPH_OSD_FEATURE_INCOMPAT_SNAPMAPPER CompatSet::Feature(10, "snapmapper")
#define CEPH_OSD_FEATURE_INCOMPAT_SHARDS CompatSet::Feature(11, "sharded objects")
#define CEPH_OSD_FEATURE_INCOMPAT_HINTS CompatSet::Feature(12, "transaction hints")
#define CEPH_OSD_FEATURE_INCOMPAT_PGMETA CompatSet::Feature(13, "pg meta object")
#define CEPH_OSD_FEATURE_INCOMPAT_MISSING CompatSet::Feature(14, "explicit missing set")
#define CEPH_OSD_FEATURE_INCOMPAT_FASTINFO CompatSet::Feature(15, "fastinfo pg attr")
/// min recovery priority for MBackfillReserve
#define OSD_RECOVERY_PRIORITY_MIN 0
/// base backfill priority for MBackfillReserve
#define OSD_BACKFILL_PRIORITY_BASE 100
/// base backfill priority for MBackfillReserve (degraded PG)
#define OSD_BACKFILL_DEGRADED_PRIORITY_BASE 140
/// base recovery priority for MBackfillReserve
#define OSD_RECOVERY_PRIORITY_BASE 180
/// base backfill priority for MBackfillReserve (inactive PG)
#define OSD_BACKFILL_INACTIVE_PRIORITY_BASE 220
/// max recovery priority for MBackfillReserve
#define OSD_RECOVERY_PRIORITY_MAX 255
typedef hobject_t collection_list_handle_t;
/// convert a single CPEH_OSD_FLAG_* to a string
const char *ceph_osd_flag_name(unsigned flag);
/// convert a single CEPH_OSD_OF_FLAG_* to a string
const char *ceph_osd_op_flag_name(unsigned flag);
/// convert CEPH_OSD_FLAG_* op flags to a string
string ceph_osd_flag_string(unsigned flags);
/// conver CEPH_OSD_OP_FLAG_* op flags to a string
string ceph_osd_op_flag_string(unsigned flags);
/// conver CEPH_OSD_ALLOC_HINT_FLAG_* op flags to a string
string ceph_osd_alloc_hint_flag_string(unsigned flags);
/**
* osd request identifier
*
* caller name + incarnation# + tid to unique identify this request.
*/
struct osd_reqid_t {
entity_name_t name; // who
ceph_tid_t tid;
int32_t inc; // incarnation
osd_reqid_t()
: tid(0), inc(0) {}
osd_reqid_t(const entity_name_t& a, int i, ceph_tid_t t)
: name(a), tid(t), inc(i) {}
DENC(osd_reqid_t, v, p) {
DENC_START(2, 2, p);
denc(v.name, p);
denc(v.tid, p);
denc(v.inc, p);
DENC_FINISH(p);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<osd_reqid_t*>& o);
};
WRITE_CLASS_DENC(osd_reqid_t)
struct pg_shard_t {
int32_t osd;
shard_id_t shard;
pg_shard_t() : osd(-1), shard(shard_id_t::NO_SHARD) {}
explicit pg_shard_t(int osd) : osd(osd), shard(shard_id_t::NO_SHARD) {}
pg_shard_t(int osd, shard_id_t shard) : osd(osd), shard(shard) {}
bool is_undefined() const {
return osd == -1;
}
void encode(bufferlist &bl) const;
void decode(bufferlist::iterator &bl);
void dump(Formatter *f) const {
f->dump_unsigned("osd", osd);
if (shard != shard_id_t::NO_SHARD) {
f->dump_unsigned("shard", shard);
}
}
};
WRITE_CLASS_ENCODER(pg_shard_t)
WRITE_EQ_OPERATORS_2(pg_shard_t, osd, shard)
WRITE_CMP_OPERATORS_2(pg_shard_t, osd, shard)
ostream &operator<<(ostream &lhs, const pg_shard_t &rhs);
class IsPGRecoverablePredicate {
public:
/**
* have encodes the shards available
*/
virtual bool operator()(const set<pg_shard_t> &have) const = 0;
virtual ~IsPGRecoverablePredicate() {}
};
class IsPGReadablePredicate {
public:
/**
* have encodes the shards available
*/
virtual bool operator()(const set<pg_shard_t> &have) const = 0;
virtual ~IsPGReadablePredicate() {}
};
inline ostream& operator<<(ostream& out, const osd_reqid_t& r) {
return out << r.name << "." << r.inc << ":" << r.tid;
}
inline bool operator==(const osd_reqid_t& l, const osd_reqid_t& r) {
return (l.name == r.name) && (l.inc == r.inc) && (l.tid == r.tid);
}
inline bool operator!=(const osd_reqid_t& l, const osd_reqid_t& r) {
return (l.name != r.name) || (l.inc != r.inc) || (l.tid != r.tid);
}
inline bool operator<(const osd_reqid_t& l, const osd_reqid_t& r) {
return (l.name < r.name) || (l.inc < r.inc) ||
(l.name == r.name && l.inc == r.inc && l.tid < r.tid);
}
inline bool operator<=(const osd_reqid_t& l, const osd_reqid_t& r) {
return (l.name < r.name) || (l.inc < r.inc) ||
(l.name == r.name && l.inc == r.inc && l.tid <= r.tid);
}
inline bool operator>(const osd_reqid_t& l, const osd_reqid_t& r) { return !(l <= r); }
inline bool operator>=(const osd_reqid_t& l, const osd_reqid_t& r) { return !(l < r); }
namespace std {
template<> struct hash<osd_reqid_t> {
size_t operator()(const osd_reqid_t &r) const {
static hash<uint64_t> H;
return H(r.name.num() ^ r.tid ^ r.inc);
}
};
} // namespace std
// -----
// a locator constrains the placement of an object. mainly, which pool
// does it go in.
struct object_locator_t {
// You specify either the hash or the key -- not both
int64_t pool; ///< pool id
string key; ///< key string (if non-empty)
string nspace; ///< namespace
int64_t hash; ///< hash position (if >= 0)
explicit object_locator_t()
: pool(-1), hash(-1) {}
explicit object_locator_t(int64_t po)
: pool(po), hash(-1) {}
explicit object_locator_t(int64_t po, int64_t ps)
: pool(po), hash(ps) {}
explicit object_locator_t(int64_t po, string ns)
: pool(po), nspace(ns), hash(-1) {}
explicit object_locator_t(int64_t po, string ns, int64_t ps)
: pool(po), nspace(ns), hash(ps) {}
explicit object_locator_t(int64_t po, string ns, string s)
: pool(po), key(s), nspace(ns), hash(-1) {}
explicit object_locator_t(const hobject_t& soid)
: pool(soid.pool), key(soid.get_key()), nspace(soid.nspace), hash(-1) {}
int64_t get_pool() const {
return pool;
}
void clear() {
pool = -1;
key = "";
nspace = "";
hash = -1;
}
bool empty() const {
return pool == -1;
}
void encode(bufferlist& bl) const;
void decode(bufferlist::iterator& p);
void dump(Formatter *f) const;
static void generate_test_instances(list<object_locator_t*>& o);
};
WRITE_CLASS_ENCODER(object_locator_t)
inline bool operator==(const object_locator_t& l, const object_locator_t& r) {
return l.pool == r.pool && l.key == r.key && l.nspace == r.nspace && l.hash == r.hash;
}
inline bool operator!=(const object_locator_t& l, const object_locator_t& r) {
return !(l == r);
}
inline ostream& operator<<(ostream& out, const object_locator_t& loc)
{
out << "@" << loc.pool;
if (loc.nspace.length())
out << ";" << loc.nspace;
if (loc.key.length())
out << ":" << loc.key;
return out;
}
struct request_redirect_t {
private:
object_locator_t redirect_locator; ///< this is authoritative
string redirect_object; ///< If non-empty, the request goes to this object name
bufferlist osd_instructions; ///< a bufferlist for the OSDs, passed but not interpreted by clients
friend ostream& operator<<(ostream& out, const request_redirect_t& redir);
public:
request_redirect_t() {}
explicit request_redirect_t(const object_locator_t& orig, int64_t rpool) :
redirect_locator(orig) { redirect_locator.pool = rpool; }
explicit request_redirect_t(const object_locator_t& rloc) :
redirect_locator(rloc) {}
explicit request_redirect_t(const object_locator_t& orig,
const string& robj) :
redirect_locator(orig), redirect_object(robj) {}
void set_instructions(const bufferlist& bl) { osd_instructions = bl; }
const bufferlist& get_instructions() { return osd_instructions; }
bool empty() const { return redirect_locator.empty() &&
redirect_object.empty(); }
void combine_with_locator(object_locator_t& orig, string& obj) const {
orig = redirect_locator;
if (!redirect_object.empty())
obj = redirect_object;
}
void encode(bufferlist& bl) const;
void decode(bufferlist::iterator& bl);
void dump(Formatter *f) const;
static void generate_test_instances(list<request_redirect_t*>& o);
};
WRITE_CLASS_ENCODER(request_redirect_t)
inline ostream& operator<<(ostream& out, const request_redirect_t& redir) {
out << "object " << redir.redirect_object << ", locator{" << redir.redirect_locator << "}";
return out;
}
// Internal OSD op flags - set by the OSD based on the op types
enum {
CEPH_OSD_RMW_FLAG_READ = (1 << 1),
CEPH_OSD_RMW_FLAG_WRITE = (1 << 2),
CEPH_OSD_RMW_FLAG_CLASS_READ = (1 << 3),
CEPH_OSD_RMW_FLAG_CLASS_WRITE = (1 << 4),
CEPH_OSD_RMW_FLAG_PGOP = (1 << 5),
CEPH_OSD_RMW_FLAG_CACHE = (1 << 6),
CEPH_OSD_RMW_FLAG_FORCE_PROMOTE = (1 << 7),
CEPH_OSD_RMW_FLAG_SKIP_HANDLE_CACHE = (1 << 8),
CEPH_OSD_RMW_FLAG_SKIP_PROMOTE = (1 << 9),
CEPH_OSD_RMW_FLAG_RWORDERED = (1 << 10),
};
// pg stuff
#define OSD_SUPERBLOCK_GOBJECT ghobject_t(hobject_t(sobject_t(object_t("osd_superblock"), 0)))
// placement seed (a hash value)
typedef uint32_t ps_t;
// old (v1) pg_t encoding (wrap old struct ceph_pg)
struct old_pg_t {
ceph_pg v;
void encode(bufferlist& bl) const {
::encode_raw(v, bl);
}
void decode(bufferlist::iterator& bl) {
::decode_raw(v, bl);
}
};
WRITE_CLASS_ENCODER(old_pg_t)
// placement group id
struct pg_t {
uint64_t m_pool;
uint32_t m_seed;
int32_t m_preferred;
pg_t() : m_pool(0), m_seed(0), m_preferred(-1) {}
pg_t(ps_t seed, uint64_t pool, int pref=-1) :
m_pool(pool), m_seed(seed), m_preferred(pref) {}
// cppcheck-suppress noExplicitConstructor
pg_t(const ceph_pg& cpg) :
m_pool(cpg.pool), m_seed(cpg.ps), m_preferred((__s16)cpg.preferred) {}
// cppcheck-suppress noExplicitConstructor
pg_t(const old_pg_t& opg) {
*this = opg.v;
}
old_pg_t get_old_pg() const {
old_pg_t o;
assert(m_pool < 0xffffffffull);
o.v.pool = m_pool;
o.v.ps = m_seed;
o.v.preferred = (__s16)m_preferred;
return o;
}
ps_t ps() const {
return m_seed;
}
uint64_t pool() const {
return m_pool;
}
int32_t preferred() const {
return m_preferred;
}
static const uint8_t calc_name_buf_size = 36; // max length for max values len("18446744073709551615.ffffffff") + future suffix len("_head") + '\0'
char *calc_name(char *buf, const char *suffix_backwords) const;
void set_ps(ps_t p) {
m_seed = p;
}
void set_pool(uint64_t p) {
m_pool = p;
}
void set_preferred(int32_t osd) {
m_preferred = osd;
}
pg_t get_parent() const;
pg_t get_ancestor(unsigned old_pg_num) const;
int print(char *o, int maxlen) const;
bool parse(const char *s);
bool is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t> *pchildren) const;
/**
* Returns b such that for all object o:
* ~((~0)<<b) & o.hash) == 0 iff o is in the pg for *this
*/
unsigned get_split_bits(unsigned pg_num) const;
bool contains(int bits, const ghobject_t& oid) {
return oid.match(bits, ps());
}
bool contains(int bits, const hobject_t& oid) {
return oid.match(bits, ps());
}
hobject_t get_hobj_start() const;
hobject_t get_hobj_end(unsigned pg_num) const;
void encode(bufferlist& bl) const {
__u8 v = 1;
::encode(v, bl);
::encode(m_pool, bl);
::encode(m_seed, bl);
::encode(m_preferred, bl);
}
void decode(bufferlist::iterator& bl) {
__u8 v;
::decode(v, bl);
::decode(m_pool, bl);
::decode(m_seed, bl);
::decode(m_preferred, bl);
}
void decode_old(bufferlist::iterator& bl) {
old_pg_t opg;
::decode(opg, bl);
*this = opg;
}
void dump(Formatter *f) const;
static void generate_test_instances(list<pg_t*>& o);
};
WRITE_CLASS_ENCODER(pg_t)
inline bool operator<(const pg_t& l, const pg_t& r) {
return l.pool() < r.pool() ||
(l.pool() == r.pool() && (l.preferred() < r.preferred() ||
(l.preferred() == r.preferred() && (l.ps() < r.ps()))));
}
inline bool operator<=(const pg_t& l, const pg_t& r) {
return l.pool() < r.pool() ||
(l.pool() == r.pool() && (l.preferred() < r.preferred() ||
(l.preferred() == r.preferred() && (l.ps() <= r.ps()))));
}
inline bool operator==(const pg_t& l, const pg_t& r) {
return l.pool() == r.pool() &&
l.preferred() == r.preferred() &&
l.ps() == r.ps();
}
inline bool operator!=(const pg_t& l, const pg_t& r) {
return l.pool() != r.pool() ||
l.preferred() != r.preferred() ||
l.ps() != r.ps();
}
inline bool operator>(const pg_t& l, const pg_t& r) {
return l.pool() > r.pool() ||
(l.pool() == r.pool() && (l.preferred() > r.preferred() ||
(l.preferred() == r.preferred() && (l.ps() > r.ps()))));
}
inline bool operator>=(const pg_t& l, const pg_t& r) {
return l.pool() > r.pool() ||
(l.pool() == r.pool() && (l.preferred() > r.preferred() ||
(l.preferred() == r.preferred() && (l.ps() >= r.ps()))));
}
ostream& operator<<(ostream& out, const pg_t &pg);
namespace std {
template<> struct hash< pg_t >
{
size_t operator()( const pg_t& x ) const
{
static hash<uint32_t> H;
return H((x.pool() & 0xffffffff) ^ (x.pool() >> 32) ^ x.ps() ^ x.preferred());
}
};
} // namespace std
struct spg_t {
pg_t pgid;
shard_id_t shard;
spg_t() : shard(shard_id_t::NO_SHARD) {}
spg_t(pg_t pgid, shard_id_t shard) : pgid(pgid), shard(shard) {}
explicit spg_t(pg_t pgid) : pgid(pgid), shard(shard_id_t::NO_SHARD) {}
unsigned get_split_bits(unsigned pg_num) const {
return pgid.get_split_bits(pg_num);
}
spg_t get_parent() const {
return spg_t(pgid.get_parent(), shard);
}
ps_t ps() const {
return pgid.ps();
}
uint64_t pool() const {
return pgid.pool();
}
int32_t preferred() const {
return pgid.preferred();
}
static const uint8_t calc_name_buf_size = pg_t::calc_name_buf_size + 4; // 36 + len('s') + len("255");
char *calc_name(char *buf, const char *suffix_backwords) const;
bool parse(const char *s);
bool parse(const std::string& s) {
return parse(s.c_str());
}
bool is_split(unsigned old_pg_num, unsigned new_pg_num,
set<spg_t> *pchildren) const {
set<pg_t> _children;
set<pg_t> *children = pchildren ? &_children : NULL;
bool is_split = pgid.is_split(old_pg_num, new_pg_num, children);
if (pchildren && is_split) {
for (set<pg_t>::iterator i = _children.begin();
i != _children.end();
++i) {
pchildren->insert(spg_t(*i, shard));
}
}
return is_split;
}
bool is_no_shard() const {
return shard == shard_id_t::NO_SHARD;
}
ghobject_t make_pgmeta_oid() const {
return ghobject_t::make_pgmeta(pgid.pool(), pgid.ps(), shard);
}
void encode(bufferlist &bl) const {
ENCODE_START(1, 1, bl);
::encode(pgid, bl);
::encode(shard, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator &bl) {
DECODE_START(1, bl);
::decode(pgid, bl);
::decode(shard, bl);
DECODE_FINISH(bl);
}
ghobject_t make_temp_ghobject(const string& name) const {
return ghobject_t(
hobject_t(object_t(name), "", CEPH_NOSNAP,
pgid.ps(),
hobject_t::POOL_TEMP_START - pgid.pool(), ""),
ghobject_t::NO_GEN,
shard);
}
unsigned hash_to_shard(unsigned num_shards) const {
return ps() % num_shards;
}
};
WRITE_CLASS_ENCODER(spg_t)
WRITE_EQ_OPERATORS_2(spg_t, pgid, shard)
WRITE_CMP_OPERATORS_2(spg_t, pgid, shard)
namespace std {
template<> struct hash< spg_t >
{
size_t operator()( const spg_t& x ) const
{
static hash<uint32_t> H;
return H(hash<pg_t>()(x.pgid) ^ x.shard);
}
};
} // namespace std
ostream& operator<<(ostream& out, const spg_t &pg);
// ----------------------
class coll_t {
enum type_t {
TYPE_META = 0,
TYPE_LEGACY_TEMP = 1, /* no longer used */
TYPE_PG = 2,
TYPE_PG_TEMP = 3,
};
type_t type;
spg_t pgid;
uint64_t removal_seq; // note: deprecated, not encoded
char _str_buff[spg_t::calc_name_buf_size];
char *_str;
void calc_str();
coll_t(type_t t, spg_t p, uint64_t r)
: type(t), pgid(p), removal_seq(r) {
calc_str();
}
public:
coll_t() : type(TYPE_META), removal_seq(0)
{
calc_str();
}
coll_t(const coll_t& other)
: type(other.type), pgid(other.pgid), removal_seq(other.removal_seq) {
calc_str();
}
explicit coll_t(spg_t pgid)
: type(TYPE_PG), pgid(pgid), removal_seq(0)
{
calc_str();
}
coll_t& operator=(const coll_t& rhs)
{
this->type = rhs.type;
this->pgid = rhs.pgid;
this->removal_seq = rhs.removal_seq;
this->calc_str();
return *this;
}
// named constructors
static coll_t meta() {
return coll_t();
}
static coll_t pg(spg_t p) {
return coll_t(p);
}
const std::string to_str() const {
return string(_str);
}
const char *c_str() const {
return _str;
}
bool parse(const std::string& s);
int operator<(const coll_t &rhs) const {
return type < rhs.type ||
(type == rhs.type && pgid < rhs.pgid);
}
bool is_meta() const {
return type == TYPE_META;
}
bool is_pg_prefix(spg_t *pgid_) const {
if (type == TYPE_PG || type == TYPE_PG_TEMP) {
*pgid_ = pgid;
return true;
}
return false;
}
bool is_pg() const {
return type == TYPE_PG;
}
bool is_pg(spg_t *pgid_) const {
if (type == TYPE_PG) {
*pgid_ = pgid;
return true;
}
return false;
}
bool is_temp() const {
return type == TYPE_PG_TEMP;
}
bool is_temp(spg_t *pgid_) const {
if (type == TYPE_PG_TEMP) {
*pgid_ = pgid;
return true;
}
return false;
}
void encode(bufferlist& bl) const;
void decode(bufferlist::iterator& bl);
size_t encoded_size() const;
inline bool operator==(const coll_t& rhs) const {
// only compare type if meta
if (type != rhs.type)
return false;
if (type == TYPE_META)
return true;
return type == rhs.type && pgid == rhs.pgid;
}
inline bool operator!=(const coll_t& rhs) const {
return !(*this == rhs);
}
// get a TEMP collection that corresponds to the current collection,
// which we presume is a pg collection.
coll_t get_temp() const {
assert(type == TYPE_PG);
return coll_t(TYPE_PG_TEMP, pgid, 0);
}
ghobject_t get_min_hobj() const {
ghobject_t o;
switch (type) {
case TYPE_PG:
o.hobj.pool = pgid.pool();
o.set_shard(pgid.shard);
break;
case TYPE_META:
o.hobj.pool = -1;
break;
default:
break;
}
return o;
}
unsigned hash_to_shard(unsigned num_shards) const {
if (type == TYPE_PG)
return pgid.hash_to_shard(num_shards);
return 0; // whatever.
}
void dump(Formatter *f) const;
static void generate_test_instances(list<coll_t*>& o);
};
WRITE_CLASS_ENCODER(coll_t)
inline ostream& operator<<(ostream& out, const coll_t& c) {
out << c.to_str();
return out;
}
namespace std {
template<> struct hash<coll_t> {
size_t operator()(const coll_t &c) const {
size_t h = 0;
string str(c.to_str());
std::string::const_iterator end(str.end());
for (std::string::const_iterator s = str.begin(); s != end; ++s) {
h += *s;
h += (h << 10);
h ^= (h >> 6);
}
h += (h << 3);
h ^= (h >> 11);
h += (h << 15);
return h;
}
};
} // namespace std
inline ostream& operator<<(ostream& out, const ceph_object_layout &ol)
{
out << pg_t(ol.ol_pgid);
int su = ol.ol_stripe_unit;
if (su)
out << ".su=" << su;
return out;
}
// compound rados version type
/* WARNING: If add member in eversion_t, please make sure the encode/decode function
* work well. For little-endian machine, we should make sure there is no padding
* in 32-bit machine and 64-bit machine.
*/
class eversion_t {
public:
version_t version;
epoch_t epoch;
__u32 __pad;
eversion_t() : version(0), epoch(0), __pad(0) {}
eversion_t(epoch_t e, version_t v) : version(v), epoch(e), __pad(0) {}
// cppcheck-suppress noExplicitConstructor
eversion_t(const ceph_eversion& ce) :
version(ce.version),
epoch(ce.epoch),
__pad(0) { }
explicit eversion_t(bufferlist& bl) : __pad(0) { decode(bl); }
static eversion_t max() {
eversion_t max;
max.version -= 1;
max.epoch -= 1;
return max;
}
operator ceph_eversion() {
ceph_eversion c;
c.epoch = epoch;
c.version = version;
return c;
}
string get_key_name() const;
void encode(bufferlist &bl) const {
#if defined(CEPH_LITTLE_ENDIAN)
bl.append((char *)this, sizeof(version_t) + sizeof(epoch_t));
#else
::encode(version, bl);
::encode(epoch, bl);
#endif
}
void decode(bufferlist::iterator &bl) {
#if defined(CEPH_LITTLE_ENDIAN)
bl.copy(sizeof(version_t) + sizeof(epoch_t), (char *)this);
#else
::decode(version, bl);
::decode(epoch, bl);
#endif
}
void decode(bufferlist& bl) {
bufferlist::iterator p = bl.begin();
decode(p);
}
};
WRITE_CLASS_ENCODER(eversion_t)
inline bool operator==(const eversion_t& l, const eversion_t& r) {
return (l.epoch == r.epoch) && (l.version == r.version);
}
inline bool operator!=(const eversion_t& l, const eversion_t& r) {
return (l.epoch != r.epoch) || (l.version != r.version);
}
inline bool operator<(const eversion_t& l, const eversion_t& r) {
return (l.epoch == r.epoch) ? (l.version < r.version):(l.epoch < r.epoch);
}
inline bool operator<=(const eversion_t& l, const eversion_t& r) {
return (l.epoch == r.epoch) ? (l.version <= r.version):(l.epoch <= r.epoch);
}
inline bool operator>(const eversion_t& l, const eversion_t& r) {
return (l.epoch == r.epoch) ? (l.version > r.version):(l.epoch > r.epoch);
}
inline bool operator>=(const eversion_t& l, const eversion_t& r) {
return (l.epoch == r.epoch) ? (l.version >= r.version):(l.epoch >= r.epoch);
}
inline ostream& operator<<(ostream& out, const eversion_t& e) {
return out << e.epoch << "'" << e.version;
}
/**
* objectstore_perf_stat_t
*
* current perf information about the osd
*/
struct objectstore_perf_stat_t {
// cur_op_latency is in ms since double add/sub are not associative
uint32_t os_commit_latency;
uint32_t os_apply_latency;
objectstore_perf_stat_t() :
os_commit_latency(0), os_apply_latency(0) {}
bool operator==(const objectstore_perf_stat_t &r) const {
return os_commit_latency == r.os_commit_latency &&
os_apply_latency == r.os_apply_latency;
}
void add(const objectstore_perf_stat_t &o) {
os_commit_latency += o.os_commit_latency;
os_apply_latency += o.os_apply_latency;
}
void sub(const objectstore_perf_stat_t &o) {
os_commit_latency -= o.os_commit_latency;
os_apply_latency -= o.os_apply_latency;
}
void dump(Formatter *f) const;
void encode(bufferlist &bl) const;
void decode(bufferlist::iterator &bl);
static void generate_test_instances(std::list<objectstore_perf_stat_t*>& o);
};
WRITE_CLASS_ENCODER(objectstore_perf_stat_t)
/** osd_stat
* aggregate stats for an osd
*/
struct osd_stat_t {
int64_t kb, kb_used, kb_avail;
vector<int> hb_peers;
int32_t snap_trim_queue_len, num_snap_trimming;
pow2_hist_t op_queue_age_hist;
objectstore_perf_stat_t os_perf_stat;
osd_stat_t() : kb(0), kb_used(0), kb_avail(0),
snap_trim_queue_len(0), num_snap_trimming(0) {}
void add(const osd_stat_t& o) {
kb += o.kb;
kb_used += o.kb_used;
kb_avail += o.kb_avail;
snap_trim_queue_len += o.snap_trim_queue_len;
num_snap_trimming += o.num_snap_trimming;
op_queue_age_hist.add(o.op_queue_age_hist);
os_perf_stat.add(o.os_perf_stat);
}
void sub(const osd_stat_t& o) {
kb -= o.kb;
kb_used -= o.kb_used;
kb_avail -= o.kb_avail;
snap_trim_queue_len -= o.snap_trim_queue_len;
num_snap_trimming -= o.num_snap_trimming;
op_queue_age_hist.sub(o.op_queue_age_hist);
os_perf_stat.sub(o.os_perf_stat);
}
void dump(Formatter *f) const;
void encode(bufferlist &bl) const;
void decode(bufferlist::iterator &bl);
static void generate_test_instances(std::list<osd_stat_t*>& o);
};
WRITE_CLASS_ENCODER(osd_stat_t)
inline bool operator==(const osd_stat_t& l, const osd_stat_t& r) {
return l.kb == r.kb &&
l.kb_used == r.kb_used &&
l.kb_avail == r.kb_avail &&
l.snap_trim_queue_len == r.snap_trim_queue_len &&
l.num_snap_trimming == r.num_snap_trimming &&
l.hb_peers == r.hb_peers &&
l.op_queue_age_hist == r.op_queue_age_hist &&
l.os_perf_stat == r.os_perf_stat;
}
inline bool operator!=(const osd_stat_t& l, const osd_stat_t& r) {
return !(l == r);
}
inline ostream& operator<<(ostream& out, const osd_stat_t& s) {
return out << "osd_stat(" << kb_t(s.kb_used) << " used, "
<< kb_t(s.kb_avail) << " avail, "
<< kb_t(s.kb) << " total, "
<< "peers " << s.hb_peers
<< " op hist " << s.op_queue_age_hist.h
<< ")";
}
/*
* pg states
*/
#define PG_STATE_CREATING (1<<0) // creating
#define PG_STATE_ACTIVE (1<<1) // i am active. (primary: replicas too)
#define PG_STATE_CLEAN (1<<2) // peers are complete, clean of stray replicas.
#define PG_STATE_DOWN (1<<4) // a needed replica is down, PG offline
//#define PG_STATE_REPLAY (1<<5) // crashed, waiting for replay
//#define PG_STATE_STRAY (1<<6) // i must notify the primary i exist.
//#define PG_STATE_SPLITTING (1<<7) // i am splitting
#define PG_STATE_SCRUBBING (1<<8) // scrubbing
//#define PG_STATE_SCRUBQ (1<<9) // queued for scrub
#define PG_STATE_DEGRADED (1<<10) // pg contains objects with reduced redundancy
#define PG_STATE_INCONSISTENT (1<<11) // pg replicas are inconsistent (but shouldn't be)
#define PG_STATE_PEERING (1<<12) // pg is (re)peering
#define PG_STATE_REPAIR (1<<13) // pg should repair on next scrub
#define PG_STATE_RECOVERING (1<<14) // pg is recovering/migrating objects
#define PG_STATE_BACKFILL_WAIT (1<<15) // [active] reserving backfill
#define PG_STATE_INCOMPLETE (1<<16) // incomplete content, peering failed.
#define PG_STATE_STALE (1<<17) // our state for this pg is stale, unknown.
#define PG_STATE_REMAPPED (1<<18) // pg is explicitly remapped to different OSDs than CRUSH
#define PG_STATE_DEEP_SCRUB (1<<19) // deep scrub: check CRC32 on files
#define PG_STATE_BACKFILL (1<<20) // [active] backfilling pg content
#define PG_STATE_BACKFILL_TOOFULL (1<<21) // backfill can't proceed: too full
#define PG_STATE_RECOVERY_WAIT (1<<22) // waiting for recovery reservations
#define PG_STATE_UNDERSIZED (1<<23) // pg acting < pool size
#define PG_STATE_ACTIVATING (1<<24) // pg is peered but not yet active
#define PG_STATE_PEERED (1<<25) // peered, cannot go active, can recover
#define PG_STATE_SNAPTRIM (1<<26) // trimming snaps
#define PG_STATE_SNAPTRIM_WAIT (1<<27) // queued to trim snaps
#define PG_STATE_RECOVERY_TOOFULL (1<<28) // recovery can't proceed: too full
std::string pg_state_string(int state);
std::string pg_vector_string(const vector<int32_t> &a);
int pg_string_state(const std::string& state);
/*
* pool_snap_info_t
*
* attributes for a single pool snapshot.
*/
struct pool_snap_info_t {
snapid_t snapid;
utime_t stamp;
string name;
void dump(Formatter *f) const;
void encode(bufferlist& bl, uint64_t features) const;
void decode(bufferlist::iterator& bl);
static void generate_test_instances(list<pool_snap_info_t*>& o);