Coverage Report

Created: 2026-04-13 11:59

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 CollectionValue;
39
40
class StorageField;
41
42
class TabletIndex;
43
class TabletColumn;
44
45
namespace segment_v2 {
46
class IndexFileWriter;
47
48
class IndexColumnWriter {
49
public:
50
    static Status create(const StorageField* field, std::unique_ptr<IndexColumnWriter>* res,
51
                         IndexFileWriter* index_file_writer, const TabletIndex* inverted_index);
52
    virtual Status init() = 0;
53
54
37.6k
    IndexColumnWriter() = default;
55
37.6k
    virtual ~IndexColumnWriter() = default;
56
57
    virtual Status add_values(const std::string name, const void* values, size_t count) = 0;
58
    virtual Status add_array_values(size_t field_size, const CollectionValue* values,
59
                                    size_t count) = 0;
60
61
    virtual Status add_array_values(size_t field_size, const void* value_ptr,
62
                                    const uint8_t* null_map, const uint8_t* offsets_ptr,
63
                                    size_t count) = 0;
64
65
    virtual Status add_nulls(uint32_t count) = 0;
66
    virtual Status add_array_nulls(const uint8_t* null_map, size_t num_rows) = 0;
67
68
    virtual Status finish() = 0;
69
70
    virtual int64_t size() const = 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
236
    TmpFileDirs(const std::vector<doris::StorePath>& store_paths) {
84
268
        for (const auto& store_path : store_paths) {
85
268
            _tmp_file_dirs.emplace_back(store_path.path + "/" + config::tmp_file_dir);
86
268
        }
87
236
    };
88
89
236
    Status init() {
90
268
        for (auto& tmp_file_dir : _tmp_file_dirs) {
91
            // delete the tmp dir to avoid the tmp files left by last crash
92
268
            RETURN_IF_ERROR(io::global_local_filesystem()->delete_directory(tmp_file_dir));
93
268
            RETURN_IF_ERROR(io::global_local_filesystem()->create_directory(tmp_file_dir));
94
268
        }
95
236
        return Status::OK();
96
236
    };
97
98
6.54k
    io::Path get_tmp_file_dir() {
99
6.54k
        size_t cur_index = _next_index.fetch_add(1);
100
6.54k
        return _tmp_file_dirs[cur_index % _tmp_file_dirs.size()];
101
6.54k
    };
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