Coverage Report

Created: 2026-03-15 17:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/http/action/tablets_info_action.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "service/http/action/tablets_info_action.h"
19
20
#include <algorithm>
21
#include <cstdint>
22
#include <cstdlib>
23
#include <limits>
24
#include <string>
25
#include <vector>
26
27
#include "cloud/cloud_storage_engine.h"
28
#include "cloud/cloud_tablet_mgr.h"
29
#include "cloud/config.h"
30
#include "runtime/exec_env.h"
31
#include "service/backend_options.h"
32
#include "service/http/http_channel.h"
33
#include "service/http/http_headers.h"
34
#include "service/http/http_request.h"
35
#include "service/http/http_status.h"
36
#include "storage/olap_common.h"
37
#include "storage/storage_engine.h"
38
#include "storage/tablet/tablet_manager.h"
39
40
namespace doris {
41
42
const static std::string HEADER_JSON = "application/json";
43
44
TabletsInfoAction::TabletsInfoAction(ExecEnv* exec_env, TPrivilegeHier::type hier,
45
                                     TPrivilegeType::type type)
46
1
        : HttpHandlerWithAuth(exec_env, hier, type) {}
47
48
0
void TabletsInfoAction::handle(HttpRequest* req) {
49
0
    const std::string& tablet_num_to_return = req->param("limit");
50
0
    req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.c_str());
51
0
    HttpChannel::send_reply(req, HttpStatus::OK, get_tablets_info(tablet_num_to_return).ToString());
52
0
}
53
54
0
EasyJson TabletsInfoAction::get_tablets_info(std::string tablet_num_to_return) {
55
0
    EasyJson tablets_info_ej;
56
57
0
    int64_t number;
58
0
    std::string msg;
59
0
    if (tablet_num_to_return.empty()) {
60
0
        number = 1000; // default
61
0
        msg = "OK";
62
0
    } else if (tablet_num_to_return == "all") {
63
0
        number = std::numeric_limits<std::int64_t>::max();
64
0
        msg = "OK";
65
0
    } else if (std::all_of(tablet_num_to_return.begin(), tablet_num_to_return.end(), ::isdigit)) {
66
0
        number = std::atol(tablet_num_to_return.c_str());
67
0
        msg = "OK";
68
0
    } else {
69
0
        number = 0;
70
0
        msg = "Parameter Error";
71
0
    }
72
0
    std::vector<TabletInfo> tablets_info;
73
0
    if (!config::is_cloud_mode()) {
74
0
        TabletManager* tablet_manager =
75
0
                ExecEnv::GetInstance()->storage_engine().to_local().tablet_manager();
76
0
        tablet_manager->obtain_specific_quantity_tablets(tablets_info, number);
77
0
    } else {
78
0
        CloudTabletMgr& cloud_tablet_manager =
79
0
                ExecEnv::GetInstance()->storage_engine().to_cloud().tablet_mgr();
80
0
        cloud_tablet_manager.get_tablet_info(number, &tablets_info);
81
0
    }
82
83
0
    tablets_info_ej["msg"] = msg;
84
0
    tablets_info_ej["code"] = 0;
85
0
    EasyJson data = tablets_info_ej.Set("data", EasyJson::kObject);
86
0
    data["host"] = BackendOptions::get_localhost();
87
0
    EasyJson tablets = data.Set("tablets", EasyJson::kArray);
88
0
    for (TabletInfo tablet_info : tablets_info) {
89
0
        EasyJson tablet = tablets.PushBack(EasyJson::kObject);
90
0
        tablet["tablet_id"] = tablet_info.tablet_id;
91
0
    }
92
0
    tablets_info_ej["count"] = tablets_info.size();
93
0
    return tablets_info_ej;
94
0
}
95
96
} // namespace doris