Skip to content

Commit f99d78f

Browse files
committed
first draft
1 parent 5975d07 commit f99d78f

29 files changed

+320
-125
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),
@@ -156,7 +156,7 @@ ObjectStorageIteratorPtr AzureObjectStorage::iterate(const std::string & path_pr
156156
return std::make_shared<AzureIteratorAsync>(path_prefix, client_ptr, max_keys ? max_keys : settings_ptr->list_object_keys_size);
157157
}
158158

159-
void AzureObjectStorage::listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const
159+
void AzureObjectStorage::listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const
160160
{
161161
auto client_ptr = client.get();
162162

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

179179
for (const auto & blob : blobs_list)
180180
{
181-
children.emplace_back(std::make_shared<RelativePathWithMetadata>(
181+
children.emplace_back(std::make_shared<PathWithMetadata>(
182182
blob.Name,
183183
ObjectMetadata{
184184
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
@@ -32,7 +32,7 @@ class AzureObjectStorage : public IObjectStorage
3232
const String & object_namespace_,
3333
const String & description_);
3434

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

3737
/// Sanitizer build may crash with max_keys=1; this looks like a false positive.
3838
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
@@ -202,7 +202,7 @@ std::unique_ptr<IObjectStorage> CachedObjectStorage::cloneObjectStorage(
202202
return object_storage->cloneObjectStorage(new_namespace, config, config_prefix, context);
203203
}
204204

205-
void CachedObjectStorage::listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const
205+
void CachedObjectStorage::listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const
206206
{
207207
object_storage->listObjects(path, children, max_keys);
208208
}

src/Disks/ObjectStorages/Cached/CachedObjectStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CachedObjectStorage final : public IObjectStorage
7070
const std::string & config_prefix,
7171
ContextPtr context) override;
7272

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

7575
ObjectMetadata getObjectMetadata(const std::string & path) const override;
7676

src/Disks/ObjectStorages/DiskObjectStorageRemoteMetadataRestoreHelper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ void DiskObjectStorageRemoteMetadataRestoreHelper::restoreFiles(IObjectStorage *
358358
LOG_INFO(disk->log, "Starting restore files for disk {}", disk->name);
359359

360360
ThreadPool pool{CurrentMetrics::LocalThread, CurrentMetrics::LocalThreadActive, CurrentMetrics::LocalThreadScheduled};
361-
auto restore_files = [this, &source_object_storage, &restore_information, &pool](const RelativePathsWithMetadata & objects)
361+
auto restore_files = [this, &source_object_storage, &restore_information, &pool](const PathsWithMetadata & objects)
362362
{
363363
std::vector<String> keys_names;
364364
for (const auto & object : objects)
@@ -389,7 +389,7 @@ void DiskObjectStorageRemoteMetadataRestoreHelper::restoreFiles(IObjectStorage *
389389
return true;
390390
};
391391

392-
RelativePathsWithMetadata children;
392+
PathsWithMetadata children;
393393
source_object_storage->listObjects(restore_information.source_path, children, /* max_keys= */ 0);
394394

395395
restore_files(children);
@@ -462,7 +462,7 @@ void DiskObjectStorageRemoteMetadataRestoreHelper::restoreFileOperations(IObject
462462
|| disk->object_key_prefix != restore_information.source_path;
463463

464464
std::set<String> renames;
465-
auto restore_file_operations = [this, &source_object_storage, &restore_information, &renames, &send_metadata](const RelativePathsWithMetadata & objects)
465+
auto restore_file_operations = [this, &source_object_storage, &restore_information, &renames, &send_metadata](const PathsWithMetadata & objects)
466466
{
467467
const String rename = "rename";
468468
const String hardlink = "hardlink";
@@ -529,7 +529,7 @@ void DiskObjectStorageRemoteMetadataRestoreHelper::restoreFileOperations(IObject
529529
return true;
530530
};
531531

532-
RelativePathsWithMetadata children;
532+
PathsWithMetadata children;
533533
source_object_storage->listObjects(restore_information.source_path + "operations/", children, /* max_keys= */ 0);
534534
restore_file_operations(children);
535535

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ const MetadataStorageMetrics & IObjectStorage::getMetadataStorageMetrics() const
2525

2626
bool IObjectStorage::existsOrHasAnyChild(const std::string & path) const
2727
{
28-
RelativePathsWithMetadata files;
28+
PathsWithMetadata files;
2929
listObjects(path, files, 1);
3030
return !files.empty();
3131
}
3232

33-
void IObjectStorage::listObjects(const std::string &, RelativePathsWithMetadata &, size_t) const
33+
void IObjectStorage::listObjects(const std::string &, PathsWithMetadata &, size_t) const
3434
{
3535
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "listObjects() is not supported");
3636
}
3737

3838

3939
ObjectStorageIteratorPtr IObjectStorage::iterate(const std::string & path_prefix, size_t max_keys) const
4040
{
41-
RelativePathsWithMetadata files;
41+
PathsWithMetadata files;
4242
listObjects(path_prefix, files, max_keys);
4343

4444
return std::make_shared<ObjectStorageIteratorFromList>(std::move(files));

src/Disks/ObjectStorages/IObjectStorage.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,25 @@ struct ObjectMetadata
8181
ObjectAttributes attributes;
8282
};
8383

84-
struct RelativePathWithMetadata
84+
struct PathWithMetadata
8585
{
8686
String relative_path;
8787
std::optional<ObjectMetadata> metadata;
88+
String absolute_path;
8889

89-
RelativePathWithMetadata() = default;
90+
PathWithMetadata() = default;
9091

91-
explicit RelativePathWithMetadata(String relative_path_, std::optional<ObjectMetadata> metadata_ = std::nullopt)
92+
explicit PathWithMetadata(String relative_path_, std::optional<ObjectMetadata> metadata_ = std::nullopt, String absolute_path_ = "")
9293
: relative_path(std::move(relative_path_))
9394
, metadata(std::move(metadata_))
95+
, absolute_path(std::move(absolute_path_))
9496
{}
9597

96-
virtual ~RelativePathWithMetadata() = default;
98+
virtual ~PathWithMetadata() = default;
9799

98100
virtual std::string getFileName() const { return std::filesystem::path(relative_path).filename(); }
99101
virtual std::string getPath() const { return relative_path; }
102+
virtual std::string getAbsolutePath() const { return absolute_path; }
100103
virtual bool isArchive() const { return false; }
101104
virtual std::string getPathToArchive() const { throw Exception(ErrorCodes::LOGICAL_ERROR, "Not an archive"); }
102105
virtual size_t fileSizeInArchive() const { throw Exception(ErrorCodes::LOGICAL_ERROR, "Not an archive"); }
@@ -115,8 +118,8 @@ struct ObjectKeyWithMetadata
115118
{}
116119
};
117120

118-
using RelativePathWithMetadataPtr = std::shared_ptr<RelativePathWithMetadata>;
119-
using RelativePathsWithMetadata = std::vector<RelativePathWithMetadataPtr>;
121+
using PathWithMetadataPtr = std::shared_ptr<PathWithMetadata>;
122+
using PathsWithMetadata = std::vector<PathWithMetadataPtr>;
120123
using ObjectKeysWithMetadata = std::vector<ObjectKeyWithMetadata>;
121124

122125
class IObjectStorageIterator;
@@ -157,7 +160,7 @@ class IObjectStorage
157160
virtual bool existsOrHasAnyChild(const std::string & path) const;
158161

159162
/// List objects recursively by certain prefix.
160-
virtual void listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const;
163+
virtual void listObjects(const std::string & path, PathsWithMetadata & children, size_t max_keys) const;
161164

162165
/// List objects recursively by certain prefix. Use it instead of listObjects, if you want to list objects lazily.
163166
virtual ObjectStorageIteratorPtr iterate(const std::string & path_prefix, size_t max_keys) const;

src/Disks/ObjectStorages/Local/LocalObjectStorage.cpp

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

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

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

0 commit comments

Comments
 (0)