Coverage Report

Created: 2026-03-14 13:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/http/action/meta_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/meta_action.h"
19
20
#include <json2pb/pb_to_json.h>
21
#include <stdint.h>
22
23
#include <cstring>
24
#include <exception>
25
#include <memory>
26
#include <shared_mutex>
27
#include <sstream>
28
#include <string>
29
30
#include "cloud/config.h"
31
#include "common/logging.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_define.h"
37
#include "storage/storage_engine.h"
38
#include "storage/tablet/tablet.h"
39
#include "storage/tablet/tablet_manager.h"
40
#include "storage/tablet/tablet_meta.h"
41
#include "util/easy_json.h"
42
43
namespace doris {
44
45
const static std::string HEADER_JSON = "application/json";
46
const static std::string OP = "op";
47
const static std::string DATA_SIZE = "data_size";
48
const static std::string HEADER = "header";
49
50
MetaAction::MetaAction(ExecEnv* exec_env, TPrivilegeHier::type hier, TPrivilegeType::type type)
51
8
        : HttpHandlerWithAuth(exec_env, hier, type) {}
52
53
1
Status MetaAction::_handle_header(HttpRequest* req, std::string* json_meta) {
54
1
    req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.c_str());
55
1
    std::string req_tablet_id = req->param(TABLET_ID_KEY);
56
1
    std::string req_enable_base64 = req->param(ENABLE_BYTE_TO_BASE64);
57
1
    uint64_t tablet_id = 0;
58
1
    bool enable_byte_to_base64 = false;
59
1
    if (std::strcmp(req_enable_base64.c_str(), "true") == 0) {
60
0
        enable_byte_to_base64 = true;
61
0
    }
62
1
    try {
63
1
        tablet_id = std::stoull(req_tablet_id);
64
1
    } catch (const std::exception& e) {
65
0
        LOG(WARNING) << "invalid argument.tablet_id:" << req_tablet_id
66
0
                     << ", enable_byte_to_base64: " << req_enable_base64;
67
0
        return Status::InternalError("convert failed, {}", e.what());
68
0
    }
69
70
1
    auto tablet = DORIS_TRY(ExecEnv::get_tablet(tablet_id));
71
1
    std::string operation = req->param(OP);
72
1
    if (operation == HEADER) {
73
1
        TabletMeta tablet_meta;
74
1
        tablet->generate_tablet_meta_copy(tablet_meta, true);
75
1
        json2pb::Pb2JsonOptions json_options;
76
1
        json_options.pretty_json = true;
77
1
        json_options.bytes_to_base64 = enable_byte_to_base64;
78
1
        tablet_meta.to_json(json_meta, json_options);
79
1
        return Status::OK();
80
1
    } else if (operation == DATA_SIZE) {
81
0
        if (!config::is_cloud_mode()) {
82
0
            EasyJson data_size;
83
0
            {
84
0
                auto* local_tablet = static_cast<Tablet*>(tablet.get());
85
0
                std::shared_lock rowset_ldlock(tablet->get_header_lock());
86
0
                data_size["local_data_size"] = local_tablet->tablet_local_size();
87
0
                data_size["remote_data_size"] = local_tablet->tablet_remote_size();
88
0
            }
89
0
            *json_meta = data_size.ToString();
90
0
        }
91
0
        return Status::OK();
92
0
    }
93
0
    return Status::InternalError("invalid operation");
94
1
}
95
96
1
void MetaAction::handle(HttpRequest* req) {
97
1
    std::string json_meta;
98
1
    Status status = _handle_header(req, &json_meta);
99
1
    std::string status_result = status.to_json();
100
1
    LOG(INFO) << "handle request result:" << status_result;
101
1
    if (status.ok()) {
102
1
        HttpChannel::send_reply(req, HttpStatus::OK, json_meta);
103
1
    } else {
104
0
        HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, status_result);
105
0
    }
106
1
}
107
108
} // end namespace doris