From 968cc6b49289624470222fa6467958afc1d74f33 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 20 Nov 2015 11:26:50 -0800 Subject: [PATCH] rgw: start moving report into coroutines Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_coroutine.cc | 41 ++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_coroutine.h | 9 +++++++++ 2 files changed, 50 insertions(+) diff --git a/src/rgw/rgw_coroutine.cc b/src/rgw/rgw_coroutine.cc index 9722567c3fe87..89f9c21a0fb04 100644 --- a/src/rgw/rgw_coroutine.cc +++ b/src/rgw/rgw_coroutine.cc @@ -1,5 +1,7 @@ +#include "common/ceph_json.h" + #include "rgw_coroutine.h" #include "rgw_boost_asio_yield.h" @@ -331,6 +333,14 @@ void RGWCoroutinesManager::report_error(RGWCoroutinesStack *op) lderr(cct) << "ERROR: failed operation: " << op->error_str() << dendl; } +void RGWCoroutinesStack::dump(Formatter *f) const { + f->open_array_section("ops"); + for (auto& i : ops) { + encode_json("op", *i, f); + } + f->close_section(); +} + void RGWCoroutinesManager::handle_unblocked_stack(list& stacks, RGWCoroutinesStack *stack, int *blocked_count) { --(*blocked_count); @@ -349,6 +359,13 @@ int RGWCoroutinesManager::run(list& stacks) int interval_wait_count = 0; RGWCoroutinesEnv env; + uint64_t run_num = run_context_count.inc(); + + set context_stacks = run_contexts[run_num]; + for (auto& st : stacks) { + context_stacks.insert(st); + } + env.manager = this; env.stacks = &stacks; @@ -397,6 +414,7 @@ int RGWCoroutinesManager::run(list& stacks) stack->parent->set_wait_for_child(false); stack->parent->schedule(); } + context_stacks.erase(stack); stack->put(); } else { stack->schedule(); @@ -473,6 +491,20 @@ RGWAioCompletionNotifier *RGWCoroutinesManager::create_completion_notifier(RGWCo return new RGWAioCompletionNotifier(&completion_mgr, (void *)stack); } +void RGWCoroutinesManager::dump(Formatter *f) const { + f->open_array_section("run_contexts"); + for (auto& i : run_contexts) { + char buf[32]; + snprintf(buf, sizeof(buf), "context.%lld", (long long)i.first); + f->open_array_section(buf); + for (auto& s : i.second) { + ::encode_json("entry", *s, f); + } + f->close_section(); + } + f->close_section(); +} + void RGWCoroutine::call(RGWCoroutine *op) { stack->call(op); @@ -548,6 +580,15 @@ void RGWCoroutine::wakeup() stack->wakeup(); } +void RGWCoroutine::dump(Formatter *f) const { + encode_json("type", typeid(this).name(), f); + f->open_array_section("spawned"); + for (auto& i : spawned.entries) { + encode_json("entry", *i, f); + } + f->close_section(); +} + int RGWSimpleCoroutine::operate() { int ret = 0; diff --git a/src/rgw/rgw_coroutine.h b/src/rgw/rgw_coroutine.h index 0d164ef5035cd..b4331c59fcec2 100644 --- a/src/rgw/rgw_coroutine.h +++ b/src/rgw/rgw_coroutine.h @@ -202,6 +202,8 @@ public: RGWCoroutinesStack *get_stack() const { return stack; } + + void dump(Formatter *f) const; }; ostream& operator<<(ostream& out, const RGWCoroutine& cr); @@ -376,6 +378,8 @@ public: bool unblock_stack(RGWCoroutinesStack **s); RGWCoroutinesEnv *get_env() { return env; } + + void dump(Formatter *f) const; }; template @@ -401,6 +405,9 @@ class RGWCoroutinesManager { CephContext *cct; atomic_t going_down; + atomic64_t run_context_count; + map > run_contexts; + void handle_unblocked_stack(list& stacks, RGWCoroutinesStack *stack, int *waiting_count); protected: RGWCompletionManager completion_mgr; @@ -429,6 +436,8 @@ public: stack->get(); return stack; } + + void dump(Formatter *f) const; }; class RGWSimpleCoroutine : public RGWCoroutine { -- 2.39.5