Skip to content

Commit c4629d5

Browse files
committed
first draft
1 parent abb3c0b commit c4629d5

29 files changed

+326
-153
lines changed

src/Disks/ObjectStorages/AzureBlobStorage/AzureObjectStorage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class AzureIteratorAsync final : public IObjectStorageIteratorAsync
6565
}
6666

6767
private:
68-
bool getBatchAndCheckNext(RelativePathsWithMetadata & batch) override
68+
bool getBatchAndCheckNext(PathsWithMetadata & batch) override
6969
{
7070
ProfileEvents::increment(ProfileEvents::AzureListObjects);
7171
if (client->IsClientForDisk())
@@ -78,7 +78,7 @@ class AzureIteratorAsync final : public IObjectStorageIteratorAsync
7878

7979
for (const auto & blob : blobs_list)
8080
{
81-
batch.emplace_back(std::make_shared<RelativePathWithMetadata>(
81+
batch.emplace_back(std::make_shared<PathWithMetadata>(
8282
blob.Name,
8383
ObjectMetadata{
8484
static_cast<uint64_t>(blob.BlobSize),
@@ -160,7 +160,7 @@ ObjectStorageIteratorPtr AzureObjectStorage::iterate(const std::string & path_pr
160160
return std::make_shared<AzureIteratorAsync>(path_prefix, client_ptr, max_keys ? max_keys : settings_ptr->list_object_keys_size);
161161
}
162162

163-
void AzureObjectStorage::listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const
163+
void AzureObjectStorage::listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const
164164
{
165165
auto client_ptr = client.get();
166166

@@ -182,7 +182,7 @@ void AzureObjectStorage::listObjects(const std::string & path, RelativePathsWith
182182

183183
for (const auto & blob : blobs_list)
184184
{
185-
children.emplace_back(std::make_shared<RelativePathWithMetadata>(
185+
children.emplace_back(std::make_shared<PathWithMetadata>(
186186
blob.Name,
187187
ObjectMetadata{
188188
static_cast<uint64_t>(blob.BlobSize),

src/Disks/ObjectStorages/AzureBlobStorage/AzureObjectStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AzureObjectStorage : public IObjectStorage
3737

3838
bool supportsListObjectsCache() override { return true; }
3939

40-
void listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const override;
40+
void listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const override;
4141

4242
/// Sanitizer build may crash with max_keys=1; this looks like a false positive.
4343
ObjectStorageIteratorPtr iterate(const std::string & path_prefix, size_t max_keys) const override;

src/Disks/ObjectStorages/Cached/CachedObjectStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void CachedObjectStorage::copyObject( // NOLINT
193193
object_storage->copyObject(object_from, object_to, read_settings, write_settings, object_to_attributes);
194194
}
195195

196-
void CachedObjectStorage::listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const
196+
void CachedObjectStorage::listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const
197197
{
198198
object_storage->listObjects(path, children, max_keys);
199199
}

src/Disks/ObjectStorages/Cached/CachedObjectStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CachedObjectStorage final : public IObjectStorage
6464
IObjectStorage & object_storage_to,
6565
std::optional<ObjectAttributes> object_to_attributes = {}) override;
6666

67-
void listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const override;
67+
void listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const override;
6868

6969
ObjectMetadata getObjectMetadata(const std::string & path) const override;
7070

src/Disks/ObjectStorages/HDFS/HDFSObjectStorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ ObjectMetadata HDFSObjectStorage::getObjectMetadata(const std::string & path) co
167167
return metadata;
168168
}
169169

170-
void HDFSObjectStorage::listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const
170+
void HDFSObjectStorage::listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const
171171
{
172172
initializeHDFSFS();
173173
LOG_TEST(log, "Trying to list files for {}", path);
@@ -203,7 +203,7 @@ void HDFSObjectStorage::listObjects(const std::string & path, RelativePathsWithM
203203
}
204204
else
205205
{
206-
children.emplace_back(std::make_shared<RelativePathWithMetadata>(
206+
children.emplace_back(std::make_shared<PathWithMetadata>(
207207
String(file_path),
208208
ObjectMetadata{
209209
static_cast<uint64_t>(ls.file_info[i].mSize),

src/Disks/ObjectStorages/HDFS/HDFSObjectStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class HDFSObjectStorage : public IObjectStorage, public HDFSErrorWrapper
9292
const WriteSettings & write_settings,
9393
std::optional<ObjectAttributes> object_to_attributes = {}) override;
9494

95-
void listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const override;
95+
void listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const override;
9696

9797
String getObjectsNamespace() const override { return ""; }
9898

src/Disks/ObjectStorages/IObjectStorage.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ const MetadataStorageMetrics & IObjectStorage::getMetadataStorageMetrics() const
2929

3030
bool IObjectStorage::existsOrHasAnyChild(const std::string & path) const
3131
{
32-
RelativePathsWithMetadata files;
32+
PathsWithMetadata files;
3333
listObjects(path, files, 1);
3434
return !files.empty();
3535
}
3636

37-
void IObjectStorage::listObjects(const std::string &, RelativePathsWithMetadata &, size_t) const
37+
void IObjectStorage::listObjects(const std::string &, PathsWithMetadata &, size_t) const
3838
{
3939
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "listObjects() is not supported");
4040
}
4141

4242

4343
ObjectStorageIteratorPtr IObjectStorage::iterate(const std::string & path_prefix, size_t max_keys) const
4444
{
45-
RelativePathsWithMetadata files;
45+
PathsWithMetadata files;
4646
listObjects(path_prefix, files, max_keys);
4747

4848
return std::make_shared<ObjectStorageIteratorFromList>(std::move(files));
@@ -101,7 +101,7 @@ WriteSettings IObjectStorage::patchSettings(const WriteSettings & write_settings
101101
return write_settings;
102102
}
103103

104-
void RelativePathWithMetadata::loadMetadata(ObjectStoragePtr object_storage, bool ignore_non_existent_file)
104+
void PathWithMetadata::loadMetadata(ObjectStoragePtr object_storage, bool ignore_non_existent_file)
105105
{
106106
if (!metadata)
107107
{
@@ -118,7 +118,7 @@ void RelativePathWithMetadata::loadMetadata(ObjectStoragePtr object_storage, boo
118118
}
119119
}
120120

121-
RelativePathWithMetadata::CommandInTaskResponse::CommandInTaskResponse(const std::string & task)
121+
PathWithMetadata::CommandInTaskResponse::CommandInTaskResponse(const std::string & task)
122122
{
123123
Poco::JSON::Parser parser;
124124
try
@@ -138,7 +138,7 @@ RelativePathWithMetadata::CommandInTaskResponse::CommandInTaskResponse(const std
138138
}
139139
}
140140

141-
std::string RelativePathWithMetadata::CommandInTaskResponse::to_string() const
141+
std::string PathWithMetadata::CommandInTaskResponse::to_string() const
142142
{
143143
Poco::JSON::Object json;
144144
if (retry_after_us.has_value())

src/Disks/ObjectStorages/IObjectStorage.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct ObjectMetadata
101101
ObjectAttributes attributes;
102102
};
103103

104-
struct RelativePathWithMetadata
104+
struct PathWithMetadata
105105
{
106106
class CommandInTaskResponse
107107
{
@@ -124,21 +124,26 @@ struct RelativePathWithMetadata
124124
String relative_path;
125125
std::optional<ObjectMetadata> metadata;
126126
CommandInTaskResponse command;
127+
String absolute_path;
127128

128-
RelativePathWithMetadata() = default;
129+
PathWithMetadata() = default;
129130

130-
explicit RelativePathWithMetadata(const String & task_string, std::optional<ObjectMetadata> metadata_ = std::nullopt)
131+
explicit PathWithMetadata(const String & task_string, std::optional<ObjectMetadata> metadata_ = std::nullopt, String absolute_path_ = "")
131132
: metadata(std::move(metadata_))
132133
, command(task_string)
133134
{
134135
if (!command.is_parsed())
136+
{
135137
relative_path = task_string;
138+
absolute_path = absolute_path_;
139+
}
136140
}
137141

138-
virtual ~RelativePathWithMetadata() = default;
142+
virtual ~PathWithMetadata() = default;
139143

140144
virtual std::string getFileName() const { return std::filesystem::path(relative_path).filename(); }
141145
virtual std::string getPath() const { return relative_path; }
146+
virtual std::string getAbsolutePath() const { return absolute_path; }
142147
virtual bool isArchive() const { return false; }
143148
virtual std::string getPathToArchive() const { throw Exception(ErrorCodes::LOGICAL_ERROR, "Not an archive"); }
144149
virtual size_t fileSizeInArchive() const { throw Exception(ErrorCodes::LOGICAL_ERROR, "Not an archive"); }
@@ -160,8 +165,8 @@ struct ObjectKeyWithMetadata
160165
{}
161166
};
162167

163-
using RelativePathWithMetadataPtr = std::shared_ptr<RelativePathWithMetadata>;
164-
using RelativePathsWithMetadata = std::vector<RelativePathWithMetadataPtr>;
168+
using PathWithMetadataPtr = std::shared_ptr<PathWithMetadata>;
169+
using PathsWithMetadata = std::vector<PathWithMetadataPtr>;
165170
using ObjectKeysWithMetadata = std::vector<ObjectKeyWithMetadata>;
166171

167172
class IObjectStorageIterator;
@@ -202,7 +207,7 @@ class IObjectStorage
202207
virtual bool existsOrHasAnyChild(const std::string & path) const;
203208

204209
/// List objects recursively by certain prefix.
205-
virtual void listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const;
210+
virtual void listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const;
206211

207212
/// List objects recursively by certain prefix. Use it instead of listObjects, if you want to list objects lazily.
208213
virtual ObjectStorageIteratorPtr iterate(const std::string & path_prefix, size_t max_keys) const;
@@ -284,6 +289,11 @@ class IObjectStorage
284289
/// buckets in S3. If object storage doesn't have any namepaces return empty string.
285290
virtual String getObjectsNamespace() const = 0;
286291

292+
virtual std::unique_ptr<IObjectStorage> cloneObjectStorage(
293+
const std::string & new_namespace,
294+
const Poco::Util::AbstractConfiguration & config,
295+
const std::string & config_prefix, ContextPtr context) = 0;
296+
287297
/// Generate blob name for passed absolute local path.
288298
/// Path can be generated either independently or based on `path`.
289299
virtual ObjectStorageKey generateObjectKeyForPath(const std::string & path, const std::optional<std::string> & key_prefix) const = 0;

src/Disks/ObjectStorages/Local/LocalObjectStorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ ObjectMetadata LocalObjectStorage::getObjectMetadata(const std::string & path) c
151151
return object_metadata;
152152
}
153153

154-
void LocalObjectStorage::listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t/* max_keys */) const
154+
void LocalObjectStorage::listObjects(const std::string & path, PathsWithMetadata & children, size_t/* max_keys */) const
155155
{
156156
if (!fs::exists(path) || !fs::is_directory(path))
157157
return;
@@ -164,7 +164,7 @@ void LocalObjectStorage::listObjects(const std::string & path, RelativePathsWith
164164
continue;
165165
}
166166

167-
children.emplace_back(std::make_shared<RelativePathWithMetadata>(entry.path(), getObjectMetadata(entry.path())));
167+
children.emplace_back(std::make_shared<PathWithMetadata>(entry.path(), getObjectMetadata(entry.path())));
168168
}
169169
}
170170

src/Disks/ObjectStorages/Local/LocalObjectStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class LocalObjectStorage : public IObjectStorage
6262

6363
ObjectMetadata getObjectMetadata(const std::string & path) const override;
6464

65-
void listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const override;
65+
void listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const override;
6666

6767
bool existsOrHasAnyChild(const std::string & path) const override;
6868

0 commit comments

Comments
 (0)