228
233
// ----------------------
240
coll_t() : type(TYPE_META), snap(0) {}
241
coll_t(type_t t) : type(t), snap(0) {}
242
coll_t(type_t t, pg_t p, snapid_t s) : type(t), pgid(p), snap(s) {}
244
static coll_t build_pg_coll(pg_t p) {
245
return coll_t(TYPE_PG, p, CEPH_NOSNAP);
247
static coll_t build_snap_pg_coll(pg_t p, snapid_t s) {
248
return coll_t(TYPE_PG, p, s);
251
ostream& print(ostream& out) const {
254
return out << "meta";
256
return out << "temp";
258
out << pgid << "_" << snap;
263
int print(char *o, int maxlen) {
266
return snprintf(o, maxlen, "meta");
268
return snprintf(o, maxlen, "temp");
271
int len = pgid.print(o, maxlen);
272
if (snap != CEPH_NOSNAP)
273
len += snprintf(o + len, maxlen - len, "_%llx", (long long unsigned)snap);
275
strncat(o + len, "_head", maxlen - len);
237
const static coll_t META_COLL;
238
const static coll_t TEMP_COLL;
244
explicit coll_t(const std::string &str_)
248
explicit coll_t(pg_t pgid, snapid_t snap = CEPH_NOSNAP)
249
: str(pg_and_snap_to_str(pgid, snap))
252
const std::string& to_str() const {
256
const char* c_str() const {
260
bool is_pg(pg_t& pgid, snapid_t& snap) const {
261
const char *cstr(str.c_str());
263
if (!pgid.parse(cstr))
265
const char *snap_start = strchr(cstr, '_');
268
if (strncmp(snap_start, "_head", 5) == 0)
271
snap = strtoull(snap_start+1, 0, 16);
275
void encode(bufferlist& bl) const {
277
::encode(struct_v, bl);
281
void decode(bufferlist::iterator& bl) {
283
::decode(struct_v, bl);
292
if (pgid == pg_t() && snap == 0)
295
str = pg_and_snap_to_str(pgid, snap);
315
str = pg_and_snap_to_str(pgid, snap);
319
oss << "coll_t::decode(): can't understand type " << type;
320
throw std::domain_error(oss.str());
281
return snprintf(o, maxlen, "???");
284
bool parse(char *s) {
285
if (strncmp(s, "meta", 4) == 0) {
291
if (strncmp(s, "temp", 4) == 0) {
299
char *sn = strchr(s, '_');
302
if (strncmp(sn, "_head", 5) == 0)
305
snap = strtoull(sn+1, 0, 16);
310
void encode(bufferlist& bl) const {
312
::encode(struct_v, bl);
317
void decode(bufferlist::iterator& bl) {
319
::decode(struct_v, bl);
326
if (pgid == pg_t() && snap == 0)
332
oss << "coll_t::decode(): don't know how to decode verison "
334
throw std::domain_error(oss.str());
338
inline bool operator==(const coll_t& rhs) const {
339
return str == rhs.str;
341
inline bool operator!=(const coll_t& rhs) const {
342
return str != rhs.str;
346
static std::string pg_and_snap_to_str(pg_t p, snapid_t s) {
347
std::ostringstream oss;
348
oss << p << "_" << s;
333
355
WRITE_CLASS_ENCODER(coll_t)
335
357
inline ostream& operator<<(ostream& out, const coll_t& c) {
339
#define TRIPLE_EQ(l, r, a, b, c) \
340
l.a == r.a && l.b == r.b && l.c == r.c;
341
#define TRIPLE_NE(l, r, a, b, c) \
342
l.a != r.a && l.b != r.b && l.c != r.c;
343
#define TRIPLE_LT(l, r, a, b, c) \
344
l.a < r.a || (l.a == r.a && (l.b < r.b || \
345
(l.b == r.b && l.c < r.c)));
346
#define TRIPLE_LTE(l, r, a, b, c) \
347
l.a < r.a || (l.a == r.a && (l.b < r.b || \
348
(l.b == r.b && l.c <= r.c)));
349
#define TRIPLE_GT(l, r, a, b, c) \
350
l.a > r.a || (l.a == r.a && (l.b > r.b || \
351
(l.b == r.b && l.c > r.c)));
352
#define TRIPLE_GTE(l, r, a, b, c) \
353
l.a > r.a || (l.a == r.a && (l.b > r.b || \
354
(l.b == r.b && l.c >= r.c)));
356
inline bool operator<(const coll_t& l, const coll_t& r) {
357
return TRIPLE_LT(l, r, type, pgid, snap);
359
inline bool operator<=(const coll_t& l, const coll_t& r) {
360
return TRIPLE_LTE(l, r, type, pgid, snap);
362
inline bool operator==(const coll_t& l, const coll_t& r) {
363
return TRIPLE_EQ(l, r, type, pgid, snap);
365
inline bool operator!=(const coll_t& l, const coll_t& r) {
366
return TRIPLE_NE(l, r, type, pgid, snap);
368
inline bool operator>(const coll_t& l, const coll_t& r) {
369
return TRIPLE_GT(l, r, type, pgid, snap);
371
inline bool operator>=(const coll_t& l, const coll_t& r) {
372
return TRIPLE_GTE(l, r, type, pgid, snap);
375
362
namespace __gnu_cxx {
376
363
template<> struct hash<coll_t> {
377
364
size_t operator()(const coll_t &c) const {
379
static rjhash<uint64_t> I;
380
return H(c.pgid) ^ I(c.snap + c.type);
366
string str(c.to_str());
367
std::string::const_iterator end(str.end());
368
for (std::string::const_iterator s = str.begin(); s != end; ++s) {
370
hash += (hash << 10);
374
hash ^= (hash >> 11);
375
hash += (hash << 15);
387
381
inline ostream& operator<<(ostream& out, const ceph_object_layout &ol)
389
383
out << pg_t(ol.ol_pgid);
557
551
#define PG_STATE_REPAIR (1<<13) // pg should repair on next scrub
558
552
#define PG_STATE_SCANNING (1<<14) // scanning content to generate backlog
560
static inline std::string pg_state_string(int state) {
562
if (state & PG_STATE_CREATING) st += "creating+";
563
if (state & PG_STATE_ACTIVE) st += "active+";
564
if (state & PG_STATE_CLEAN) st += "clean+";
565
if (state & PG_STATE_CRASHED) st += "crashed+";
566
if (state & PG_STATE_DOWN) st += "down+";
567
if (state & PG_STATE_REPLAY) st += "replay+";
568
if (state & PG_STATE_STRAY) st += "stray+";
569
if (state & PG_STATE_SPLITTING) st += "splitting+";
570
if (state & PG_STATE_DEGRADED) st += "degraded+";
571
if (state & PG_STATE_SCRUBBING) st += "scrubbing+";
572
if (state & PG_STATE_SCRUBQ) st += "scrubq+";
573
if (state & PG_STATE_INCONSISTENT) st += "inconsistent+";
574
if (state & PG_STATE_PEERING) st += "peering+";
575
if (state & PG_STATE_REPAIR) st += "repair+";
576
if (state & PG_STATE_SCANNING) st += "scanning+";
580
st.resize(st.length()-1);
554
static inline std::string pg_state_string(int state)
557
if (state & PG_STATE_CREATING)
559
if (state & PG_STATE_ACTIVE)
561
if (state & PG_STATE_CLEAN)
563
if (state & PG_STATE_CRASHED)
565
if (state & PG_STATE_DOWN)
567
if (state & PG_STATE_REPLAY)
569
if (state & PG_STATE_STRAY)
571
if (state & PG_STATE_SPLITTING)
573
if (state & PG_STATE_DEGRADED)
575
if (state & PG_STATE_SCRUBBING)
577
if (state & PG_STATE_SCRUBQ)
579
if (state & PG_STATE_INCONSISTENT)
580
oss << "inconsistent+";
581
if (state & PG_STATE_PEERING)
583
if (state & PG_STATE_REPAIR)
585
if (state & PG_STATE_SCANNING)
587
string ret(oss.str());
588
if (ret.length() > 0)
589
ret.resize(ret.length() - 1);