be/src/storage/index/index_writer.h
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 | | #pragma once |
19 | | |
20 | | #include <butil/macros.h> |
21 | | #include <stddef.h> |
22 | | #include <stdint.h> |
23 | | |
24 | | #include <atomic> |
25 | | #include <memory> |
26 | | #include <string> |
27 | | #include <vector> |
28 | | |
29 | | #include "common/config.h" |
30 | | #include "common/status.h" |
31 | | #include "io/fs/file_system.h" |
32 | | #include "io/fs/local_file_system.h" |
33 | | #include "storage/olap_common.h" |
34 | | #include "storage/options.h" |
35 | | |
36 | | namespace doris { |
37 | | #include "common/compile_check_begin.h" |
38 | | |
39 | | class CollectionValue; |
40 | | |
41 | | class StorageField; |
42 | | |
43 | | class TabletIndex; |
44 | | class TabletColumn; |
45 | | |
46 | | namespace segment_v2 { |
47 | | class IndexFileWriter; |
48 | | |
49 | | class IndexColumnWriter { |
50 | | public: |
51 | | static Status create(const StorageField* field, std::unique_ptr<IndexColumnWriter>* res, |
52 | | IndexFileWriter* index_file_writer, const TabletIndex* inverted_index); |
53 | | virtual Status init() = 0; |
54 | | |
55 | 2.31k | IndexColumnWriter() = default; |
56 | 2.31k | virtual ~IndexColumnWriter() = default; |
57 | | |
58 | | virtual Status add_values(const std::string name, const void* values, size_t count) = 0; |
59 | | virtual Status add_array_values(size_t field_size, const CollectionValue* values, |
60 | | size_t count) = 0; |
61 | | |
62 | | virtual Status add_array_values(size_t field_size, const void* value_ptr, |
63 | | const uint8_t* null_map, const uint8_t* offsets_ptr, |
64 | | size_t count) = 0; |
65 | | |
66 | | virtual Status add_nulls(uint32_t count) = 0; |
67 | | virtual Status add_array_nulls(const uint8_t* null_map, size_t num_rows) = 0; |
68 | | |
69 | | virtual Status finish() = 0; |
70 | | |
71 | | virtual int64_t size() const = 0; |
72 | | |
73 | | virtual void close_on_error() = 0; |
74 | | |
75 | | // check if the column is valid for inverted index, some columns |
76 | | // are generated from variant, but not all of them are supported |
77 | | static bool check_support_inverted_index(const TabletColumn& column); |
78 | | |
79 | | static bool check_support_ann_index(const TabletColumn& column); |
80 | | }; |
81 | | |
82 | | class TmpFileDirs { |
83 | | public: |
84 | 231 | TmpFileDirs(const std::vector<doris::StorePath>& store_paths) { |
85 | 263 | for (const auto& store_path : store_paths) { |
86 | 263 | _tmp_file_dirs.emplace_back(store_path.path + "/" + config::tmp_file_dir); |
87 | 263 | } |
88 | 231 | }; |
89 | | |
90 | 231 | Status init() { |
91 | 263 | for (auto& tmp_file_dir : _tmp_file_dirs) { |
92 | | // delete the tmp dir to avoid the tmp files left by last crash |
93 | 263 | RETURN_IF_ERROR(io::global_local_filesystem()->delete_directory(tmp_file_dir)); |
94 | 263 | RETURN_IF_ERROR(io::global_local_filesystem()->create_directory(tmp_file_dir)); |
95 | 263 | } |
96 | 231 | return Status::OK(); |
97 | 231 | }; |
98 | | |
99 | 474 | io::Path get_tmp_file_dir() { |
100 | 474 | size_t cur_index = _next_index.fetch_add(1); |
101 | 474 | return _tmp_file_dirs[cur_index % _tmp_file_dirs.size()]; |
102 | 474 | }; |
103 | | |
104 | | private: |
105 | | std::vector<io::Path> _tmp_file_dirs; |
106 | | std::atomic_size_t _next_index {0}; // use for round-robin |
107 | | }; |
108 | | |
109 | | } // namespace segment_v2 |
110 | | |
111 | | #include "common/compile_check_end.h" |
112 | | } // namespace doris |