be/src/storage/storage_policy.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 <fmt/format.h> |
21 | | #include <stdint.h> |
22 | | |
23 | | #include <memory> |
24 | | #include <optional> |
25 | | #include <string> |
26 | | #include <utility> |
27 | | #include <vector> |
28 | | |
29 | | #include "common/status.h" |
30 | | #include "io/fs/file_system.h" |
31 | | #include "io/fs/remote_file_system.h" |
32 | | |
33 | | namespace doris { |
34 | | class RowsetMeta; |
35 | | |
36 | | namespace cloud { |
37 | | class StorageVaultPB_PathFormat; |
38 | | } |
39 | | |
40 | | struct StoragePolicy { |
41 | | std::string name; |
42 | | int64_t version; |
43 | | int64_t cooldown_datetime; |
44 | | int64_t cooldown_ttl; |
45 | | int64_t resource_id; |
46 | | |
47 | 24 | std::string to_string() const { |
48 | 24 | return fmt::format( |
49 | 24 | "(name={}, version={}, cooldown_date_time={}, cooldown_ttl={}, resource_id={})", |
50 | 24 | name, version, cooldown_datetime, cooldown_ttl, resource_id); |
51 | 24 | } |
52 | | }; |
53 | | |
54 | | using StoragePolicyPtr = std::shared_ptr<StoragePolicy>; |
55 | | |
56 | | // return nullptr if not found |
57 | | StoragePolicyPtr get_storage_policy(int64_t id); |
58 | | |
59 | | // always success |
60 | | void put_storage_policy(int64_t id, StoragePolicyPtr policy); |
61 | | |
62 | | void delete_storage_policy(int64_t id); |
63 | | |
64 | | // return [id, version] of all storage policies |
65 | | std::vector<std::pair<int64_t, int64_t>> get_storage_policy_ids(); |
66 | | |
67 | | struct StorageResource { |
68 | | io::RemoteFileSystemSPtr fs; |
69 | | int64_t path_version = 0; |
70 | | std::function<int64_t(int64_t)> shard_fn; |
71 | | |
72 | 787k | StorageResource() = default; |
73 | 54 | StorageResource(io::RemoteFileSystemSPtr fs_) : fs(std::move(fs_)) {} |
74 | | StorageResource(io::RemoteFileSystemSPtr, const cloud::StorageVaultPB_PathFormat&); |
75 | | |
76 | | std::string remote_segment_path(int64_t tablet_id, std::string_view rowset_id, |
77 | | int64_t seg_id) const; |
78 | | std::string remote_segment_path(const RowsetMeta& rowset, int64_t seg_id) const; |
79 | | std::string remote_tablet_path(int64_t tablet_id) const; |
80 | | std::string remote_delete_bitmap_path(int64_t tablet_id, std::string_view rowset_id) const; |
81 | | |
82 | | std::string remote_idx_v1_path(const RowsetMeta& rowset, int64_t seg_id, int64_t index_id, |
83 | | std::string_view index_suffix) const; |
84 | | std::string remote_idx_v2_path(const RowsetMeta& rowset, int64_t seg_id) const; |
85 | | |
86 | | std::string cooldown_tablet_meta_path(int64_t tablet_id, int64_t replica_id, |
87 | | int64_t cooldown_term) const; |
88 | | |
89 | | // Static function to parse tablet_id from remote segment path |
90 | | static std::optional<int64_t> parse_tablet_id_from_path(const std::string& path); |
91 | | }; |
92 | | |
93 | | // return nullptr if not found |
94 | | io::RemoteFileSystemSPtr get_filesystem(const std::string& resource_id); |
95 | | |
96 | | // Get `StorageResource` and its version |
97 | | std::optional<std::pair<StorageResource, int64_t>> get_storage_resource(int64_t resource_id); |
98 | | std::optional<std::pair<StorageResource, int64_t>> get_storage_resource( |
99 | | const std::string& resource_id); |
100 | | |
101 | | Result<StorageResource> get_resource_by_storage_policy_id(int64_t storage_policy_id); |
102 | | |
103 | | // always success |
104 | | void put_storage_resource(std::string resource_id, StorageResource resource, int64_t version); |
105 | | |
106 | | // always success |
107 | | void put_storage_resource(int64_t resource_id, StorageResource resource, int64_t version); |
108 | | |
109 | | void delete_storage_resource(int64_t resource_id); |
110 | | |
111 | | void clear_storage_resource(); |
112 | | |
113 | | // return [id, version] of all resources |
114 | | std::vector<std::pair<std::string, int64_t>> get_storage_resource_ids(); |
115 | | |
116 | | } // namespace doris |