Coverage Report

Created: 2026-06-06 13:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
38
class TabletIndex;
39
class TabletColumn;
40
41
namespace segment_v2 {
42
class IndexFileWriter;
43
44
class IndexColumnWriter {
45
public:
46
    static Status create(const TabletColumn* column, std::unique_ptr<IndexColumnWriter>* res,
47
                         IndexFileWriter* index_file_writer, const TabletIndex* inverted_index);
48
    virtual Status init() = 0;
49
50
2.41k
    IndexColumnWriter() = default;
51
2.41k
    virtual ~IndexColumnWriter() = default;
52
53
    virtual Status add_values(const std::string name, const void* values, size_t count) = 0;
54
55
    virtual Status add_array_values(size_t field_size, const void* value_ptr,
56
                                    const uint8_t* null_map, const uint8_t* offsets_ptr,
57
                                    size_t count) = 0;
58
59
    virtual Status add_nulls(uint32_t count) = 0;
60
    virtual Status add_array_nulls(const uint8_t* null_map, size_t num_rows) = 0;
61
62
    virtual Status finish() = 0;
63
64
    virtual int64_t size() const = 0;
65
66
    // For tests: returns the V4 SPIMI posting buffer's resident bytes
67
    // (12 B/record + arena + intern slots), or 0 on the V1/V2/V3
68
    // (CLucene) path. Overridden by `InvertedIndexColumnWriter` for the
69
    // fulltext (slice) field types.
70
0
    virtual size_t spimi_buffer_memory_usage() const { return 0; }
71
72
    virtual void close_on_error() = 0;
73
74
    // check if the column is valid for inverted index, some columns
75
    // are generated from variant, but not all of them are supported
76
    static bool check_support_inverted_index(const TabletColumn& column);
77
78
    static bool check_support_ann_index(const TabletColumn& column);
79
};
80
81
class TmpFileDirs {
82
public:
83
266
    TmpFileDirs(const std::vector<doris::StorePath>& store_paths) {
84
294
        for (const auto& store_path : store_paths) {
85
294
            _tmp_file_dirs.emplace_back(store_path.path + "/" + config::tmp_file_dir);
86
294
        }
87
266
    };
88
89
266
    Status init() {
90
294
        for (auto& tmp_file_dir : _tmp_file_dirs) {
91
            // delete the tmp dir to avoid the tmp files left by last crash
92
294
            RETURN_IF_ERROR(io::global_local_filesystem()->delete_directory(tmp_file_dir));
93
294
            RETURN_IF_ERROR(io::global_local_filesystem()->create_directory(tmp_file_dir));
94
294
        }
95
266
        return Status::OK();
96
266
    };
97
98
582
    io::Path get_tmp_file_dir() {
99
582
        size_t cur_index = _next_index.fetch_add(1);
100
582
        return _tmp_file_dirs[cur_index % _tmp_file_dirs.size()];
101
582
    };
102
103
private:
104
    std::vector<io::Path> _tmp_file_dirs;
105
    std::atomic_size_t _next_index {0}; // use for round-robin
106
};
107
108
} // namespace segment_v2
109
110
} // namespace doris