Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
63e4289
Object storage: identity cache + GetObjectAttributes to avoid per-fil…
UnamedRus Aug 8, 2026
ef65f44
Object storage: own the identity cache from Context
ianton-ru Nov 16, 2026
f01689c
Update 01271_show_privileges reference for SYSTEM DROP OBJECT STORAGE…
UnamedRus Aug 9, 2026
c653bcc
Object storage: default to HEAD for identity metadata, gate GetObject…
UnamedRus Aug 13, 2026
3119a15
Object storage: initialize ObjectMetadata::part_offsets to fix build
ianton-ru Nov 16, 2026
56df2a6
Object storage: test identity cache and honor the fetch-part-offsets …
ianton-ru Nov 17, 2026
b9229c4
Object storage: key the identity cache by endpoint and region
ianton-ru Nov 17, 2026
17e10c3
Object storage: drop replaced object identity from the identity cache
ianton-ru Nov 17, 2026
5c9cd7f
Object storage: store the quoted ETag from GetObjectAttributes
ianton-ru Nov 17, 2026
91e2cf3
Object storage: create the identity cache on config reload
ianton-ru Nov 17, 2026
8421641
Object storage: simplify the identity cache
ianton-ru Nov 17, 2026
25026d6
Object storage: keep a stale identity out of the cache after an overw…
ianton-ru Nov 17, 2026
5c9ae99
Object storage: keep a fetch from storing after the identity cache is…
ianton-ru Nov 17, 2026
7099ed7
Object storage: cap the identity cache generation map
ianton-ru Nov 17, 2026
a1580ca
Object storage: simplify the identity cache generation to one epoch
ianton-ru Nov 17, 2026
46e8d1c
Object storage: drop a replaced object's identity from the identity c…
ianton-ru Nov 17, 2026
87e0944
Object storage: keep the url() shard index when fetching object metadata
ianton-ru Nov 17, 2026
e1cf3b4
Object storage: return Last-Modified from the identity cache
ianton-ru Nov 17, 2026
4309cb8
Object storage: keep a cached Last-Modified out of schema and count f…
ianton-ru Nov 17, 2026
a5016ad
Object storage: revalidate the identity before a filesystem-cache hit
ianton-ru Nov 17, 2026
d6e0058
Object storage: do not cache "time unknown" from GetObjectAttributes
ianton-ru Nov 17, 2026
24f0663
Object storage: revalidate a filesystem-cache hit with HEAD, not GetO…
ianton-ru Nov 17, 2026
5d910de
Object storage: HEAD before a Parquet footer-only count uses an ident…
ianton-ru Nov 17, 2026
62901c4
Object storage: identity cache stores only HEAD results
ianton-ru Nov 17, 2026
1cda589
Object storage: re-HEAD an identity-cache hit before a skip decision
ianton-ru Nov 17, 2026
e05a9bc
Object storage: re-HEAD before skipping an empty condition-cache repl…
ianton-ru Nov 17, 2026
9253933
Merge remote-tracking branch 'altinity/antalya-26.8' into feature/ant…
ianton-ru Nov 17, 2026
d208648
Object storage: rename the private S3 metadata overload to fix overlo…
ianton-ru Nov 17, 2026
be68b12
Object storage: pin populate-on-miss in the identity cache filesystem…
ianton-ru Nov 17, 2026
0ffd9d6
Merge branch 'antalya-26.8' into feature/antalya-26.8/object-storage-…
ianton-ru Nov 17, 2026
96dba9e
Object storage: clear the identity cache in tests that rewrite object…
ianton-ru Nov 18, 2026
9f77d4e
Key the object storage identity cache by credentials
ianton-ru Nov 18, 2026
0c385e1
Object storage: do not use a cached identity for reads without ETag v…
ianton-ru Nov 19, 2026
2608efa
Object storage: drop the identity cache entry for backup writes and d…
ianton-ru Nov 19, 2026
2d50588
Object storage: drop the identity cache entry when an upload fails af…
ianton-ru Nov 19, 2026
e1b1580
Object storage: drop the identity cache entry when a copy fails after…
ianton-ru Nov 19, 2026
1263d35
Object storage queue: drop the identity cache entry for a cross-bucke…
ianton-ru Nov 19, 2026
2add0ef
Object storage: share one helper for dropping the identity cache entry
ianton-ru Nov 19, 2026
9990639
Object storage: declare s3_validate_etag_on_read in S3ObjectStorage
ianton-ru Nov 19, 2026
0805259
Merge branch 'antalya-26.8' into feature/antalya-26.8/object-storage-…
ianton-ru Nov 23, 2026
c42bc9c
Object storage: restore the pin argument position in createReadBuffer
ianton-ru Nov 23, 2026
5fd1461
Object storage: confirm an identity-cache hit before any condition-ca…
ianton-ru Nov 23, 2026
bde2fbd
Object storage: mark the identity cache clear as an override
ianton-ru Nov 23, 2026
85c874d
Tests: validate the ETag in identity-cache hit tests
ianton-ru Nov 23, 2026
cbbd954
Tests: remove the first backup object before the second backup
ianton-ru Nov 23, 2026
bdfca7c
Tests: write four Parquet row groups in the partial condition-cache test
ianton-ru Nov 23, 2026
40b51be
Forward `getObjectMetadataIgnoringIdentityCache` in `CachedObjectStor…
ianton-ru Nov 23, 2026
ebb662f
Object storage: drop the identity cache entry when `preFinalize` fail…
ianton-ru Nov 26, 2026
2e47295
Object storage: drop the identity cache entry when a write buffer is …
ianton-ru Nov 26, 2026
ddd170b
Object storage: drop the identity cache entry when a delete fails
ianton-ru Nov 26, 2026
b5a9264
Object storage: lock memory exceptions in the identity cache invalida…
ianton-ru Nov 26, 2026
e65b47a
Object storage: drop the identity cache entry when a restore copies a…
ianton-ru Nov 26, 2026
2164e1a
Object storage: restore to a cache-wrapped S3 disk without a cast to …
ianton-ru Nov 26, 2026
6f6c3c2
Tests: pin the count optimization in the identity cache Parquet count…
ianton-ru Nov 26, 2026
c19329f
Merge branch 'antalya-26.8' into feature/antalya-26.8/object-storage-…
ianton-ru Nov 26, 2026
67567e0
Object storage: separate identity cache entries by request headers
ianton-ru Nov 26, 2026
acde8d5
Object storage: keep identity cache fetch ordering after eviction
ianton-ru Nov 26, 2026
21c2642
Docs: state that the object storage identity cache does not see exter…
ianton-ru Nov 26, 2026
a2e2da6
Object storage: keep identity cache invalidation from throwing memory…
ianton-ru Nov 26, 2026
456ca72
Object storage: count the identity cache key in the entry weight
ianton-ru Nov 26, 2026
4ad1cd9
Tests: shorten the path in the identity cache weight test
ianton-ru Nov 26, 2026
5372584
Tests: use a shorter path in the identity cache weight test
ianton-ru Nov 26, 2026
0efa794
Count both copies of the key in the object storage identity cache weight
ianton-ru Nov 26, 2026
04088c0
Rename the identity cache key weight field to `key_memory`
ianton-ru Nov 26, 2026
32fbd93
Merge branch 'antalya-26.8' into feature/antalya-26.8/object-storage-…
ianton-ru Nov 26, 2026
050bc00
Tests: expect no number-of-rows cache hit for identity-cached S3 objects
ianton-ru Nov 27, 2026
ac85e69
Object storage: do not drop identity cache stores for writes to other…
ianton-ru Nov 27, 2026
126f57c
Tests: check the number-of-rows cache hit for S3 with identity cache …
ianton-ru Nov 27, 2026
f9476da
Tests: restore the ETag validation setting in 05489 that the previous…
ianton-ru Nov 27, 2026
8aafbe6
Reject an Iceberg constant column whose value does not fit the reques…
ianton-ru Nov 30, 2026
5f49c7a
Iceberg: read a column from the file when its bound is not a constant…
ianton-ru Nov 30, 2026
4edbed8
Object storage: do not cache an identity that has no ETag
ianton-ru Dec 1, 2026
db92ddb
Object storage: revalidate an identity-cache hit before every Parquet…
ianton-ru Dec 1, 2026
3635038
Object storage: separate `gcp_oauth` identities in the identity cache…
ianton-ru Dec 1, 2026
2a36913
Iceberg: revalidate an identity-cache hit before its ETag keys the Pu…
ianton-ru Dec 1, 2026
a1ed91e
Object storage: drop the identity cache entry on every exit of a writ…
ianton-ru Dec 1, 2026
458abf4
Object storage: revalidate an identity-cache hit for the `One` format…
ianton-ru Dec 1, 2026
8dce144
Object storage: revalidate an identity-cache hit before an archive re…
ianton-ru Dec 1, 2026
1e9fb2b
Object storage: drop the identity cache entry when a GET answers `416`
ianton-ru Dec 1, 2026
b6eb20a
Object storage: make the `WriteBufferFromS3` creation-request flag at…
ianton-ru Dec 1, 2026
da4fa65
Object storage: store the credential hash of the client that signed t…
ianton-ru Dec 1, 2026
0e39e9b
Delta Lake: read the identity of `_last_checkpoint` with a HEAD
ianton-ru Dec 1, 2026
a4ba831
Object storage: guard the upload callback in `WriteBufferFromS3::canc…
ianton-ru Dec 1, 2026
615ed95
Object storage: drop the identity of the Keeper lock file on every ex…
ianton-ru Dec 1, 2026
81462c2
Object storage: drop the identity cache entry when an uncached HEAD f…
ianton-ru Dec 1, 2026
592bb25
Object storage: do not store an identity with a weak ETag
ianton-ru Dec 1, 2026
70dcf01
Object storage: do not use an identity-cache hit for a read of a give…
ianton-ru Dec 1, 2026
28cc395
Revalidate a zero-size identity cache hit before the read
ianton-ru Dec 1, 2026
d05c186
Revalidate an identity cache hit for the `One` format before the empt…
ianton-ru Dec 1, 2026
a331469
Revalidate an identity cache hit for Parquet only when the footer may…
ianton-ru Dec 1, 2026
2608a27
Report `object_storage_identity_cache_size` as changeable without res…
ianton-ru Dec 1, 2026
ff46029
Add a test that `object_storage_identity_cache_size` is changeable wi…
ianton-ru Dec 1, 2026
e567e4b
Drop the identity cache when a config reload sets its size to 0
ianton-ru Dec 1, 2026
5cd1931
Make the identity cache tests exercise the code they claim to cover
ianton-ru Dec 1, 2026
9bfecb9
Use the real name of the S3 setting in the test of the 404 invalidation
ianton-ru Dec 1, 2026
a1db177
Remove temporary files of `00408_http_keep_alive` added by mistake
ianton-ru Dec 1, 2026
31bd07b
Do not refresh the identity in the second pass of lazy materializatio…
ianton-ru Dec 1, 2026
510f00e
Invalidate every key of a batch delete, also for a key that failed
ianton-ru Dec 1, 2026
111641f
Do not use the parquet metadata cache for an unconfirmed identity cac…
ianton-ru Dec 1, 2026
96cf7d7
Empty the identity cache that a config reload to 0 detaches, outside …
ianton-ru Dec 1, 2026
8875a37
Report `object_storage_identity_cache_size` as changeable also while …
ianton-ru Dec 1, 2026
a0d3fc8
Drop the identity cache entry when a request for tags finds the objec…
ianton-ru Dec 1, 2026
380864e
Pin `optimize_count_from_files` in `05493` and remove the port race f…
ianton-ru Dec 1, 2026
c2cc3c1
Object storage: mark a weak ETag from an S3 listing as weak
ianton-ru Dec 1, 2026
e32f84f
Revalidate an identity cache hit of a tiny object before the read
ianton-ru Dec 1, 2026
5b8e964
Object storage: store the identity that an uncached metadata request …
ianton-ru Dec 1, 2026
ee36514
Object storage: skip an object that the read-time HEAD found empty
ianton-ru Dec 1, 2026
971d8cd
Object storage: revalidate a short identity hit only for formats that…
ianton-ru Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/reference/statements/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ Clears the per-URL Confluent Schema Registry caches used by the `AvroConfluent`

Clears the parquet metadata cache.

## SYSTEM CLEAR|DROP OBJECT STORAGE IDENTITY CACHE {#drop-object-storage-identity-cache}

Clears the object-storage identity cache, which stores per-object size, ETag and Last-Modified so that opening an object does not repeat a `HEAD` request. Its size is configured with the server settings `object_storage_identity_cache_size`, `object_storage_identity_cache_policy` and `object_storage_identity_cache_size_ratio`. Set `object_storage_identity_cache_size` to `0` to disable the cache. `SYSTEM RELOAD CONFIG` with a non-zero size creates it when startup left it disabled. A write, copy, or delete by this server drops that object's entry, and the next read requests the metadata again.

The modification time from this cache is not proof that the object is unchanged, so the schema inference cache and the number-of-rows cache are not used for an object whose modification time comes from it. A query on such an object infers the schema and counts the rows again.

An object that was replaced outside this server is not noticed until the entry is dropped. A read that downloads the object detects the replacement through the ETag (`If-Match`, enabled by `s3_validate_etag_on_read`) and then drops the entry, but a metadata-only read can return the previous size, ETag and modification time: for example the virtual columns `_size`, `_etag` and `_time`. To always see current metadata, set `s3_validate_etag_on_read` to `0` for the query (a cached entry is then not used), set `object_storage_identity_cache_size` to `0`, or run `SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHE` after the external change.

## SYSTEM CLEAR|DROP PAIMON METADATA CACHE {#drop-paimon-metadata-cache}

Clears the in-memory cache of parsed Paimon metadata files (manifest lists and manifests).
Expand Down
14 changes: 14 additions & 0 deletions programs/local/LocalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ namespace ServerSetting
extern const ServerSettingsString mark_cache_policy;
extern const ServerSettingsUInt64 mark_cache_size;
extern const ServerSettingsDouble mark_cache_size_ratio;
extern const ServerSettingsString object_storage_identity_cache_policy;
extern const ServerSettingsUInt64 object_storage_identity_cache_size;
extern const ServerSettingsDouble object_storage_identity_cache_size_ratio;
extern const ServerSettingsString unique_key_bitmap_cache_policy;
extern const ServerSettingsUInt64 unique_key_bitmap_cache_size_bytes;
extern const ServerSettingsDouble unique_key_bitmap_cache_size_ratio;
Expand Down Expand Up @@ -1537,6 +1540,17 @@ void LocalServer::processConfig()
}
global_context->setMarkCache(mark_cache_policy, mark_cache_size, mark_cache_size_ratio);

String object_storage_identity_cache_policy = server_settings[ServerSetting::object_storage_identity_cache_policy];
size_t object_storage_identity_cache_size = server_settings[ServerSetting::object_storage_identity_cache_size];
double object_storage_identity_cache_size_ratio = server_settings[ServerSetting::object_storage_identity_cache_size_ratio];
if (object_storage_identity_cache_size > max_cache_size)
{
object_storage_identity_cache_size = max_cache_size;
LOG_INFO(log, "Lowered object storage identity cache size to {} because the system has limited RAM", formatReadableSizeWithBinarySuffix(object_storage_identity_cache_size));
}
global_context->setObjectStorageIdentityCache(
object_storage_identity_cache_policy, object_storage_identity_cache_size, object_storage_identity_cache_size_ratio);

/// UNIQUE KEY delete-bitmap cache. Zero size disables.
String unique_key_bitmap_cache_policy_name = server_settings[ServerSetting::unique_key_bitmap_cache_policy];
size_t unique_key_bitmap_cache_size = server_settings[ServerSetting::unique_key_bitmap_cache_size_bytes];
Expand Down
15 changes: 15 additions & 0 deletions programs/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ namespace ServerSetting
extern const ServerSettingsString mark_cache_policy;
extern const ServerSettingsUInt64 mark_cache_size;
extern const ServerSettingsDouble mark_cache_size_ratio;
extern const ServerSettingsString object_storage_identity_cache_policy;
extern const ServerSettingsUInt64 object_storage_identity_cache_size;
extern const ServerSettingsDouble object_storage_identity_cache_size_ratio;
extern const ServerSettingsString unique_key_index_cache_policy;
extern const ServerSettingsUInt64 unique_key_index_cache_size_bytes;
extern const ServerSettingsDouble unique_key_index_cache_size_ratio;
Expand Down Expand Up @@ -2483,6 +2486,17 @@ try
}
global_context->setMarkCache(mark_cache_policy, mark_cache_size, mark_cache_size_ratio);

String object_storage_identity_cache_policy = server_settings[ServerSetting::object_storage_identity_cache_policy];
size_t object_storage_identity_cache_size = server_settings[ServerSetting::object_storage_identity_cache_size];
double object_storage_identity_cache_size_ratio = server_settings[ServerSetting::object_storage_identity_cache_size_ratio];
if (object_storage_identity_cache_size > max_cache_size)
{
object_storage_identity_cache_size = max_cache_size;
LOG_INFO(log, "Lowered object storage identity cache size to {} because the system has limited RAM", formatReadableSizeWithBinarySuffix(object_storage_identity_cache_size));
}
global_context->setObjectStorageIdentityCache(
object_storage_identity_cache_policy, object_storage_identity_cache_size, object_storage_identity_cache_size_ratio);

String unique_key_index_cache_policy_name = server_settings[ServerSetting::unique_key_index_cache_policy];
size_t unique_key_index_cache_size = server_settings[ServerSetting::unique_key_index_cache_size_bytes];
double unique_key_index_cache_size_ratio = server_settings[ServerSetting::unique_key_index_cache_size_ratio];
Expand Down Expand Up @@ -3136,6 +3150,7 @@ try

global_context->updateUncompressedCacheConfiguration(config(), max_cache_size_in_bytes);
global_context->updateMarkCacheConfiguration(config(), max_cache_size_in_bytes);
global_context->updateObjectStorageIdentityCacheConfiguration(config(), max_cache_size_in_bytes);
global_context->updateUniqueKeyIndexCacheConfiguration(config(), max_cache_size_in_bytes);
global_context->updateDeleteBitmapCacheConfiguration(config(), max_cache_size_in_bytes);
global_context->updatePrimaryIndexCacheConfiguration(config(), max_cache_size_in_bytes);
Expand Down
1 change: 1 addition & 0 deletions src/Access/Common/AccessType.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ enum class AccessType : uint16_t
M(SYSTEM_DROP_PAIMON_METADATA_CACHE, "SYSTEM CLEAR PAIMON_METADATA_CACHE, SYSTEM DROP PAIMON_METADATA_CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
M(SYSTEM_DROP_AVRO_SCHEMA_CACHE, "SYSTEM CLEAR AVRO SCHEMA CACHE, SYSTEM DROP AVRO SCHEMA CACHE, DROP AVRO SCHEMA CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
M(SYSTEM_DROP_PARQUET_METADATA_CACHE, "SYSTEM DROP PARQUET_METADATA_CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
M(SYSTEM_DROP_OBJECT_STORAGE_IDENTITY_CACHE, "SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHE, SYSTEM DROP OBJECT STORAGE IDENTITY CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
M(SYSTEM_DROP_POINT_IN_POLYGON_CACHE, "SYSTEM CLEAR POINT IN POLYGON CACHE, SYSTEM DROP POINT IN POLYGON CACHE, DROP POINT IN POLYGON CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
M(SYSTEM_DROP_PUFFIN_FILES_CACHE, "SYSTEM DROP PUFFIN_FILES_CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
M(SYSTEM_PREWARM_PRIMARY_INDEX_CACHE, "SYSTEM PREWARM PRIMARY INDEX, PREWARM PRIMARY INDEX CACHE, PREWARM PRIMARY INDEX", GLOBAL, SYSTEM_DROP_CACHE) \
Expand Down
126 changes: 107 additions & 19 deletions src/Backups/BackupIO_S3.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Backups/BackupIO_S3.h>

#if USE_AWS_S3
#include <Common/scope_guard_safe.h>
#include <Core/Settings.h>
#include <Core/ServerSettings.h>
#include <Common/HTTPHeaderFilter.h>
Expand All @@ -20,7 +21,7 @@
#include <Disks/IDisk.h>
#include <Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/ContentAddressedExchange.h>
#include <Disks/DiskObjectStorage/ObjectStorages/IObjectStorage.h>

#include <Disks/DiskObjectStorage/ObjectStorages/ObjectStorageIdentityCache.h>
#include <Poco/Util/AbstractConfiguration.h>

#include <aws/core/auth/AWSCredentials.h>
Expand Down Expand Up @@ -497,17 +498,34 @@ void BackupReaderS3::copyToDiskImpl(const String & path_in_backup, size_t offset
auto runner = threadPoolCallbackRunnerUnsafe<void>(getBackupsIOThreadPool().get(), ThreadName::S3_BACKUP_READER);
auto create_read_buffer = [&, this] { return readFile(path_in_backup); };

/// The restored object replaces `blob_path[0]` in `blob_path[1]`, which may hold an identity cached by an
/// earlier read. Key the entry by the destination endpoint, as `S3ObjectStorage` does for its own writes.
/// `getDescription` returns that endpoint and forwards through a cache layer, so a cached S3 disk works too.
/// The native copy is only taken when the destination has the S3 data source kind.
const String dest_endpoint = destination_disk->getObjectStorage()->getDescription();
const String dest_bucket = blob_path[1];
const String dest_key = blob_path[0];
/// Runs when the copy throws after an object-creating request was sent. The success path below runs it too.
auto invalidate_destination = [dest_endpoint, dest_bucket, dest_key]()
{
invalidateObjectStorageIdentityCache(dest_endpoint, dest_bucket, dest_key);
};

if (is_range)
copyS3FileRange(
client, s3_uri.bucket, src_key, offset, size, /* src_object_size= */ file_size,
dest_client, /* dest_bucket= */ blob_path[1], /* dest_key= */ blob_path[0],
s3_settings.request_settings, read_settings, blob_storage_log, runner, create_read_buffer, object_attributes);
dest_client, dest_bucket, dest_key,
s3_settings.request_settings, read_settings, blob_storage_log, runner, create_read_buffer, object_attributes,
invalidate_destination);
else
copyS3File(
client, s3_uri.bucket, src_key, size,
dest_client, /* dest_bucket= */ blob_path[1], /* dest_key= */ blob_path[0],
s3_settings.request_settings, read_settings, blob_storage_log, runner, create_read_buffer, object_attributes);
dest_client, dest_bucket, dest_key,
s3_settings.request_settings, read_settings, blob_storage_log, runner, create_read_buffer, object_attributes,
ObjectStorageCopyMode::Default, /* object_creation_client= */ nullptr, invalidate_destination);

/// The copy has returned, so `dest_key` now holds the restored object.
invalidate_destination();
return size;
};

Expand Down Expand Up @@ -649,6 +667,15 @@ void BackupWriterS3::copyFileFromDisk(
const size_t source_size = ca_plan ? ca_plan->object.bytes_size
: (copy_encrypted ? src_disk->getEncryptedFileSize(src_path) : src_disk->getFileSize(src_path));
const bool whole_object = (src_offset == 0) && (length == source_size);
const String dest_key = fs::path(s3_uri.key) / path_in_backup;
/// Runs when the copy throws after `CopyObject`, `PutObject`, or `CompleteMultipartUpload`
/// was sent. The success path below invalidates only if the copy returns.
const String endpoint = s3_uri.endpoint;
const String bucket = s3_uri.bucket;
auto on_object_creation_failure = [endpoint, bucket, dest_key]()
{
invalidateObjectStorageIdentityCache(endpoint, bucket, dest_key);
};

if (whole_object)
{
Expand All @@ -660,12 +687,16 @@ void BackupWriterS3::copyFileFromDisk(
length,
/* dest_s3_client */ client,
/* dest_bucket */ s3_uri.bucket,
/* dest_key */ fs::path(s3_uri.key) / path_in_backup,
/* dest_key */ dest_key,
s3_settings.request_settings,
read_settings,
blob_storage_log,
runner,
create_read_buffer);
create_read_buffer,
/* object_metadata= */ std::nullopt,
ObjectStorageCopyMode::Default,
/* object_creation_client= */ nullptr,
on_object_creation_failure);
}
else
{
Expand All @@ -678,14 +709,18 @@ void BackupWriterS3::copyFileFromDisk(
/* src_object_size= */ source_size,
/* dest_s3_client */ client,
/* dest_bucket */ s3_uri.bucket,
/* dest_key */ fs::path(s3_uri.key) / path_in_backup,
/* dest_key */ dest_key,
s3_settings.request_settings,
read_settings,
blob_storage_log,
runner,
create_read_buffer);
create_read_buffer,
/* object_metadata= */ std::nullopt,
on_object_creation_failure);
}

/// The copy has replaced `dest_key`. A read that cached the previous ETag must not send it as `If-Match`.
invalidateObjectStorageIdentityCache(s3_uri.endpoint, s3_uri.bucket, dest_key);
return; /// copied!
}
}
Expand All @@ -699,14 +734,17 @@ void BackupWriterS3::copyFile(const String & destination, const String & source,
LOG_TRACE(log, "Copying file inside backup from {} to {}", source, destination);

const auto source_key = fs::path(s3_uri.key) / source;
const String dest_key = fs::path(s3_uri.key) / destination;
const String endpoint = s3_uri.endpoint;
const String bucket = s3_uri.bucket;
copyS3File(
client,
/* src_bucket */ s3_uri.bucket,
/* src_key= */ source_key,
size,
/* dest_s3_client= */ client,
/* dest_bucket= */ s3_uri.bucket,
/* dest_key= */ fs::path(s3_uri.key) / destination,
/* dest_key= */ dest_key,
s3_settings.request_settings,
read_settings,
blob_storage_log,
Expand All @@ -716,14 +754,31 @@ void BackupWriterS3::copyFile(const String & destination, const String & source,
LOG_TRACE(log, "Falling back to copy file inside backup from {} to {} through direct buffers", source, destination);
return std::make_unique<ReadBufferFromS3>(
client, s3_uri.bucket, source_key, s3_uri.version_id, s3_settings.request_settings, read_settings);
},
/* object_metadata= */ std::nullopt,
ObjectStorageCopyMode::Default,
/* object_creation_client= */ nullptr,
[endpoint, bucket, dest_key]()
{
invalidateObjectStorageIdentityCache(endpoint, bucket, dest_key);
});
invalidateObjectStorageIdentityCache(s3_uri.endpoint, s3_uri.bucket, dest_key);
}

void BackupWriterS3::copyDataToFile(const String & path_in_backup, const CreateReadBufferFunction & create_read_buffer, UInt64 start_pos, UInt64 length)
{
copyDataToS3File(create_read_buffer, start_pos, length, client, s3_uri.bucket, fs::path(s3_uri.key) / path_in_backup,
const String dest_key = fs::path(s3_uri.key) / path_in_backup;
const String endpoint = s3_uri.endpoint;
const String bucket = s3_uri.bucket;
copyDataToS3File(create_read_buffer, start_pos, length, client, s3_uri.bucket, dest_key,
s3_settings.request_settings, blob_storage_log,
threadPoolCallbackRunnerUnsafe<void>(getBackupsIOThreadPool().get(), ThreadName::S3_BACKUP_WRITER));
threadPoolCallbackRunnerUnsafe<void>(getBackupsIOThreadPool().get(), ThreadName::S3_BACKUP_WRITER),
/* object_metadata= */ std::nullopt,
[endpoint, bucket, dest_key]()
{
invalidateObjectStorageIdentityCache(endpoint, bucket, dest_key);
});
invalidateObjectStorageIdentityCache(s3_uri.endpoint, s3_uri.bucket, dest_key);
}

BackupWriterS3::~BackupWriterS3() = default;
Expand Down Expand Up @@ -752,37 +807,61 @@ std::unique_ptr<ReadBuffer> BackupWriterS3::readFile(const String & file_name, s

std::unique_ptr<WriteBuffer> BackupWriterS3::writeFile(const String & file_name)
{
/// Captured by value. The buffer can outlive this writer, and the cache itself is process-global.
const String endpoint = s3_uri.endpoint;
const String bucket = s3_uri.bucket;
const String object_key = fs::path(s3_uri.key) / file_name;
return std::make_unique<WriteBufferFromS3>(
client,
s3_uri.bucket,
fs::path(s3_uri.key) / file_name,
bucket,
object_key,
DBMS_DEFAULT_BUFFER_SIZE,
s3_settings.request_settings,
blob_storage_log,
std::nullopt,
threadPoolCallbackRunnerUnsafe<void>(getBackupsIOThreadPool().get(), ThreadName::S3_BACKUP_WRITER),
write_settings);
write_settings,
/* object_creation_client */ nullptr,
[endpoint, bucket, object_key]()
{
invalidateObjectStorageIdentityCache(endpoint, bucket, object_key);
});
}

std::unique_ptr<WriteBuffer> BackupWriterS3::writeFileIfNotExists(const String & file_name)
{
WriteSettings conditional_write_settings = write_settings;
conditional_write_settings.object_storage_write_if_none_match = "*";
const String endpoint = s3_uri.endpoint;
const String bucket = s3_uri.bucket;
const String object_key = fs::path(s3_uri.key) / file_name;
return std::make_unique<WriteBufferFromS3>(
client,
s3_uri.bucket,
fs::path(s3_uri.key) / file_name,
bucket,
object_key,
DBMS_DEFAULT_BUFFER_SIZE,
s3_settings.request_settings,
blob_storage_log,
std::nullopt,
threadPoolCallbackRunnerUnsafe<void>(getBackupsIOThreadPool().get(), ThreadName::S3_BACKUP_WRITER),
conditional_write_settings);
conditional_write_settings,
/* object_creation_client */ nullptr,
[endpoint, bucket, object_key]()
{
invalidateObjectStorageIdentityCache(endpoint, bucket, object_key);
});
}

void BackupWriterS3::removeFile(const String & file_name)
{
deleteFileFromS3(client, s3_uri.bucket, fs::path(s3_uri.key) / file_name, /* if_exists = */ true,
const String object_key = fs::path(s3_uri.key) / file_name;
/// Runs when the delete throws too: a lost response can follow an applied delete.
/// Locks memory exceptions: a destructor is noexcept, so a MEMORY_LIMIT_EXCEEDED thrown here would terminate.
SCOPE_EXIT_MEMORY(
{
invalidateObjectStorageIdentityCache(s3_uri.endpoint, s3_uri.bucket, object_key);
});
deleteFileFromS3(client, s3_uri.bucket, object_key, /* if_exists = */ true,
blob_storage_log);
}

Expand All @@ -796,6 +875,15 @@ void BackupWriterS3::removeFiles(const Strings & file_names)
/// One call of DeleteObjects() cannot remove more than 1000 keys.
size_t batch_size = 1000;

/// A key that was deleted, or was already gone, must not keep its previous size and ETag. This also runs
/// when a later batch throws: earlier batches have already deleted their keys.
/// Locks memory exceptions: a destructor is noexcept, so a MEMORY_LIMIT_EXCEEDED thrown here would terminate.
SCOPE_EXIT_MEMORY(
{
for (const auto & key : keys)
invalidateObjectStorageIdentityCache(s3_uri.endpoint, s3_uri.bucket, key);
});

deleteFilesFromS3(client, s3_uri.bucket, keys, /* if_exists = */ true,
s3_capabilities, batch_size, blob_storage_log);
}
Expand Down
Loading
Loading