This is an automated email from the ASF dual-hosted git repository.

lide pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 238e218312f [fix](httpapi) restore compaction/run_status api can show 
be's overall compaction status and refactor code (#35409)
238e218312f is described below

commit 238e218312fdcaeb98c96fa25ee2067aa61b1a7d
Author: Yulei-Yang <yulei.yang0...@gmail.com>
AuthorDate: Tue May 28 09:43:43 2024 +0800

    [fix](httpapi) restore compaction/run_status api can show be's overall 
compaction status and refactor code (#35409)
---
 be/src/http/action/compaction_action.cpp           | 34 +++++++++++++++++-----
 be/src/http/action/compaction_action.h             |  3 ++
 .../plugins/plugin_curl_requester.groovy           |  6 ++++
 .../test_overall_compaction_status.groovy          | 32 ++++++++++++++++++++
 4 files changed, 67 insertions(+), 8 deletions(-)

diff --git a/be/src/http/action/compaction_action.cpp 
b/be/src/http/action/compaction_action.cpp
index 87c048529f8..85f8cad68ba 100644
--- a/be/src/http/action/compaction_action.cpp
+++ b/be/src/http/action/compaction_action.cpp
@@ -68,7 +68,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();
         }
@@ -77,7 +77,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 {
@@ -87,11 +87,30 @@ 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");
+    // check & retrieve tablet_id from req if it contains
+    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) {
@@ -177,10 +196,9 @@ 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");
+    // check & retrieve tablet_id from req if it contains
+    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 6c4bc86270f..f5bc80c73e5 100644
--- a/regression-test/plugins/plugin_curl_requester.groovy
+++ b/regression-test/plugins/plugin_curl_requester.groovy
@@ -82,6 +82,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_compaction = { String ip, String port, String 
tablet_id, String compact_type ->
     return curl("POST", 
String.format("http://%s:%s/api/compaction/run?tablet_id=%s&compact_type=%s";,
             ip, port, tablet_id, compact_type))
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: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to