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 <cstddef> |
21 | | #include <functional> |
22 | | |
23 | | #include "io/fs/file_range_coalescer.h" |
24 | | #include "util/slice.h" |
25 | | |
26 | | namespace doris::io { |
27 | | |
28 | | /// One contiguous fragment of a File Cache block. `block_valid_size` is shorter than the fixed |
29 | | /// block size only at physical EOF. The data slice remains valid only during the consumer call. |
30 | | struct FileCacheBlockFragment { |
31 | | size_t block_offset {0}; |
32 | | size_t block_valid_size {0}; |
33 | | size_t fragment_offset {0}; |
34 | | Slice data; |
35 | | |
36 | 23 | bool complete() const { return fragment_offset == 0 && data.size == block_valid_size; } |
37 | | }; |
38 | | |
39 | | using FileCacheBlockFragmentConsumer = std::function<bool(const FileCacheBlockFragment& fragment)>; |
40 | | |
41 | | struct RangeWritebackDispatchResult { |
42 | | /// Fragments classified by whether they cover all valid bytes of their cache block. |
43 | | size_t complete_block_count {0}; |
44 | | size_t partial_fragment_count {0}; |
45 | | size_t complete_block_bytes {0}; |
46 | | size_t partial_fragment_bytes {0}; |
47 | | /// Fragments whose selected consumer returned true. |
48 | | size_t submitted_complete_block_count {0}; |
49 | | size_t submitted_partial_fragment_count {0}; |
50 | | }; |
51 | | |
52 | | /// Splits an already consumed query range at File Cache block boundaries. Consumers run |
53 | | /// synchronously and must copy or otherwise acquire ownership of the fragment before returning. |
54 | | class RangeWritebackDispatcher { |
55 | | public: |
56 | | /// Both consumers are required and run inline in dispatch(). |
57 | | RangeWritebackDispatcher(size_t file_size, size_t block_size, |
58 | | FileCacheBlockFragmentConsumer complete_block_consumer, |
59 | | FileCacheBlockFragmentConsumer partial_block_consumer); |
60 | | |
61 | | /// `range` must be non-empty and contained by the file, while `data` must cover it exactly. |
62 | | /// The result counts every classified fragment and each consumer's accepted submissions. |
63 | | RangeWritebackDispatchResult dispatch(const FileRange& range, Slice data) const; |
64 | | |
65 | | private: |
66 | | const size_t _file_size; |
67 | | const size_t _block_size; |
68 | | const FileCacheBlockFragmentConsumer _complete_block_consumer; |
69 | | const FileCacheBlockFragmentConsumer _partial_block_consumer; |
70 | | }; |
71 | | |
72 | | } // namespace doris::io |