[fix](httpapi) restore compaction/run_status api can show be's overall compaction status and refactor code (#35409)

This commit is contained in:
Yulei-Yang
2024-05-28 09:43:43 +08:00
committed by GitHub
parent 8ff95a00f3
commit 238e218312
4 changed files with 67 additions and 8 deletions

View File

@ -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

View File

@ -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;
};

View File

@ -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))

View File

@ -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"))
}