Repository: incubator-impala Updated Branches: refs/heads/master 276376aca -> 48725753e
IMPALA-3716: Add Memory Tab in query's Details page Add a QueryMemoryHandler and register it to memory tab's url For inflight queries, show Memtracker output, for completed queries and queries with no mem-tracker, e.g explain queries, show Error message. Testing: Ran locally and looked at queries tab for inflight and completed queries. Change-Id: I86db096ab7a022d230018becdb60bcc3056847af Reviewed-on: http://gerrit.cloudera.org:8080/3664 Reviewed-by: Henry Robinson <[email protected]> Tested-by: Internal Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/48725753 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/48725753 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/48725753 Branch: refs/heads/master Commit: 48725753e51ce99b2c179979e5e7bb5f8e6efdba Parents: 276376a Author: kathy.sun <[email protected]> Authored: Wed Jul 13 17:15:54 2016 -0700 Committer: Tim Armstrong <[email protected]> Committed: Wed Jul 20 21:30:33 2016 -0700 ---------------------------------------------------------------------- be/src/service/impala-http-handler.cc | 40 +++++++++++++++++++++++++++++- be/src/service/impala-http-handler.h | 4 +++ www/query_detail_tabs.tmpl | 1 + www/query_memory.tmpl | 26 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/48725753/be/src/service/impala-http-handler.cc ---------------------------------------------------------------------- diff --git a/be/src/service/impala-http-handler.cc b/be/src/service/impala-http-handler.cc index d2ffdd8..fba756d 100644 --- a/be/src/service/impala-http-handler.cc +++ b/be/src/service/impala-http-handler.cc @@ -19,9 +19,10 @@ #include <gutil/strings/substitute.h> #include "catalog/catalog-util.h" +#include "gen-cpp/beeswax_types.h" +#include "runtime/mem-tracker.h" #include "service/impala-server.h" #include "service/query-exec-state.h" -#include "gen-cpp/beeswax_types.h" #include "thrift/protocol/TDebugProtocol.h" #include "util/redactor.h" #include "util/summary-util.h" @@ -86,6 +87,9 @@ void ImpalaHttpHandler::RegisterHandlers(Webserver* webserver) { webserver->RegisterUrlCallback("/query_profile", "query_profile.tmpl", MakeCallback(this, &ImpalaHttpHandler::QueryProfileHandler), false); + webserver->RegisterUrlCallback("/query_memory", "query_memory.tmpl", + MakeCallback(this, &ImpalaHttpHandler::QueryMemoryHandler), false); + webserver->RegisterUrlCallback("/cancel_query", "common-pre.tmpl", MakeCallback(this, &ImpalaHttpHandler::CancelQueryHandler), false); @@ -232,6 +236,40 @@ void ImpalaHttpHandler::InflightQueryIdsHandler(const Webserver::ArgumentMap& ar document->AddMember("contents", query_ids, document->GetAllocator()); } +void ImpalaHttpHandler::QueryMemoryHandler(const Webserver::ArgumentMap& args, + Document* document) { + TUniqueId unique_id; + Status parse_status = ParseIdFromArguments(args, &unique_id, "query_id"); + if (!parse_status.ok()) { + Value error(parse_status.GetDetail().c_str(), document->GetAllocator()); + document->AddMember("error", error, document->GetAllocator()); + return; + } + shared_ptr<ImpalaServer::QueryExecState> exec_state = + server_->GetQueryExecState(unique_id, true); + string mem_usage_text; + // Search the in-flight queries, since only in-flight queries have a MemTracker + if (exec_state != NULL) { + lock_guard<mutex> l(*exec_state->lock(), adopt_lock_t()); + // Only queries with coordinator have mem_tracker + if (exec_state->coord() == NULL) { + mem_usage_text = + "The query does not have memory tracking information available."; + } else { + MemTracker* query_mem_tracker = exec_state->coord()->query_mem_tracker(); + mem_usage_text = query_mem_tracker->LogUsage(); + } + } else { + mem_usage_text = + "The query is finished, current memory consumption is not available."; + } + + Value mem_usage(mem_usage_text.c_str(), document->GetAllocator()); + document->AddMember("mem_usage", mem_usage, document->GetAllocator()); + document->AddMember("query_id", args.find("query_id")->second.c_str(), + document->GetAllocator()); +} + void ImpalaHttpHandler::QueryStateToJson(const ImpalaServer::QueryStateRecord& record, Value* value, Document* document) { Value user(record.effective_user.c_str(), document->GetAllocator()); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/48725753/be/src/service/impala-http-handler.h ---------------------------------------------------------------------- diff --git a/be/src/service/impala-http-handler.h b/be/src/service/impala-http-handler.h index 443ab65..0135b0e 100644 --- a/be/src/service/impala-http-handler.h +++ b/be/src/service/impala-http-handler.h @@ -133,6 +133,10 @@ class ImpalaHttpHandler { void CatalogObjectsHandler(const Webserver::ArgumentMap& args, rapidjson::Document* output); + // Returns memory usage for queries in flight. + void QueryMemoryHandler(const Webserver::ArgumentMap& args, + rapidjson::Document* output); + /// Helper method to render a single QueryStateRecord as a Json object Used by /// QueryStateHandler(). void QueryStateToJson(const ImpalaServer::QueryStateRecord& record, http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/48725753/www/query_detail_tabs.tmpl ---------------------------------------------------------------------- diff --git a/www/query_detail_tabs.tmpl b/www/query_detail_tabs.tmpl index 40190b9..4da4d60 100644 --- a/www/query_detail_tabs.tmpl +++ b/www/query_detail_tabs.tmpl @@ -7,4 +7,5 @@ <li id="plan-text-tab" role="presentation"><a href="/query_plan_text?query_id={{query_id}}">Text plan</a></li> <li id="summary-tab" role="presentation"><a href="/query_summary?query_id={{query_id}}">Summary</a></li> <li id="profile-tab" role="presentation"><a href="/query_profile?query_id={{query_id}}">Profile</a></li> + <li id="memory-tab" role="presentation"><a href="/query_memory?query_id={{query_id}}">Memory</a></li> </ul> http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/48725753/www/query_memory.tmpl ---------------------------------------------------------------------- diff --git a/www/query_memory.tmpl b/www/query_memory.tmpl new file mode 100644 index 0000000..55c064c --- /dev/null +++ b/www/query_memory.tmpl @@ -0,0 +1,26 @@ +<!-- +Copyright 2016- Cloudera Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + +{{> www/common-header.tmpl }} + +{{> www/query_detail_tabs.tmpl }} + +<pre>{{mem_usage}}</pre> + +<script> +document.getElementById("memory-tab").className = "active"; +</script> +{{> www/common-footer.tmpl }}
