Merge pull request #70852 from jkartseva/fix-list-objects-2

Do not call `LIST` API in exists* functions for the plain_rewritable disk.
This commit is contained in:
Alexey Milovidov 2024-10-19 21:06:36 +08:00 committed by GitHub
commit 47a24b778a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 16 deletions

View File

@ -56,8 +56,10 @@ bool MetadataStorageFromPlainObjectStorage::existsFile(const std::string & path)
return false; return false;
/// The path does not correspond to a directory. /// The path does not correspond to a directory.
/// This check is required for a local object storage since it supports hierarchy.
auto directory = std::filesystem::path(object_key.serialize()) / ""; auto directory = std::filesystem::path(object_key.serialize()) / "";
return !object_storage->existsOrHasAnyChild(directory); ObjectStorageKey directory_key = object_storage->generateObjectKeyForPath(directory, std::nullopt /* key_prefix */);
return !object_storage->exists(StoredObject(directory_key.serialize(), directory));
} }
bool MetadataStorageFromPlainObjectStorage::existsDirectory(const std::string & path) const bool MetadataStorageFromPlainObjectStorage::existsDirectory(const std::string & path) const

View File

@ -212,31 +212,32 @@ MetadataStorageFromPlainRewritableObjectStorage::~MetadataStorageFromPlainRewrit
bool MetadataStorageFromPlainRewritableObjectStorage::existsFileOrDirectory(const std::string & path) const bool MetadataStorageFromPlainRewritableObjectStorage::existsFileOrDirectory(const std::string & path) const
{ {
if (MetadataStorageFromPlainObjectStorage::existsFileOrDirectory(path)) if (existsDirectory(path))
return true; return true;
if (useSeparateLayoutForMetadata()) ObjectStorageKey object_key = object_storage->generateObjectKeyForPath(path, std::nullopt /* key_prefix */);
{ StoredObject object(object_key.serialize(), path);
auto key_prefix = object_storage->generateObjectKeyForPath(path, getMetadataKeyPrefix()).serialize(); return object_storage->exists(object);
return object_storage->existsOrHasAnyChild(key_prefix);
}
return false;
} }
bool MetadataStorageFromPlainRewritableObjectStorage::existsFile(const std::string & path) const bool MetadataStorageFromPlainRewritableObjectStorage::existsFile(const std::string & path) const
{ {
return MetadataStorageFromPlainObjectStorage::existsFile(path); if (existsDirectory(path))
return false;
ObjectStorageKey object_key = object_storage->generateObjectKeyForPath(path, std::nullopt /* key_prefix */);
StoredObject object(object_key.serialize(), path);
return object_storage->exists(object);
} }
bool MetadataStorageFromPlainRewritableObjectStorage::existsDirectory(const std::string & path) const bool MetadataStorageFromPlainRewritableObjectStorage::existsDirectory(const std::string & path) const
{ {
if (useSeparateLayoutForMetadata()) auto base_path = path;
{ if (base_path.ends_with('/'))
auto directory = std::filesystem::path(object_storage->generateObjectKeyForPath(path, getMetadataKeyPrefix()).serialize()) / ""; base_path.pop_back();
return object_storage->existsOrHasAnyChild(directory);
} SharedLockGuard lock(path_map->mutex);
return MetadataStorageFromPlainObjectStorage::existsDirectory(path); return path_map->map.find(base_path) != path_map->map.end();
} }
std::vector<std::string> MetadataStorageFromPlainRewritableObjectStorage::listDirectory(const std::string & path) const std::vector<std::string> MetadataStorageFromPlainRewritableObjectStorage::listDirectory(const std::string & path) const