acelyc111 commented on a change in pull request #4312: URL: https://github.com/apache/incubator-doris/pull/4312#discussion_r468275887
########## File path: be/src/http/action/compaction_action.cpp ########## @@ -30,33 +31,52 @@ #include "gutil/strings/substitute.h" #include "olap/olap_define.h" #include "olap/storage_engine.h" -#include "olap/tablet.h" +#include "olap/base_compaction.h" +#include "olap/cumulative_compaction.h" #include "util/json_util.h" 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) { +bool CompactionAction::_is_compaction_running = false; +std::mutex CompactionAction::_compaction_running_mutex; +uint64_t CompactionAction::_current_tablet_id = -1; +uint32_t CompactionAction::_current_schema_hash = -1; +std::string CompactionAction::_current_compaction_type = ""; + +Status CompactionAction::_check_param(HttpRequest* req, uint64_t* tablet_id, uint32_t* schema_hash) { + 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"); } - 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); + *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())); } + return Status::OK(); +} + +// for viewing the compaction status +Status CompactionAction::_handle_show_compaction(HttpRequest* req, std::string* json_result) { + + uint64_t tablet_id = 0; + uint32_t schema_hash = 0; + + Status status = _check_param(req, &tablet_id, &schema_hash); + if (!status.ok()) { + return status; + } Review comment: You can use macro `RETURN_IF_ERROR` to simplify code. ########## File path: be/src/http/action/compaction_action.h ########## @@ -41,8 +52,25 @@ class CompactionAction : public HttpHandler { private: Status _handle_show_compaction(HttpRequest *req, std::string* json_result); + /// execute compaction request to run compaction task + /// param compact_type in req to distinguish the task type, base or cumulative + Status _handle_run_compaction(HttpRequest *req, std::string* json_result); + + /// thread callback function for the tablet to do compaction + OLAPStatus _execute_compaction_callback(TabletSharedPtr tablet, const std::string& compaction_type); + + /// fetch compaction running status + Status _handle_run_status_compaction(HttpRequest* req, std::string* json_result); + private: CompactionActionType _type; + + /// running check mutex + static std::mutex _compaction_running_mutex; + /// whether there is manual compaction running + static bool _is_compaction_running; Review comment: I mean, mutex is not needed, you can use atomic<bool> instead, I found `_compaction_running_mutex ` is only aim to protect `_is_compaction_running ` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org