be/src/storage/index/index_compound_reader.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/SharedHeader.h> |
22 | | #include <CLucene/store/Directory.h> |
23 | | #include <CLucene/store/IndexInput.h> |
24 | | #include <CLucene/store/IndexOutput.h> |
25 | | #include <CLucene/util/Equators.h> |
26 | | #include <CLucene/util/VoidMap.h> |
27 | | |
28 | | #include <cstdint> |
29 | | #include <map> |
30 | | #include <memory> |
31 | | #include <mutex> |
32 | | #include <string> |
33 | | #include <unordered_map> |
34 | | #include <utility> |
35 | | #include <vector> |
36 | | |
37 | | #include "io/fs/file_system.h" |
38 | | #include "io/io_common.h" |
39 | | #include "storage/index/inverted/common/inverted_index_desc.h" |
40 | | |
41 | | class CLuceneError; |
42 | | |
43 | | namespace lucene::store { |
44 | | class RAMDirectory; |
45 | | } // namespace lucene::store |
46 | | |
47 | | namespace doris::segment_v2 { |
48 | | |
49 | | class ReaderFileEntry : LUCENE_BASE { |
50 | | public: |
51 | | std::string file_name {}; |
52 | | int64_t offset; |
53 | | int64_t length; |
54 | 668k | ReaderFileEntry() { |
55 | | //file_name = nullptr; |
56 | 668k | offset = 0; |
57 | 668k | length = 0; |
58 | 668k | } |
59 | 668k | ~ReaderFileEntry() override = default; |
60 | | }; |
61 | | |
62 | | // Modern C++ using std::unordered_map with smart pointers for automatic memory management |
63 | | using EntriesType = std::unordered_map<std::string, std::unique_ptr<ReaderFileEntry>>; |
64 | | |
65 | | class CLUCENE_EXPORT DorisCompoundReader : public lucene::store::Directory { |
66 | | private: |
67 | | std::unique_ptr<lucene::store::RAMDirectory> _ram_dir; |
68 | | CL_NS(store)::IndexInput* _stream = nullptr; |
69 | | // The life cycle of _entries should be consistent with that of the DorisCompoundReader. |
70 | | std::unique_ptr<EntriesType> _entries; |
71 | | std::mutex _this_lock; |
72 | | bool _closed = false; |
73 | | int32_t _read_buffer_size = CL_NS(store)::BufferedIndexInput::BUFFER_SIZE; |
74 | | void _copyFile(const char* file, int32_t file_length, uint8_t* buffer, int32_t buffer_length); |
75 | | |
76 | | protected: |
77 | | /** Removes an existing file in the directory-> */ |
78 | | bool doDeleteFile(const char* name) override; |
79 | | |
80 | | public: |
81 | | DorisCompoundReader(CL_NS(store)::IndexInput* stream, const EntriesType& entries_clone, |
82 | | int32_t read_buffer_size = CL_NS(store)::BufferedIndexInput::BUFFER_SIZE, |
83 | | const io::IOContext* io_ctx = nullptr); |
84 | | DorisCompoundReader(CL_NS(store)::IndexInput* stream, |
85 | | int32_t read_buffer_size = CL_NS(store)::BufferedIndexInput::BUFFER_SIZE, |
86 | | const io::IOContext* io_ctx = nullptr); |
87 | | ~DorisCompoundReader() override; |
88 | | bool list(std::vector<std::string>* names) const override; |
89 | | bool fileExists(const char* name) const override; |
90 | | int64_t fileModified(const char* name) const override; |
91 | | int64_t fileLength(const char* name) const override; |
92 | | bool openInput(const char* name, lucene::store::IndexInput*& ret, CLuceneError& err, |
93 | | int32_t bufferSize = -1) override; |
94 | | bool openInput(const char* name, std::unique_ptr<lucene::store::IndexInput>& ret, |
95 | | CLuceneError& err, int32_t bufferSize = -1); |
96 | | void renameFile(const char* from, const char* to) override; |
97 | | void touchFile(const char* name) override; |
98 | | lucene::store::IndexOutput* createOutput(const char* name) override; |
99 | | void close() override; |
100 | | std::string toString() const override; |
101 | | std::string getPath() const; |
102 | | static const char* getClassName(); |
103 | | const char* getObjectName() const override; |
104 | | CL_NS(store)::IndexInput* getDorisIndexInput(); |
105 | | |
106 | | private: |
107 | | void initialize(const io::IOContext* io_ctx); |
108 | | }; |
109 | | |
110 | | } // namespace doris::segment_v2 |