Coverage Report

Created: 2025-04-24 12:23

/root/doris/be/src/io/io_common.h
Line
Count
Source (jump to first uncovered line)
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 <gen_cpp/Types_types.h>
21
22
#include <sstream>
23
24
namespace doris {
25
26
enum class ReaderType : uint8_t {
27
    READER_QUERY = 0,
28
    READER_ALTER_TABLE = 1,
29
    READER_BASE_COMPACTION = 2,
30
    READER_CUMULATIVE_COMPACTION = 3,
31
    READER_CHECKSUM = 4,
32
    READER_COLD_DATA_COMPACTION = 5,
33
    READER_SEGMENT_COMPACTION = 6,
34
    READER_FULL_COMPACTION = 7,
35
    UNKNOWN = 8
36
};
37
38
namespace io {
39
40
struct FileCacheStatistics {
41
    int64_t num_local_io_total = 0;
42
    int64_t num_remote_io_total = 0;
43
    int64_t local_io_timer = 0;
44
    int64_t bytes_read_from_local = 0;
45
    int64_t bytes_read_from_remote = 0;
46
    int64_t remote_io_timer = 0;
47
    int64_t write_cache_io_timer = 0;
48
    int64_t bytes_write_into_cache = 0;
49
    int64_t num_skip_cache_io_total = 0;
50
51
0
    void update(const FileCacheStatistics& other) {
52
0
        num_local_io_total += other.num_local_io_total;
53
0
        num_remote_io_total += other.num_remote_io_total;
54
0
        local_io_timer += other.local_io_timer;
55
0
        bytes_read_from_local += other.bytes_read_from_local;
56
0
        bytes_read_from_remote += other.bytes_read_from_remote;
57
0
        remote_io_timer += other.remote_io_timer;
58
0
        write_cache_io_timer += other.write_cache_io_timer;
59
0
        write_cache_io_timer += other.write_cache_io_timer;
60
0
        bytes_write_into_cache += other.bytes_write_into_cache;
61
0
        num_skip_cache_io_total += other.num_skip_cache_io_total;
62
0
    }
63
64
0
    void reset() {
65
0
        num_local_io_total = 0;
66
0
        num_remote_io_total = 0;
67
0
        local_io_timer = 0;
68
0
        bytes_read_from_local = 0;
69
0
        bytes_read_from_remote = 0;
70
0
        remote_io_timer = 0;
71
0
        write_cache_io_timer = 0;
72
0
        bytes_write_into_cache = 0;
73
0
        num_skip_cache_io_total = 0;
74
0
    }
75
76
0
    std::string debug_string() const {
77
0
        std::stringstream ss;
78
0
        ss << "bytes_read_from_local: " << bytes_read_from_local
79
0
           << ", bytes_read_from_remote: " << bytes_read_from_remote;
80
0
        return ss.str();
81
0
    }
82
};
83
84
struct IOContext {
85
    ReaderType reader_type = ReaderType::UNKNOWN;
86
    // FIXME(plat1ko): Seems `is_disposable` can be inferred from the `reader_type`?
87
    bool is_disposable = false;
88
    bool is_index_data = false;
89
    bool read_file_cache = true;
90
    // TODO(lightman): use following member variables to control file cache
91
    bool is_persistent = false;
92
    // stop reader when reading, used in some interrupted operations
93
    bool should_stop = false;
94
    int64_t expiration_time = 0;
95
    const TUniqueId* query_id = nullptr;             // Ref
96
    FileCacheStatistics* file_cache_stats = nullptr; // Ref
97
98
0
    std::string debug_string() const {
99
0
        if (file_cache_stats != nullptr) {
100
0
            return file_cache_stats->debug_string();
101
0
        } else {
102
0
            return "no file cache stats";
103
0
        }
104
0
    }
105
};
106
107
} // namespace io
108
} // namespace doris