Skip to content

Commit

Permalink
generate key for clickhouse_remove_objects_capability
Browse files Browse the repository at this point in the history
  • Loading branch information
CheSema committed Feb 1, 2024
1 parent e029021 commit bcb61b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Disks/ObjectStorages/ObjectStorageFactory.cpp
Expand Up @@ -96,10 +96,10 @@ S3::URI getS3URI(const Poco::Util::AbstractConfiguration & config, const std::st
}

void checkS3Capabilities(
S3ObjectStorage & storage, const S3Capabilities s3_capabilities, const String & name, const String & key_with_trailing_slash)
S3ObjectStorage & storage, const S3Capabilities s3_capabilities, const String & name)
{
/// If `support_batch_delete` is turned on (default), check and possibly switch it off.
if (s3_capabilities.support_batch_delete && !checkBatchRemove(storage, key_with_trailing_slash))
if (s3_capabilities.support_batch_delete && !checkBatchRemove(storage))
{
LOG_WARNING(
getLogger("S3ObjectStorage"),
Expand Down Expand Up @@ -134,7 +134,7 @@ void registerS3ObjectStorage(ObjectStorageFactory & factory)

/// NOTE: should we still perform this check for clickhouse-disks?
if (!skip_access_check)
checkS3Capabilities(*object_storage, s3_capabilities, name, uri.key);
checkS3Capabilities(*object_storage, s3_capabilities, name);

return object_storage;
});
Expand Down Expand Up @@ -170,7 +170,7 @@ void registerS3PlainObjectStorage(ObjectStorageFactory & factory)

/// NOTE: should we still perform this check for clickhouse-disks?
if (!skip_access_check)
checkS3Capabilities(*object_storage, s3_capabilities, name, uri.key);
checkS3Capabilities(*object_storage, s3_capabilities, name);

return object_storage;
});
Expand Down
7 changes: 4 additions & 3 deletions src/Disks/ObjectStorages/S3/DiskS3Utils.cpp
Expand Up @@ -79,13 +79,14 @@ static String getServerUUID()
return toString(server_uuid);
}

bool checkBatchRemove(S3ObjectStorage & storage, const String & key_with_trailing_slash)
bool checkBatchRemove(S3ObjectStorage & storage)
{
/// NOTE: key_with_trailing_slash is the disk prefix, it is required
/// because access is done via S3ObjectStorage not via IDisk interface
/// (since we don't have disk yet).
const String path = fmt::format("{}clickhouse_remove_objects_capability_{}", key_with_trailing_slash, getServerUUID());
StoredObject object(path);
const String path = fmt::format("clickhouse_remove_objects_capability_{}", getServerUUID());
const auto key = storage.generateObjectKeyForPath(path);
StoredObject object(key.serialize(), path);
try
{
auto file = storage.writeObject(object, WriteMode::Rewrite);
Expand Down
2 changes: 1 addition & 1 deletion src/Disks/ObjectStorages/S3/DiskS3Utils.h
Expand Up @@ -18,7 +18,7 @@ ObjectStorageKeysGeneratorPtr getKeyGenerator(
const String & config_prefix);

class S3ObjectStorage;
bool checkBatchRemove(S3ObjectStorage & storage, const std::string & key_with_trailing_slash);
bool checkBatchRemove(S3ObjectStorage & storage);

}

Expand Down

0 comments on commit bcb61b3

Please sign in to comment.