-
Notifications
You must be signed in to change notification settings - Fork 593
/
remote_path_provider.cc
172 lines (154 loc) · 5.96 KB
/
remote_path_provider.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2024 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0
#include "cloud_storage/remote_path_provider.h"
#include "cloud_storage/partition_manifest.h"
#include "cloud_storage/partition_path_utils.h"
#include "cloud_storage/remote_label.h"
#include "cloud_storage/segment_path_utils.h"
#include "cloud_storage/spillover_manifest.h"
#include "cloud_storage/topic_mount_manifest.h"
#include "cloud_storage/topic_mount_manifest_path.h"
#include "cloud_storage/topic_path_utils.h"
#include "cloud_storage/types.h"
#include "model/fundamental.h"
#include <utility>
namespace cloud_storage {
remote_path_provider::remote_path_provider(
std::optional<remote_label> label,
std::optional<model::topic_namespace> topic_namespace_override)
: label_(label)
, _topic_namespace_override(std::move(topic_namespace_override)) {}
remote_path_provider remote_path_provider::copy() const {
remote_path_provider ret(label_, _topic_namespace_override);
return ret;
}
ss::sstring remote_path_provider::topic_manifest_prefix(
const model::topic_namespace& topic) const {
const auto& tp_ns = _topic_namespace_override.value_or(topic);
if (label_.has_value()) {
return labeled_topic_manifest_prefix(*label_, tp_ns);
}
return prefixed_topic_manifest_prefix(tp_ns);
}
ss::sstring remote_path_provider::topic_manifest_path(
const model::topic_namespace& topic, model::initial_revision_id rev) const {
const auto& tp_ns = _topic_namespace_override.value_or(topic);
if (label_.has_value()) {
return labeled_topic_manifest_path(*label_, tp_ns, rev);
}
return prefixed_topic_manifest_bin_path(tp_ns);
}
std::optional<ss::sstring> remote_path_provider::topic_manifest_path_json(
const model::topic_namespace& topic) const {
if (label_.has_value()) {
return std::nullopt;
}
const auto& tp_ns = _topic_namespace_override.value_or(topic);
return prefixed_topic_manifest_json_path(tp_ns);
}
ss::sstring remote_path_provider::partition_manifest_prefix(
const model::ntp& ntp, model::initial_revision_id rev) const {
std::optional<model::ntp> ntp_override;
if (_topic_namespace_override.has_value()) {
ntp_override = model::ntp(
_topic_namespace_override->ns,
_topic_namespace_override->tp,
ntp.tp.partition);
}
const auto& maybe_overridden_ntp = ntp_override.value_or(ntp);
if (label_.has_value()) {
return labeled_partition_manifest_prefix(
*label_, maybe_overridden_ntp, rev);
}
return prefixed_partition_manifest_prefix(maybe_overridden_ntp, rev);
}
ss::sstring remote_path_provider::partition_manifest_path(
const partition_manifest& manifest) const {
return fmt::format(
"{}/{}",
partition_manifest_prefix(manifest.get_ntp(), manifest.get_revision_id()),
manifest.get_manifest_filename());
}
ss::sstring remote_path_provider::partition_manifest_path(
const model::ntp& ntp, model::initial_revision_id rev) const {
return fmt::format(
"{}/{}",
partition_manifest_prefix(ntp, rev),
partition_manifest::filename());
}
std::optional<ss::sstring> remote_path_provider::partition_manifest_path_json(
const model::ntp& ntp, model::initial_revision_id rev) const {
if (label_.has_value()) {
return std::nullopt;
}
std::optional<model::ntp> ntp_override;
if (_topic_namespace_override.has_value()) {
ntp_override = model::ntp(
_topic_namespace_override->ns,
_topic_namespace_override->tp,
ntp.tp.partition);
}
const auto& maybe_overridden_ntp = ntp_override.value_or(ntp);
return prefixed_partition_manifest_json_path(maybe_overridden_ntp, rev);
}
ss::sstring remote_path_provider::spillover_manifest_path(
const partition_manifest& stm_manifest,
const spillover_manifest_path_components& c) const {
return fmt::format(
"{}/{}",
partition_manifest_prefix(
stm_manifest.get_ntp(), stm_manifest.get_revision_id()),
spillover_manifest::filename(c));
}
ss::sstring remote_path_provider::topic_mount_manifest_path(
const topic_mount_manifest& manifest) const {
return ss::sstring(cloud_storage::topic_mount_manifest_path(
manifest.get_source_label().cluster_uuid,
manifest.get_tp_ns(),
manifest.get_revision_id()));
}
ss::sstring remote_path_provider::segment_path(
const model::ntp& ntp,
model::initial_revision_id rev,
const segment_meta& segment) const {
const auto segment_name = partition_manifest::generate_remote_segment_name(
segment);
std::optional<model::ntp> ntp_override;
if (_topic_namespace_override.has_value()) {
ntp_override = model::ntp(
_topic_namespace_override->ns,
_topic_namespace_override->tp,
ntp.tp.partition);
}
const auto& maybe_overridden_ntp = ntp_override.value_or(ntp);
if (label_.has_value()) {
return labeled_segment_path(
*label_,
maybe_overridden_ntp,
rev,
segment_name,
segment.archiver_term);
}
return prefixed_segment_path(
maybe_overridden_ntp, rev, segment_name, segment.archiver_term);
}
ss::sstring remote_path_provider::segment_path(
const partition_manifest& manifest, const segment_meta& segment) const {
return segment_path(
manifest.get_ntp(), manifest.get_revision_id(), segment);
}
ss::sstring remote_path_provider::topic_lifecycle_marker_path(
const model::topic_namespace& topic, model::initial_revision_id rev) const {
const auto& tp_ns = _topic_namespace_override.value_or(topic);
if (label_.has_value()) {
return labeled_topic_lifecycle_marker_path(*label_, tp_ns, rev);
}
return prefixed_topic_lifecycle_marker_path(tp_ns, rev);
}
} // namespace cloud_storage