be/src/storage/index/index_file_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 <CLucene.h> // IWYU pragma: keep |
21 | | #include <CLucene/store/IndexInput.h> |
22 | | #include <gen_cpp/olap_common.pb.h> |
23 | | #include <gen_cpp/olap_file.pb.h> |
24 | | |
25 | | #include <string> |
26 | | #include <utility> |
27 | | |
28 | | #include "common/be_mock_util.h" |
29 | | #include "io/fs/file_system.h" |
30 | | #include "io/fs/file_writer.h" |
31 | | #include "io/fs/local_file_system.h" |
32 | | #include "storage/index/index_storage_format.h" |
33 | | #include "storage/index/inverted/inverted_index_common.h" |
34 | | #include "storage/index/inverted/inverted_index_compound_reader.h" |
35 | | #include "storage/index/inverted/inverted_index_searcher.h" |
36 | | |
37 | | namespace doris { |
38 | | class TabletIndex; |
39 | | |
40 | | namespace segment_v2 { |
41 | | class DorisFSDirectory; |
42 | | |
43 | | using InvertedIndexDirectoryMap = |
44 | | std::map<std::pair<int64_t, std::string>, std::shared_ptr<lucene::store::Directory>>; |
45 | | |
46 | | class IndexFileWriter; |
47 | | using IndexFileWriterPtr = std::unique_ptr<IndexFileWriter>; |
48 | | |
49 | | class IndexFileWriter { |
50 | | public: |
51 | | IndexFileWriter(io::FileSystemSPtr fs, std::string index_path_prefix, std::string rowset_id, |
52 | | int64_t seg_id, InvertedIndexStorageFormatPB storage_format, |
53 | | io::FileWriterPtr file_writer = nullptr, bool can_use_ram_dir = true); |
54 | 444 | virtual ~IndexFileWriter() = default; |
55 | | |
56 | | MOCK_FUNCTION Result<std::shared_ptr<DorisFSDirectory>> open(const TabletIndex* index_meta); |
57 | | Status delete_index(const TabletIndex* index_meta); |
58 | | Status initialize(InvertedIndexDirectoryMap& indices_dirs); |
59 | | Status add_into_searcher_cache(); |
60 | | // Begin the close process. This mainly triggers the asynchronous close operation of |
61 | | // _idx_v2_writer by calling close(true), which starts the close process but returns |
62 | | // immediately without waiting for completion. |
63 | | Status begin_close(); |
64 | | // Finish the close process. This waits for the close operation to complete by calling |
65 | | // _idx_v2_writer->close(false), which blocks until the close is fully done. |
66 | | Status finish_close(); |
67 | 217 | const InvertedIndexFileInfo* get_index_file_info() const { |
68 | 217 | DCHECK(_closed) << debug_string(); |
69 | 217 | return &_file_info; |
70 | 217 | } |
71 | 292 | int64_t get_index_file_total_size() const { |
72 | 292 | DCHECK(_closed) << debug_string(); |
73 | 292 | return _total_file_size; |
74 | 292 | } |
75 | 0 | const io::FileSystemSPtr& get_fs() const { return _fs; } |
76 | 7.14k | InvertedIndexStorageFormatPB get_storage_format() const { return _storage_format; } |
77 | 228 | void set_file_writer_opts(const io::FileWriterOptions& opts) { _opts = opts; } |
78 | | std::vector<std::string> get_index_file_names() const; |
79 | | std::string debug_string() const; |
80 | | |
81 | | // Get internal file writer (for merge file index collection) |
82 | 0 | io::FileWriter* get_file_writer() const { return _idx_v2_writer.get(); } |
83 | | |
84 | | private: |
85 | | Status _insert_directory_into_map(int64_t index_id, const std::string& index_suffix, |
86 | | std::shared_ptr<DorisFSDirectory> dir); |
87 | | virtual Result<std::unique_ptr<IndexSearcherBuilder>> _construct_index_searcher_builder( |
88 | | const DorisCompoundReader* dir); |
89 | | |
90 | | // Member variables... |
91 | | InvertedIndexDirectoryMap _indices_dirs; |
92 | | const io::FileSystemSPtr _fs; |
93 | | std::string _index_path_prefix; |
94 | | std::string _rowset_id; |
95 | | int64_t _seg_id; |
96 | | InvertedIndexStorageFormatPB _storage_format; |
97 | | std::string _tmp_dir; |
98 | | const std::shared_ptr<io::LocalFileSystem>& _local_fs; |
99 | | |
100 | | // write to disk or stream |
101 | | io::FileWriterPtr _idx_v2_writer = nullptr; |
102 | | io::FileWriterOptions _opts; |
103 | | |
104 | | // v1: all file size |
105 | | // v2: file size |
106 | | int64_t _total_file_size = 0; |
107 | | InvertedIndexFileInfo _file_info; |
108 | | |
109 | | // only once |
110 | | bool _closed = false; |
111 | | bool _can_use_ram_dir = true; |
112 | | |
113 | | IndexStorageFormatPtr _index_storage_format; |
114 | | |
115 | | friend class IndexStorageFormatV1; |
116 | | friend class IndexStorageFormatV2; |
117 | | friend class IndexFileWriterTest; |
118 | | }; |
119 | | |
120 | | } // namespace segment_v2 |
121 | | } // namespace doris |