Coverage Report

Created: 2026-05-14 14: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.33k
    IndexColumnWriter() = default;
51
2.33k
    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
    virtual void close_on_error() = 0;
67
68
    // check if the column is valid for inverted index, some columns
69
    // are generated from variant, but not all of them are supported
70
    static bool check_support_inverted_index(const TabletColumn& column);
71
72
    static bool check_support_ann_index(const TabletColumn& column);
73
};
74
75
class TmpFileDirs {
76
public:
77
252
    TmpFileDirs(const std::vector<doris::StorePath>& store_paths) {
78
280
        for (const auto& store_path : store_paths) {
79
280
            _tmp_file_dirs.emplace_back(store_path.path + "/" + config::tmp_file_dir);
80
280
        }
81
252
    };
82
83
252
    Status init() {
84
280
        for (auto& tmp_file_dir : _tmp_file_dirs) {
85
            // delete the tmp dir to avoid the tmp files left by last crash
86
280
            RETURN_IF_ERROR(io::global_local_filesystem()->delete_directory(tmp_file_dir));
87
280
            RETURN_IF_ERROR(io::global_local_filesystem()->create_directory(tmp_file_dir));
88
280
        }
89
252
        return Status::OK();
90
252
    };
91
92
500
    io::Path get_tmp_file_dir() {
93
500
        size_t cur_index = _next_index.fetch_add(1);
94
500
        return _tmp_file_dirs[cur_index % _tmp_file_dirs.size()];
95
500
    };
96
97
private:
98
    std::vector<io::Path> _tmp_file_dirs;
99
    std::atomic_size_t _next_index {0}; // use for round-robin
100
};
101
102
} // namespace segment_v2
103
104
} // namespace doris