Skip to content

Commit

Permalink
mon, osd: add create-time for pool
Browse files Browse the repository at this point in the history
We want to know how old the pools currently are, on which mgr/balancer
can make some time-related smart decisions based.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
  • Loading branch information
xiexingguo committed Apr 28, 2018
1 parent 0cb3e64 commit 47359a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/mon/OSDMonitor.cc
Expand Up @@ -6470,6 +6470,7 @@ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid,
int64_t pool = ++pending_inc.new_pool_max;
pg_pool_t empty;
pg_pool_t *pi = pending_inc.get_new_pool(pool, &empty);
pi->create_time = ceph_clock_now();
pi->type = pool_type;
pi->fast_read = fread;
pi->flags = g_conf->osd_pool_default_flags;
Expand Down
14 changes: 12 additions & 2 deletions src/osd/osd_types.cc
Expand Up @@ -1163,6 +1163,7 @@ const char *pg_pool_t::APPLICATION_NAME_RGW("rgw");

void pg_pool_t::dump(Formatter *f) const
{
f->dump_stream("create_time") << get_create_time();
f->dump_unsigned("flags", get_flags());
f->dump_string("flags_names", get_flags_string());
f->dump_int("type", get_type());
Expand Down Expand Up @@ -1554,7 +1555,7 @@ void pg_pool_t::encode(bufferlist& bl, uint64_t features) const
return;
}

uint8_t v = 26;
uint8_t v = 27;
// NOTE: any new encoding dependencies must be reflected by
// SIGNIFICANT_FEATURES
if (!(features & CEPH_FEATURE_NEW_OSDOP_ENCODING)) {
Expand All @@ -1563,6 +1564,8 @@ void pg_pool_t::encode(bufferlist& bl, uint64_t features) const
v = 21;
} else if (!HAVE_FEATURE(features, SERVER_LUMINOUS)) {
v = 24;
} else if (!HAVE_FEATURE(features, SERVER_MIMIC)) {
v = 26;
}

ENCODE_START(v, 5, bl);
Expand Down Expand Up @@ -1638,12 +1641,15 @@ void pg_pool_t::encode(bufferlist& bl, uint64_t features) const
if (v >= 26) {
encode(application_metadata, bl);
}
if (v >= 27) {
encode(create_time, bl);
}
ENCODE_FINISH(bl);
}

void pg_pool_t::decode(bufferlist::iterator& bl)
{
DECODE_START_LEGACY_COMPAT_LEN(26, 5, 5, bl);
DECODE_START_LEGACY_COMPAT_LEN(27, 5, 5, bl);
decode(type, bl);
decode(size, bl);
decode(crush_rule, bl);
Expand Down Expand Up @@ -1793,6 +1799,9 @@ void pg_pool_t::decode(bufferlist::iterator& bl)
if (struct_v >= 26) {
decode(application_metadata, bl);
}
if (struct_v >= 27) {
decode(create_time, bl);
}
DECODE_FINISH(bl);
calc_pg_masks();
calc_grade_table();
Expand All @@ -1803,6 +1812,7 @@ void pg_pool_t::generate_test_instances(list<pg_pool_t*>& o)
pg_pool_t a;
o.push_back(new pg_pool_t(a));

a.create_time = utime_t(4,5);
a.type = TYPE_REPLICATED;
a.size = 2;
a.crush_rule = 3;
Expand Down
2 changes: 2 additions & 0 deletions src/osd/osd_types.h
Expand Up @@ -1295,6 +1295,7 @@ struct pg_pool_t {
}
}

utime_t create_time;
uint64_t flags; ///< FLAG_*
__u8 type; ///< TYPE_*
__u8 size, min_size; ///< number of osds in each pg
Expand Down Expand Up @@ -1456,6 +1457,7 @@ struct pg_pool_t {

void dump(Formatter *f) const;

const utime_t &get_create_time() const { return create_time; }
uint64_t get_flags() const { return flags; }
bool has_flag(uint64_t f) const { return flags & f; }
void set_flag(uint64_t f) { flags |= f; }
Expand Down

0 comments on commit 47359a3

Please sign in to comment.