You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by zh...@apache.org on 2020/06/03 11:54:55 UTC
[incubator-doris] branch master updated: [HttpServer] capture
convert exception (#3736)
This is an automated email from the ASF dual-hosted git repository.
zhaoc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new ed886a4 [HttpServer] capture convert exception (#3736)
ed886a4 is described below
commit ed886a485d7c2206e8ff65331f989b4b2b6a6bcb
Author: HuangWei <hu...@xiaomi.com>
AuthorDate: Wed Jun 3 19:54:41 2020 +0800
[HttpServer] capture convert exception (#3736)
If parameter str is an empty string, it will throw exception too. Maybe we can add an ut for parsing parameters in http server.
---
be/src/http/action/compaction_action.cpp | 32 ++++++++++++++++++-----------
be/src/http/action/meta_action.cpp | 35 +++++++++++++++++++-------------
2 files changed, 41 insertions(+), 26 deletions(-)
diff --git a/be/src/http/action/compaction_action.cpp b/be/src/http/action/compaction_action.cpp
index 489ba6d..efec3da 100644
--- a/be/src/http/action/compaction_action.cpp
+++ b/be/src/http/action/compaction_action.cpp
@@ -21,16 +21,16 @@
#include <string>
#include "http/http_channel.h"
+#include "http/http_headers.h"
#include "http/http_request.h"
#include "http/http_response.h"
-#include "http/http_headers.h"
#include "http/http_status.h"
-#include "olap/storage_engine.h"
-#include "olap/olap_define.h"
-#include "olap/tablet.h"
#include "common/logging.h"
#include "gutil/strings/substitute.h"
+#include "olap/olap_define.h"
+#include "olap/storage_engine.h"
+#include "olap/tablet.h"
#include "util/json_util.h"
namespace doris {
@@ -38,20 +38,27 @@ namespace doris {
const static std::string HEADER_JSON = "application/json";
// for viewing the compaction status
-Status CompactionAction::_handle_show_compaction(HttpRequest *req, std::string* json_result) {
+Status CompactionAction::_handle_show_compaction(HttpRequest* req, std::string* json_result) {
std::string req_tablet_id = req->param(TABLET_ID_KEY);
std::string req_schema_hash = req->param(TABLET_SCHEMA_HASH_KEY);
if (req_tablet_id == "" && req_schema_hash == "") {
// TODO(cmy): View the overall compaction status
return Status::NotSupported("The overall compaction status is not supported yet");
- } else if (req_tablet_id == "" || req_schema_hash == "") {
- return Status::InvalidArgument("Missing tablet id or schema hash");
}
- uint64_t tablet_id = std::stoull(req_tablet_id);
- uint32_t schema_hash = std::stoul(req_schema_hash);
+ uint64_t tablet_id = 0;
+ uint32_t schema_hash = 0;
+ try {
+ tablet_id = std::stoull(req_tablet_id);
+ schema_hash = std::stoul(req_schema_hash);
+ } catch (const std::exception& e) {
+ LOG(WARNING) << "invalid argument.tablet_id:" << req_tablet_id
+ << ", schema_hash:" << req_schema_hash;
+ return Status::InternalError(strings::Substitute("convert failed, $0", e.what()));
+ }
- TabletSharedPtr tablet = StorageEngine::instance()->tablet_manager()->get_tablet(tablet_id, schema_hash);
+ TabletSharedPtr tablet =
+ StorageEngine::instance()->tablet_manager()->get_tablet(tablet_id, schema_hash);
if (tablet == nullptr) {
return Status::NotFound("Tablet not found");
}
@@ -60,7 +67,7 @@ Status CompactionAction::_handle_show_compaction(HttpRequest *req, std::string*
return Status::OK();
}
-void CompactionAction::handle(HttpRequest *req) {
+void CompactionAction::handle(HttpRequest* req) {
req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.c_str());
if (_type == CompactionActionType::SHOW_INFO) {
@@ -72,7 +79,8 @@ void CompactionAction::handle(HttpRequest *req) {
HttpChannel::send_reply(req, HttpStatus::OK, json_result);
}
} else {
- HttpChannel::send_reply(req, HttpStatus::OK, to_json(Status::NotSupported("Action not supported")));
+ HttpChannel::send_reply(req, HttpStatus::OK,
+ to_json(Status::NotSupported("Action not supported")));
}
}
diff --git a/be/src/http/action/meta_action.cpp b/be/src/http/action/meta_action.cpp
index e077864..2fad2a9 100644
--- a/be/src/http/action/meta_action.cpp
+++ b/be/src/http/action/meta_action.cpp
@@ -21,40 +21,47 @@
#include <string>
#include "http/http_channel.h"
+#include "http/http_headers.h"
#include "http/http_request.h"
#include "http/http_response.h"
-#include "http/http_headers.h"
#include "http/http_status.h"
-#include "olap/tablet_meta_manager.h"
-#include "olap/storage_engine.h"
+#include "common/logging.h"
+#include "gutil/strings/substitute.h"
#include "olap/olap_define.h"
-#include "olap/tablet_meta.h"
+#include "olap/storage_engine.h"
#include "olap/tablet.h"
-#include "common/logging.h"
+#include "olap/tablet_meta.h"
+#include "olap/tablet_meta_manager.h"
#include "util/json_util.h"
namespace doris {
const static std::string HEADER_JSON = "application/json";
-Status MetaAction::_handle_header(HttpRequest *req, std::string* json_meta) {
+Status MetaAction::_handle_header(HttpRequest* req, std::string* json_meta) {
req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.c_str());
std::string req_tablet_id = req->param(TABLET_ID_KEY);
std::string req_schema_hash = req->param(TABLET_SCHEMA_HASH_KEY);
- if (req_tablet_id == "" || req_schema_hash == "") {
+ uint64_t tablet_id = 0;
+ uint32_t schema_hash = 0;
+ try {
+ tablet_id = std::stoull(req_tablet_id);
+ schema_hash = std::stoul(req_schema_hash);
+ } catch (const std::exception& e) {
LOG(WARNING) << "invalid argument.tablet_id:" << req_tablet_id
- << ", schema_hash:" << req_schema_hash;
- return Status::InternalError("invalid arguments");
+ << ", schema_hash:" << req_schema_hash;
+ return Status::InternalError(strings::Substitute("convert failed, $0", e.what()));
}
- uint64_t tablet_id = std::stoull(req_tablet_id);
- uint32_t schema_hash = std::stoul(req_schema_hash);
- TabletSharedPtr tablet = StorageEngine::instance()->tablet_manager()->get_tablet(tablet_id, schema_hash);
+
+ TabletSharedPtr tablet =
+ StorageEngine::instance()->tablet_manager()->get_tablet(tablet_id, schema_hash);
if (tablet == nullptr) {
LOG(WARNING) << "no tablet for tablet_id:" << tablet_id << " schema hash:" << schema_hash;
return Status::InternalError("no tablet exist");
}
- OLAPStatus s = TabletMetaManager::get_json_meta(tablet->data_dir(), tablet_id, schema_hash, json_meta);
+ OLAPStatus s =
+ TabletMetaManager::get_json_meta(tablet->data_dir(), tablet_id, schema_hash, json_meta);
if (s == OLAP_ERR_META_KEY_NOT_FOUND) {
return Status::InternalError("no header exist");
} else if (s != OLAP_SUCCESS) {
@@ -63,7 +70,7 @@ Status MetaAction::_handle_header(HttpRequest *req, std::string* json_meta) {
return Status::OK();
}
-void MetaAction::handle(HttpRequest *req) {
+void MetaAction::handle(HttpRequest* req) {
if (_meta_type == META_TYPE::HEADER) {
std::string json_meta;
Status status = _handle_header(req, &json_meta);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org