Skip to content
Permalink
Browse files

osd: filter the trackedop that we needed.

Signed-off-by: Yan Jun <yan.jun8@zte.com.cn>
  • Loading branch information...
Yan-waller committed Jul 25, 2017
1 parent 237d951 commit 814de29d02912a7cd6c5e24db6d99664693b4a58
Showing with 114 additions and 45 deletions.
  1. +17 −9 src/common/TrackedOp.cc
  2. +8 −6 src/common/TrackedOp.h
  3. +60 −30 src/osd/OSD.cc
  4. +28 −0 src/osd/OpRequest.cc
  5. +1 −0 src/osd/OpRequest.h
@@ -68,7 +68,7 @@ void OpHistory::cleanup(utime_t now)
}
}

void OpHistory::dump_ops(utime_t now, Formatter *f)
void OpHistory::dump_ops(utime_t now, Formatter *f, set<string> filters)
{
Mutex::Locker history_lock(ops_history_lock);
cleanup(now);
@@ -81,6 +81,8 @@ void OpHistory::dump_ops(utime_t now, Formatter *f)
arrived.begin();
i != arrived.end();
++i) {
if (!i->second->filter_out(filters))
continue;
f->open_object_section("op");
i->second->dump(now, f);
f->close_section();
@@ -90,7 +92,7 @@ void OpHistory::dump_ops(utime_t now, Formatter *f)
f->close_section();
}

void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f)
void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f, set<string> filters)
{
Mutex::Locker history_lock(ops_history_lock);
cleanup(now);
@@ -107,6 +109,8 @@ void OpHistory::dump_ops_by_duration(utime_t now, Formatter *f)
arrived.begin();
i != arrived.end();
++i) {
if (!i->second->filter_out(filters))
continue;
durationvec.push_back(pair<double, TrackedOpRef>(i->second->get_duration(), i->second));
}

@@ -152,22 +156,22 @@ OpTracker::~OpTracker() {
}
}

bool OpTracker::dump_historic_ops(Formatter *f, bool by_duration)
bool OpTracker::dump_historic_ops(Formatter *f, bool by_duration, set<string> filters)
{
RWLock::RLocker l(lock);
if (!tracking_enabled)
return false;

utime_t now = ceph_clock_now();
if (by_duration) {
history.dump_ops_by_duration(now, f);
history.dump_ops_by_duration(now, f, filters);
} else {
history.dump_ops(now, f);
history.dump_ops(now, f, filters);
}
return true;
}

void OpHistory::dump_slow_ops(utime_t now, Formatter *f)
void OpHistory::dump_slow_ops(utime_t now, Formatter *f, set<string> filters)
{
Mutex::Locker history_lock(ops_history_lock);
cleanup(now);
@@ -180,6 +184,8 @@ void OpHistory::dump_slow_ops(utime_t now, Formatter *f)
slow_op.begin();
i != slow_op.end();
++i) {
if (!i->second->filter_out(filters))
continue;
f->open_object_section("Op");
i->second->dump(now, f);
f->close_section();
@@ -189,18 +195,18 @@ void OpHistory::dump_slow_ops(utime_t now, Formatter *f)
f->close_section();
}

bool OpTracker::dump_historic_slow_ops(Formatter *f)
bool OpTracker::dump_historic_slow_ops(Formatter *f, set<string> filters)
{
RWLock::RLocker l(lock);
if (!tracking_enabled)
return false;

utime_t now = ceph_clock_now();
history.dump_slow_ops(now, f);
history.dump_slow_ops(now, f, filters);
return true;
}

bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked)
bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked, set<string> filters)
{
RWLock::RLocker l(lock);
if (!tracking_enabled)
@@ -217,6 +223,8 @@ bool OpTracker::dump_ops_in_flight(Formatter *f, bool print_only_blocked)
for (auto& op : sdata->ops_in_flight_sharded) {
if (print_only_blocked && (now - op.get_initiated() <= complaint_time))
break;
if (!op.filter_out(filters))
continue;
f->open_object_section("op");
op.dump(now, f);
f->close_section(); // this TrackedOp
@@ -46,9 +46,9 @@ class OpHistory {
assert(slow_op.empty());
}
void insert(utime_t now, TrackedOpRef op);
void dump_ops(utime_t now, Formatter *f);
void dump_ops_by_duration(utime_t now, Formatter *f);
void dump_slow_ops(utime_t now, Formatter *f);
void dump_ops(utime_t now, Formatter *f, set<string> filters = {""});
void dump_ops_by_duration(utime_t now, Formatter *f, set<string> filters = {""});
void dump_slow_ops(utime_t now, Formatter *f, set<string> filters = {""});
void on_shutdown();
void set_size_and_duration(uint32_t new_size, uint32_t new_duration) {
history_size = new_size;
@@ -90,9 +90,9 @@ class OpTracker {
RWLock::WLocker l(lock);
tracking_enabled = enable;
}
bool dump_ops_in_flight(Formatter *f, bool print_only_blocked=false);
bool dump_historic_ops(Formatter *f, bool by_duration = false);
bool dump_historic_slow_ops(Formatter *f);
bool dump_ops_in_flight(Formatter *f, bool print_only_blocked = false, set<string> filters = {""});
bool dump_historic_ops(Formatter *f, bool by_duration = false, set<string> filters = {""});
bool dump_historic_slow_ops(Formatter *f, set<string> filters = {""});
bool register_inflight_op(TrackedOp *i);
void unregister_inflight_op(TrackedOp *i);

@@ -215,6 +215,8 @@ class TrackedOp : public boost::intrusive::list_base_hook<> {
/// called when the last non-OpTracker reference is dropped
virtual void _unregistered() {};

virtual bool filter_out(const set<string>& filters) { return true; }

public:
ZTracer::Trace osd_trace;
ZTracer::Trace pg_trace;
@@ -2044,30 +2044,48 @@ bool OSD::asok_command(string admin_command, cmdmap_t& cmdmap, string format,
} else if (admin_command == "flush_journal") {
store->flush_journal();
} else if (admin_command == "dump_ops_in_flight" ||
admin_command == "ops") {
if (!op_tracker.dump_ops_in_flight(f)) {
ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
}
} else if (admin_command == "dump_blocked_ops") {
if (!op_tracker.dump_ops_in_flight(f, true)) {
ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
}
} else if (admin_command == "dump_historic_ops") {
if (!op_tracker.dump_historic_ops(f, false)) {
ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
}
} else if (admin_command == "dump_historic_ops_by_duration") {
if (!op_tracker.dump_historic_ops(f, true)) {
ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
}
} else if (admin_command == "dump_historic_slow_ops") {
if (!op_tracker.dump_historic_slow_ops(f)) {
ss << "op_tracker tracking is not enabled now, so no ops are tracked currently, even those get stuck. \
Please enable \"osd_enable_op_tracker\", and the tracker will start to track new ops received afterwards.";
admin_command == "ops" ||
admin_command == "dump_blocked_ops" ||
admin_command == "dump_historic_ops" ||
admin_command == "dump_historic_ops_by_duration" ||
admin_command == "dump_historic_slow_ops") {

const string error_str = "op_tracker tracking is not enabled now, so no ops are tracked currently, \
even those get stuck. Please enable \"osd_enable_op_tracker\", and the tracker \
will start to track new ops received afterwards.";

set<string> filters;
vector<string> filter_str;
if (cmd_getval(cct, cmdmap, "filterstr", filter_str)) {
copy(filter_str.begin(), filter_str.end(),
inserter(filters, filters.end()));
}

if (admin_command == "dump_ops_in_flight" ||
admin_command == "ops") {
if (!op_tracker.dump_ops_in_flight(f, false, filters)) {
ss << error_str;
}
}
if (admin_command == "dump_blocked_ops") {
if (!op_tracker.dump_ops_in_flight(f, true, filters)) {
ss << error_str;
}
}
if (admin_command == "dump_historic_ops") {
if (!op_tracker.dump_historic_ops(f, false, filters)) {
ss << error_str;
}
}
if (admin_command == "dump_historic_ops_by_duration") {
if (!op_tracker.dump_historic_ops(f, true, filters)) {
ss << error_str;
}
}
if (admin_command == "dump_historic_slow_ops") {
if (!op_tracker.dump_historic_slow_ops(f, filters)) {
ss << error_str;
}
}
} else if (admin_command == "dump_op_pq_state") {
f->open_object_section("pq");
@@ -2684,26 +2702,38 @@ void OSD::final_init()
"flush the journal to permanent store");
assert(r == 0);
r = admin_socket->register_command("dump_ops_in_flight",
"dump_ops_in_flight", asok_hook,
"dump_ops_in_flight " \
"name=filterstr,type=CephString,n=N,req=false",
asok_hook,
"show the ops currently in flight");
assert(r == 0);
r = admin_socket->register_command("ops",
"ops", asok_hook,
"ops " \
"name=filterstr,type=CephString,n=N,req=false",
asok_hook,
"show the ops currently in flight");
assert(r == 0);
r = admin_socket->register_command("dump_blocked_ops",
"dump_blocked_ops", asok_hook,
"dump_blocked_ops " \
"name=filterstr,type=CephString,n=N,req=false",
asok_hook,
"show the blocked ops currently in flight");
assert(r == 0);
r = admin_socket->register_command("dump_historic_ops", "dump_historic_ops",
r = admin_socket->register_command("dump_historic_ops",
"dump_historic_ops " \
"name=filterstr,type=CephString,n=N,req=false",
asok_hook,
"show recent ops");
assert(r == 0);
r = admin_socket->register_command("dump_historic_slow_ops", "dump_historic_slow_ops",
r = admin_socket->register_command("dump_historic_slow_ops",
"dump_historic_slow_ops " \
"name=filterstr,type=CephString,n=N,req=false",
asok_hook,
"show slowest recent ops");
assert(r == 0);
r = admin_socket->register_command("dump_historic_ops_by_duration", "dump_historic_ops_by_duration",
r = admin_socket->register_command("dump_historic_ops_by_duration",
"dump_historic_ops_by_duration " \
"name=filterstr,type=CephString,n=N,req=false",
asok_hook,
"show slowest recent ops, sorted by duration");
assert(r == 0);
@@ -162,6 +162,34 @@ void OpRequest::mark_flag_point_string(uint8_t flag, const string& s) {
flag, s.c_str(), old_flags, hit_flag_points);
}

bool OpRequest::filter_out(const set<string>& filters)
{
set<entity_addr_t> addrs;
for (auto it = filters.begin(); it != filters.end(); it++) {
entity_addr_t addr;
if (addr.parse((*it).c_str())) {
addrs.insert(addr);
}
}
if (addrs.empty())
return true;

entity_addr_t cmp_addr = req_src_inst.addr;
if (addrs.count(cmp_addr)) {
return true;
}
cmp_addr.set_nonce(0);
if (addrs.count(cmp_addr)) {
return true;
}
cmp_addr.set_port(0);
if (addrs.count(cmp_addr)) {
return true;
}

return false;
}

ostream& operator<<(ostream& out, const OpRequest::ClassInfo& i)
{
out << "class " << i.name << " rd " << i.read
@@ -103,6 +103,7 @@ struct OpRequest : public TrackedOp {
protected:
void _dump_op_descriptor_unlocked(ostream& stream) const override;
void _unregistered() override;
bool filter_out(const set<string>& filters) override;

public:
~OpRequest() override {

0 comments on commit 814de29

Please sign in to comment.
You can’t perform that action at this time.