Coverage Report

Created: 2026-03-15 17:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/cache/file_cache_storage.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 <mutex>
21
22
#include "common/status.h"
23
#include "io/cache/file_cache_common.h"
24
#include "util/slice.h"
25
26
namespace doris::io {
27
28
class BlockFileCache;
29
30
using FileWriterMapKey = std::pair<UInt128Wrapper, size_t>;
31
32
enum FileCacheStorageType { DISK = 0, MEMORY = 1 };
33
34
struct FileWriterMapKeyHash {
35
18.0k
    std::size_t operator()(const FileWriterMapKey& w) const {
36
18.0k
        char* v1 = (char*)&w.first.value_;
37
18.0k
        char* v2 = (char*)&w.second;
38
18.0k
        char buf[24];
39
18.0k
        memcpy(buf, v1, 16);
40
18.0k
        memcpy(buf + 16, v2, 8);
41
18.0k
        std::string_view str(buf, 24);
42
18.0k
        return std::hash<std::string_view> {}(str);
43
18.0k
    }
44
};
45
46
// The interface is for organizing datas in disk
47
class FileCacheStorage {
48
public:
49
180
    FileCacheStorage() = default;
50
180
    virtual ~FileCacheStorage() = default;
51
    // init the manager, read the blocks meta into memory
52
    virtual Status init(BlockFileCache* _mgr) = 0;
53
    // append datas into block
54
    virtual Status append(const FileCacheKey& key, const Slice& value) = 0;
55
    // finalize the block
56
    virtual Status finalize(const FileCacheKey& key, const size_t size) = 0;
57
    // read the block
58
    virtual Status read(const FileCacheKey& key, size_t value_offset, Slice result) = 0;
59
    // remove the block
60
    virtual Status remove(const FileCacheKey& key) = 0;
61
    // change the block meta
62
    virtual Status change_key_meta_type(const FileCacheKey& key, const FileCacheType type,
63
                                        const size_t size) = 0;
64
    // use when lazy load cache
65
    virtual void load_blocks_directly_unlocked(BlockFileCache* _mgr, const FileCacheKey& key,
66
0
                                               std::lock_guard<std::mutex>& cache_lock) {}
67
    // force clear all current data in the cache
68
    virtual Status clear(std::string& msg) = 0;
69
    virtual FileCacheStorageType get_type() = 0;
70
    // get local cached file
71
    virtual std::string get_local_file(const FileCacheKey& key) = 0;
72
    virtual Status get_file_cache_infos(std::vector<FileCacheInfo>& infos,
73
1
                                        std::lock_guard<std::mutex>& cache_lock) const {
74
1
        return Status::OK();
75
1
    };
76
};
77
78
} // namespace doris::io