This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 7d1561d04de [fix](httpapi) restore compaction/run_status api can show
be's overall compaction status and refactor code #35278 (#35281)
7d1561d04de is described below
commit 7d1561d04de69491989aad20da4dd758a8741d40
Author: Yulei-Yang <[email protected]>
AuthorDate: Sun May 26 16:19:20 2024 +0800
[fix](httpapi) restore compaction/run_status api can show be's overall
compaction status and refactor code #35278 (#35281)
---
be/src/http/action/compaction_action.cpp | 32 ++++++++++++++++------
be/src/http/action/compaction_action.h | 3 ++
.../plugins/plugin_curl_requester.groovy | 6 ++++
.../test_overall_compaction_status.groovy | 32 ++++++++++++++++++++++
4 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/be/src/http/action/compaction_action.cpp
b/be/src/http/action/compaction_action.cpp
index 2332f719a7a..facbcdf40ba 100644
--- a/be/src/http/action/compaction_action.cpp
+++ b/be/src/http/action/compaction_action.cpp
@@ -67,7 +67,7 @@ Status CompactionAction::_check_param(HttpRequest* req,
uint64_t* tablet_id, uin
try {
*table_id = std::stoull(req_table_id);
} catch (const std::exception& e) {
- return Status::InternalError("convert tablet_id or table_id
failed, {}", e.what());
+ return Status::InternalError("convert table_id failed, {}",
e.what());
}
return Status::OK();
}
@@ -76,7 +76,7 @@ Status CompactionAction::_check_param(HttpRequest* req,
uint64_t* tablet_id, uin
try {
*tablet_id = std::stoull(req_tablet_id);
} catch (const std::exception& e) {
- return Status::InternalError("convert tablet_id or table_id
failed, {}", e.what());
+ return Status::InternalError("convert tablet_id failed, {}",
e.what());
}
return Status::OK();
} else {
@@ -86,11 +86,29 @@ Status CompactionAction::_check_param(HttpRequest* req,
uint64_t* tablet_id, uin
}
}
+/// retrieve specific id from req
+Status CompactionAction::_check_param(HttpRequest* req, uint64_t* id_param,
+ const std::string param_name) {
+ std::string req_id_param = req->param(param_name);
+ if (req_id_param != "") {
+ try {
+ *id_param = std::stoull(req_id_param);
+ } catch (const std::exception& e) {
+ return Status::InternalError("convert {} failed, {}", param_name,
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;
- uint64_t table_id = 0;
- RETURN_NOT_OK_STATUS_WITH_WARN(_check_param(req, &tablet_id, &table_id),
"check param failed");
+ RETURN_NOT_OK_STATUS_WITH_WARN(_check_param(req, &tablet_id,
TABLET_ID_KEY),
+ "check param failed");
+ if (tablet_id == 0) {
+ return Status::InternalError("check param failed: missing tablet_id");
+ }
TabletSharedPtr tablet =
StorageEngine::instance()->tablet_manager()->get_tablet(tablet_id);
if (tablet == nullptr) {
@@ -176,10 +194,8 @@ Status
CompactionAction::_handle_run_compaction(HttpRequest* req, std::string* j
Status CompactionAction::_handle_run_status_compaction(HttpRequest* req,
std::string* json_result) {
uint64_t tablet_id = 0;
- uint64_t table_id = 0;
-
- // check req_tablet_id is not empty
- RETURN_NOT_OK_STATUS_WITH_WARN(_check_param(req, &tablet_id, &table_id),
"check param failed");
+ RETURN_NOT_OK_STATUS_WITH_WARN(_check_param(req, &tablet_id,
TABLET_ID_KEY),
+ "check param failed");
if (tablet_id == 0) {
// overall compaction status
diff --git a/be/src/http/action/compaction_action.h
b/be/src/http/action/compaction_action.h
index 111a54549ff..e1f820e7a8f 100644
--- a/be/src/http/action/compaction_action.h
+++ b/be/src/http/action/compaction_action.h
@@ -70,6 +70,9 @@ private:
/// check param and fetch tablet_id from req
Status _check_param(HttpRequest* req, uint64_t* tablet_id, uint64_t*
table_id);
+ /// retrieve specific id from req
+ Status _check_param(HttpRequest* req, uint64_t* id_param, const
std::string param_name);
+
private:
CompactionActionType _type;
};
diff --git a/regression-test/plugins/plugin_curl_requester.groovy
b/regression-test/plugins/plugin_curl_requester.groovy
index 51e1a893796..c92b30487ad 100644
--- a/regression-test/plugins/plugin_curl_requester.groovy
+++ b/regression-test/plugins/plugin_curl_requester.groovy
@@ -58,6 +58,12 @@ Suite.metaClass.be_get_compaction_status{ String ip, String
port, String tablet_
logger.info("Added 'be_get_compaction_status' function to Suite")
+Suite.metaClass.be_get_overall_compaction_status{ String ip, String port /*
param */->
+ return curl("GET", String.format("http://%s:%s/api/compaction/run_status",
ip, port))
+}
+
+logger.info("Added 'be_get_overall_compaction_status' function to Suite")
+
Suite.metaClass.be_run_cumulative_compaction = { String ip, String port,
String tablet_id /* param */->
return curl("POST",
String.format("http://%s:%s/api/compaction/run?tablet_id=%s&compact_type=cumulative",
ip, port, tablet_id))
}
diff --git
a/regression-test/suites/compaction/test_overall_compaction_status.groovy
b/regression-test/suites/compaction/test_overall_compaction_status.groovy
new file mode 100644
index 00000000000..7623d4118db
--- /dev/null
+++ b/regression-test/suites/compaction/test_overall_compaction_status.groovy
@@ -0,0 +1,32 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+
+suite("test_overall_compaction_status") {
+ String backend_id;
+ def backendId_to_backendIP = [:]
+ def backendId_to_backendHttpPort = [:]
+ getBackendIpHttpPort(backendId_to_backendIP, backendId_to_backendHttpPort);
+ backend_id = backendId_to_backendIP.keySet()[0]
+
+ // test be's overall compaction status api
+ (code, out, err) =
be_get_overall_compaction_status(backendId_to_backendIP.get(backend_id),
backendId_to_backendHttpPort.get(backend_id))
+ logger.info("Get overall compaction status: code=" + code + ", out=" + out
+ ", err=" + err)
+ assertEquals(code, 0)
+ assertTrue(out.toLowerCase().contains("basecompaction"))
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]