// -- coll_t --
-std::string coll_t::to_str() const
+void coll_t::calc_str()
{
switch (type) {
case TYPE_META:
- return "meta";
+ _str = "meta";
+ break;
case TYPE_PG:
- return stringify(pgid) + "_head";
+ _str = stringify(pgid) + "_head";
+ break;
case TYPE_PG_TEMP:
- return stringify(pgid) + "_TEMP";
+ _str = stringify(pgid) + "_TEMP";
+ break;
case TYPE_PG_REMOVAL:
- return string("FORREMOVAL_") +
+ _str = string("FORREMOVAL_") +
stringify(removal_seq) + "_" +
stringify(pgid);
+ break;
default:
assert(0 == "unknown collection type");
}
type = TYPE_META;
pgid = spg_t();
removal_seq = 0;
+ calc_str();
+ assert(s == _str);
return true;
}
if (s.find("_head") == s.length() - 5 &&
pgid.parse(s.substr(0, s.length() - 5))) {
type = TYPE_PG;
removal_seq = 0;
+ calc_str();
+ assert(s == _str);
return true;
}
if (s.find("_TEMP") == s.length() - 5 &&
pgid.parse(s.substr(0, s.length() - 5))) {
type = TYPE_PG_TEMP;
removal_seq = 0;
+ calc_str();
+ assert(s == _str);
return true;
}
if (s.find("FORREMOVAL_") == 0) {
assert(0);
return false;
}
+ calc_str();
+ assert(s == _str);
return true;
}
return false;
spg_t pgid;
uint64_t removal_seq; // note: deprecated, not encoded
+ string _str; // cached string
+
+ 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) {}
+ : type(other.type), pgid(other.pgid), removal_seq(other.removal_seq) {
+ calc_str();
+ }
explicit coll_t(spg_t pgid)
: type(TYPE_PG), pgid(pgid)
- { }
+ {
+ calc_str();
+ }
- std::string to_str() const;
+ const std::string& to_str() const {
+ return _str;
+ }
bool parse(const std::string& s);
int operator<(const coll_t &rhs) const {
// get a TEMP collection that corresponds to the current collection,
// which we presume is a pg collection.
- coll_t get_temp() {
+ coll_t get_temp() const {
assert(type == TYPE_PG);
- coll_t other;
- other.type = TYPE_PG_TEMP;
- other.pgid = pgid;
- return other;
+ return coll_t(TYPE_PG_TEMP, pgid, 0);
}
void dump(Formatter *f) const;