Coverage Report

Created: 2026-03-12 17:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/http/action/checksum_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/checksum_action.h"
19
20
#include <boost/lexical_cast/bad_lexical_cast.hpp>
21
#include <sstream>
22
#include <string>
23
24
#include "boost/lexical_cast.hpp"
25
#include "common/logging.h"
26
#include "common/status.h"
27
#include "service/http/http_channel.h"
28
#include "service/http/http_request.h"
29
#include "service/http/http_status.h"
30
#include "storage/storage_engine.h"
31
#include "storage/task/engine_checksum_task.h"
32
33
namespace doris {
34
#include "common/compile_check_begin.h"
35
36
const std::string TABLET_ID = "tablet_id";
37
// do not use name "VERSION",
38
// or will be conflict with "VERSION" in thrift/config.h
39
const std::string TABLET_VERSION = "version";
40
const std::string SCHEMA_HASH = "schema_hash";
41
42
ChecksumAction::ChecksumAction(ExecEnv* exec_env, StorageEngine& engine, TPrivilegeHier::type hier,
43
                               TPrivilegeType::type type)
44
6
        : HttpHandlerWithAuth(exec_env, hier, type), _engine(engine) {}
45
46
0
void ChecksumAction::handle(HttpRequest* req) {
47
0
    LOG(INFO) << "accept one request " << req->debug_string();
48
    // Get tablet id
49
0
    const std::string& tablet_id_str = req->param(TABLET_ID);
50
0
    if (tablet_id_str.empty()) {
51
0
        std::string error_msg = std::string("parameter " + TABLET_ID + " not specified in url.");
52
53
0
        HttpChannel::send_reply(req, HttpStatus::BAD_REQUEST, error_msg);
54
0
        return;
55
0
    }
56
57
    // Get version
58
0
    const std::string& version_str = req->param(TABLET_VERSION);
59
0
    if (version_str.empty()) {
60
0
        std::string error_msg =
61
0
                std::string("parameter " + TABLET_VERSION + " not specified in url.");
62
0
        HttpChannel::send_reply(req, HttpStatus::BAD_REQUEST, error_msg);
63
0
        return;
64
0
    }
65
66
    // Get schema hash
67
0
    const std::string& schema_hash_str = req->param(SCHEMA_HASH);
68
0
    if (schema_hash_str.empty()) {
69
0
        std::string error_msg = std::string("parameter " + SCHEMA_HASH + " not specified in url.");
70
0
        HttpChannel::send_reply(req, HttpStatus::BAD_REQUEST, error_msg);
71
0
        return;
72
0
    }
73
74
    // valid str format
75
0
    int64_t tablet_id;
76
0
    int64_t version;
77
0
    int32_t schema_hash;
78
0
    try {
79
0
        tablet_id = boost::lexical_cast<int64_t>(tablet_id_str);
80
0
        version = boost::lexical_cast<int64_t>(version_str);
81
0
        schema_hash = boost::lexical_cast<int32_t>(schema_hash_str);
82
0
    } catch (boost::bad_lexical_cast& e) {
83
0
        std::string error_msg = std::string("param format is invalid: ") + std::string(e.what());
84
0
        HttpChannel::send_reply(req, HttpStatus::BAD_REQUEST, error_msg);
85
0
        return;
86
0
    }
87
88
0
    VLOG_ROW << "get checksum tablet info: " << tablet_id << "-" << version << "-" << schema_hash;
89
90
0
    int64_t checksum = do_checksum(tablet_id, version, schema_hash, req);
91
0
    if (checksum == -1L) {
92
0
        std::string error_msg = std::string("checksum failed");
93
0
        HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, error_msg);
94
0
        return;
95
0
    } else {
96
0
        std::stringstream result;
97
0
        result << checksum;
98
0
        std::string result_str = result.str();
99
0
        HttpChannel::send_reply(req, result_str);
100
0
    }
101
102
0
    LOG(INFO) << "deal with checksum request finished! tablet id: " << tablet_id;
103
0
}
104
105
int64_t ChecksumAction::do_checksum(int64_t tablet_id, int64_t version, int32_t schema_hash,
106
0
                                    HttpRequest* req) {
107
0
    Status res = Status::OK();
108
0
    uint32_t checksum;
109
0
    EngineChecksumTask engine_task(_engine, tablet_id, schema_hash, version, &checksum);
110
0
    SCOPED_ATTACH_TASK(engine_task.mem_tracker());
111
0
    res = engine_task.execute();
112
0
    if (!res.ok()) {
113
0
        LOG(WARNING) << "checksum failed. status: " << res << ", signature: " << tablet_id;
114
0
        return -1L;
115
0
    } else {
116
0
        LOG(INFO) << "checksum success. status: " << res << ", signature: " << tablet_id
117
0
                  << ". checksum: " << checksum;
118
0
    }
119
120
0
    return static_cast<int64_t>(checksum);
121
0
}
122
123
#include "common/compile_check_end.h"
124
} // end namespace doris