be/src/load/channel/load_stream_mgr.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 "load/channel/load_stream_mgr.h" |
19 | | |
20 | | #include <brpc/stream.h> |
21 | | |
22 | | #include "load/channel/load_channel.h" |
23 | | #include "load/channel/load_stream.h" |
24 | | #include "runtime/exec_env.h" |
25 | | #include "storage/rowset/rowset_factory.h" |
26 | | #include "storage/rowset/rowset_meta.h" |
27 | | #include "storage/storage_engine.h" |
28 | | #include "storage/tablet/tablet_manager.h" |
29 | | #include "util/lru_cache.h" |
30 | | #include "util/uid_util.h" |
31 | | |
32 | | namespace doris { |
33 | | |
34 | 20 | LoadStreamMgr::LoadStreamMgr(uint32_t segment_file_writer_thread_num) { |
35 | 20 | static_cast<void>(ThreadPoolBuilder("SegmentFileWriterThreadPool") |
36 | 20 | .set_min_threads(segment_file_writer_thread_num) |
37 | 20 | .set_max_threads(segment_file_writer_thread_num) |
38 | 20 | .build(&_file_writer_thread_pool)); |
39 | 20 | } |
40 | | |
41 | 17 | LoadStreamMgr::~LoadStreamMgr() { |
42 | 17 | _load_streams_map.clear(); |
43 | 17 | _file_writer_thread_pool->shutdown(); |
44 | 17 | } |
45 | | |
46 | | Status LoadStreamMgr::open_load_stream(const POpenLoadStreamRequest* request, |
47 | 3.82k | LoadStream*& load_stream) { |
48 | 3.82k | UniqueId load_id(request->load_id()); |
49 | | |
50 | 3.82k | { |
51 | 3.82k | std::lock_guard l(_lock); |
52 | 3.82k | auto it = _load_streams_map.find(load_id); |
53 | 3.82k | if (it != _load_streams_map.end()) { |
54 | 1.84k | load_stream = it->second.get(); |
55 | 1.98k | } else { |
56 | 1.98k | auto p = std::make_unique<LoadStream>(request->load_id(), this, |
57 | 1.98k | request->enable_profile()); |
58 | 1.98k | RETURN_IF_ERROR(p->init(request)); |
59 | 1.98k | load_stream = p.get(); |
60 | 1.98k | _load_streams_map[load_id] = std::move(p); |
61 | 1.98k | } |
62 | 3.82k | load_stream->add_source(request->src_id()); |
63 | 3.82k | } |
64 | 0 | return Status::OK(); |
65 | 3.82k | } |
66 | | |
67 | 1.98k | void LoadStreamMgr::clear_load(UniqueId load_id) { |
68 | 1.98k | std::lock_guard<decltype(_lock)> l(_lock); |
69 | 1.98k | _load_streams_map.erase(load_id); |
70 | 1.98k | } |
71 | | |
72 | | } // namespace doris |