Coverage Report

Created: 2025-05-03 15:02

/root/doris/be/src/pipeline/pipeline.cpp
Line
Count
Source (jump to first uncovered line)
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 "pipeline.h"
19
20
#include <memory>
21
#include <string>
22
#include <utility>
23
24
#include "pipeline/exec/operator.h"
25
#include "pipeline/pipeline_task.h"
26
27
namespace doris::pipeline {
28
29
445k
void Pipeline::_init_profile() {
30
445k
    auto s = fmt::format("Pipeline (pipeline id={})", _pipeline_id);
31
445k
    _pipeline_profile = std::make_unique<RuntimeProfile>(std::move(s));
32
445k
}
33
34
4.04k
Status Pipeline::build_operators() {
35
4.04k
    _name.reserve(_operator_builders.size() * 10);
36
4.04k
    _name.append(std::to_string(id()));
37
38
4.04k
    OperatorPtr pre;
39
4.05k
    for (auto& operator_t : _operator_builders) {
40
4.05k
        auto o = operator_t->build_operator();
41
4.05k
        if (pre) {
42
11
            RETURN_IF_ERROR(o->set_child(pre));
43
11
        }
44
4.05k
        _operators.emplace_back(o);
45
46
4.05k
        _name.push_back('-');
47
4.05k
        _name.append(std::to_string(operator_t->id()));
48
4.05k
        _name.append(o->get_name());
49
50
4.05k
        pre = std::move(o);
51
4.05k
    }
52
4.04k
    return Status::OK();
53
4.04k
}
54
55
4.05k
Status Pipeline::add_operator(OperatorBuilderPtr& op) {
56
4.05k
    if (_operator_builders.empty() && !op->is_source()) {
57
0
        return Status::InternalError("Should set source before other operator");
58
0
    }
59
4.05k
    _operator_builders.emplace_back(op);
60
4.05k
    return Status::OK();
61
4.05k
}
62
63
416k
Status Pipeline::add_operator(OperatorXPtr& op) {
64
416k
    op->set_parallel_tasks(num_tasks());
65
416k
    operatorXs.emplace_back(op);
66
416k
    if (op->is_source()) {
67
394k
        std::reverse(operatorXs.begin(), operatorXs.end());
68
394k
    }
69
416k
    return Status::OK();
70
416k
}
71
72
441k
Status Pipeline::prepare(RuntimeState* state) {
73
    // TODO
74
441k
    RETURN_IF_ERROR(operatorXs.back()->prepare(state));
75
441k
    RETURN_IF_ERROR(operatorXs.back()->open(state));
76
441k
    RETURN_IF_ERROR(_sink_x->prepare(state));
77
441k
    RETURN_IF_ERROR(_sink_x->open(state));
78
441k
    return Status::OK();
79
441k
}
80
81
4.04k
Status Pipeline::set_sink_builder(OperatorBuilderPtr& sink_) {
82
4.04k
    if (_sink_builder) {
83
0
        return Status::InternalError("set sink twice");
84
0
    }
85
4.04k
    if (!sink_->is_sink()) {
86
0
        return Status::InternalError("should set a sink operator but {}", typeid(sink_).name());
87
0
    }
88
4.04k
    _sink_builder = sink_;
89
4.04k
    return Status::OK();
90
4.04k
}
91
92
441k
Status Pipeline::set_sink(DataSinkOperatorXPtr& sink) {
93
441k
    if (_sink_x) {
94
0
        return Status::InternalError("set sink twice");
95
0
    }
96
441k
    if (!sink->is_sink()) {
97
0
        return Status::InternalError("should set a sink operator but {}", typeid(sink).name());
98
0
    }
99
441k
    _sink_x = sink;
100
441k
    return Status::OK();
101
441k
}
102
103
209k
void Pipeline::make_all_runnable() {
104
209k
    DBUG_EXECUTE_IF("Pipeline::make_all_runnable.sleep", {
105
209k
        auto pipeline_id = DebugPoints::instance()->get_debug_param_or_default<int32_t>(
106
209k
                "Pipeline::make_all_runnable.sleep", "pipeline_id", -1);
107
209k
        if (pipeline_id == id()) {
108
209k
            LOG(WARNING) << "Pipeline::make_all_runnable.sleep sleep 10s";
109
209k
            sleep(10);
110
209k
        }
111
209k
    });
112
113
209k
    if (_sink_x->count_down_destination()) {
114
594k
        for (auto* task : _tasks) {
115
594k
            if (task) {
116
593k
                task->set_wake_up_early();
117
593k
            }
118
594k
        }
119
594k
        for (auto* task : _tasks) {
120
594k
            if (task) {
121
594k
                task->clear_blocking_state();
122
594k
            }
123
594k
        }
124
209k
    }
125
209k
}
126
127
} // namespace doris::pipeline