Coverage Report

Created: 2026-03-13 19:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/http/action/pad_rowset_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/pad_rowset_action.h"
19
20
#include <gen_cpp/olap_file.pb.h>
21
#include <glog/logging.h>
22
23
#include <cstdlib>
24
#include <memory>
25
#include <mutex>
26
#include <ostream>
27
#include <string>
28
#include <vector>
29
30
#include "service/http/http_channel.h"
31
#include "service/http/http_request.h"
32
#include "service/http/http_status.h"
33
#include "storage/olap_common.h"
34
#include "storage/rowset/rowset.h"
35
#include "storage/rowset/rowset_writer.h"
36
#include "storage/rowset/rowset_writer_context.h"
37
#include "storage/storage_engine.h"
38
#include "storage/tablet/tablet_manager.h"
39
#include "util/time.h"
40
#include "util/trace.h"
41
42
namespace doris {
43
namespace {
44
45
const std::string TABLET_ID = "tablet_id";
46
const std::string START_VERSION = "start_version";
47
const std::string END_VERSION = "end_version";
48
49
0
Status check_one_param(const std::string& param_val, const std::string& param_name) {
50
0
    if (param_val.empty()) {
51
0
        return Status::InternalError("paramater {} not specified in url", param_name);
52
0
    }
53
0
    return Status::OK();
54
0
}
55
56
0
Status check_param(HttpRequest* req) {
57
0
    RETURN_IF_ERROR(check_one_param(req->param(TABLET_ID), TABLET_ID));
58
0
    RETURN_IF_ERROR(check_one_param(req->param(START_VERSION), START_VERSION));
59
0
    RETURN_IF_ERROR(check_one_param(req->param(END_VERSION), END_VERSION));
60
0
    return Status::OK();
61
0
}
62
63
} // namespace
64
65
0
void PadRowsetAction::handle(HttpRequest* req) {
66
0
    LOG(INFO) << "accept one request " << req->debug_string();
67
0
    Status status = _handle(req);
68
0
    std::string result = status.to_json();
69
0
    LOG(INFO) << "handle request result:" << result;
70
0
    if (status.ok()) {
71
0
        HttpChannel::send_reply(req, HttpStatus::OK, result);
72
0
    } else {
73
0
        HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, result);
74
0
    }
75
0
}
76
77
0
Status PadRowsetAction::_handle(HttpRequest* req) {
78
0
    RETURN_IF_ERROR(check_param(req));
79
80
0
    const std::string& tablet_id_str = req->param(TABLET_ID);
81
0
    const std::string& start_version_str = req->param(START_VERSION);
82
0
    const std::string& end_version_str = req->param(END_VERSION);
83
84
    // valid str format
85
0
    int64_t tablet_id = std::atol(tablet_id_str.c_str());
86
0
    int32_t start_version = std::atoi(start_version_str.c_str());
87
0
    int32_t end_version = std::atoi(end_version_str.c_str());
88
0
    if (start_version < 0 || end_version < 0 || end_version < start_version) {
89
0
        return Status::InternalError("Invalid input version");
90
0
    }
91
92
0
    auto tablet = _engine.tablet_manager()->get_tablet(tablet_id);
93
0
    if (nullptr == tablet) {
94
0
        return Status::InternalError("Unknown tablet id {}", tablet_id);
95
0
    }
96
0
    return _pad_rowset(tablet.get(), Version(start_version, end_version));
97
0
}
98
99
1
Status PadRowsetAction::_pad_rowset(Tablet* tablet, const Version& version) {
100
1
    if (tablet->check_version_exist(version)) {
101
0
        return Status::InternalError("Input version {} exists", version.to_string());
102
0
    }
103
104
1
    RowsetWriterContext ctx;
105
1
    ctx.version = version;
106
1
    ctx.rowset_state = VISIBLE;
107
1
    ctx.segments_overlap = NONOVERLAPPING;
108
1
    ctx.tablet_schema = tablet->tablet_schema();
109
1
    ctx.newest_write_timestamp = UnixSeconds();
110
1
    auto writer = DORIS_TRY(tablet->create_rowset_writer(ctx, false));
111
1
    RowsetSharedPtr rowset;
112
1
    RETURN_IF_ERROR(writer->build(rowset));
113
1
    rowset->make_visible(version);
114
115
1
    std::vector<RowsetSharedPtr> to_add {rowset};
116
1
    std::vector<RowsetSharedPtr> to_delete;
117
1
    {
118
1
        std::unique_lock wlock(tablet->get_header_lock());
119
1
        SCOPED_SIMPLE_TRACE_IF_TIMEOUT(TRACE_TABLET_LOCK_THRESHOLD);
120
1
        RETURN_IF_ERROR(tablet->modify_rowsets(to_add, to_delete));
121
1
        tablet->save_meta();
122
1
    }
123
124
0
    return Status::OK();
125
1
}
126
127
} // namespace doris