Skip to content

Commit ff42c3a

Browse files
authored
Merge pull request #805 from Altinity/list_objects_object_storage_cache_25.3
2 parents c52a6be + e1e8671 commit ff42c3a

21 files changed

+770
-17
lines changed

programs/server/Server.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
#include <Storages/System/attachInformationSchemaTables.h>
8585
#include <Storages/Cache/ExternalDataSourceCache.h>
8686
#include <Storages/Cache/registerRemoteFileMetadatas.h>
87+
#include <Storages/Cache/ObjectStorageListObjectsCache.h>
8788
#include <AggregateFunctions/registerAggregateFunctions.h>
8889
#include <Functions/UserDefined/IUserDefinedSQLObjectsStorage.h>
8990
#include <Functions/registerFunctions.h>
@@ -325,6 +326,9 @@ namespace ServerSetting
325326
extern const ServerSettingsDouble page_cache_free_memory_ratio;
326327
extern const ServerSettingsUInt64 page_cache_lookahead_blocks;
327328
extern const ServerSettingsUInt64 input_format_parquet_metadata_cache_max_size;
329+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_size;
330+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_max_entries;
331+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_ttl;
328332
}
329333

330334
}
@@ -2397,6 +2401,10 @@ try
23972401
if (dns_cache_updater)
23982402
dns_cache_updater->start();
23992403

2404+
ObjectStorageListObjectsCache::instance().setMaxSizeInBytes(server_settings[ServerSetting::object_storage_list_objects_cache_size]);
2405+
ObjectStorageListObjectsCache::instance().setMaxCount(server_settings[ServerSetting::object_storage_list_objects_cache_max_entries]);
2406+
ObjectStorageListObjectsCache::instance().setTTL(server_settings[ServerSetting::object_storage_list_objects_cache_ttl]);
2407+
24002408
auto replicas_reconnector = ReplicasReconnector::init(global_context);
24012409
ParquetFileMetaDataCache::instance()->setMaxSizeInBytes(server_settings[ServerSetting::input_format_parquet_metadata_cache_max_size]);
24022410

src/Access/Common/AccessType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ enum class AccessType : uint8_t
184184
M(SYSTEM_DROP_FORMAT_SCHEMA_CACHE, "SYSTEM DROP FORMAT SCHEMA CACHE, DROP FORMAT SCHEMA CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
185185
M(SYSTEM_DROP_S3_CLIENT_CACHE, "SYSTEM DROP S3 CLIENT, DROP S3 CLIENT CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
186186
M(SYSTEM_DROP_PARQUET_METADATA_CACHE, "SYSTEM DROP PARQUET METADATA CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
187+
M(SYSTEM_DROP_OBJECT_STORAGE_LIST_OBJECTS_CACHE, "SYSTEM DROP OBJECT STORAGE LIST OBJECTS CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
187188
M(SYSTEM_DROP_CACHE, "DROP CACHE", GROUP, SYSTEM) \
188189
M(SYSTEM_RELOAD_CONFIG, "RELOAD CONFIG", GLOBAL, SYSTEM_RELOAD) \
189190
M(SYSTEM_RELOAD_USERS, "RELOAD USERS", GLOBAL, SYSTEM_RELOAD) \

src/Common/ProfileEvents.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ The server successfully detected this situation and will download merged part fr
977977
M(QueryPreempted, "How many times tasks are paused and waiting due to 'priority' setting", ValueType::Number) \
978978
M(ParquetMetaDataCacheHits, "Number of times the read from filesystem cache hit the cache.", ValueType::Number) \
979979
M(ParquetMetaDataCacheMisses, "Number of times the read from filesystem cache miss the cache.", ValueType::Number) \
980+
M(ObjectStorageListObjectsCacheHits, "Number of times object storage list objects operation hit the cache.", ValueType::Number) \
981+
M(ObjectStorageListObjectsCacheMisses, "Number of times object storage list objects operation miss the cache.", ValueType::Number) \
982+
M(ObjectStorageListObjectsCacheExactMatchHits, "Number of times object storage list objects operation hit the cache with an exact match.", ValueType::Number) \
983+
M(ObjectStorageListObjectsCachePrefixMatchHits, "Number of times object storage list objects operation miss the cache using prefix matching.", ValueType::Number) \
980984

981985
#ifdef APPLY_FOR_EXTERNAL_EVENTS
982986
#define APPLY_FOR_EVENTS(M) APPLY_FOR_BUILTIN_EVENTS(M) APPLY_FOR_EXTERNAL_EVENTS(M)

src/Common/TTLCachePolicy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ class TTLCachePolicy : public ICachePolicy<Key, Mapped, HashFunction, WeightFunc
248248
return res;
249249
}
250250

251-
private:
251+
protected:
252252
using Cache = std::unordered_map<Key, MappedPtr, HashFunction>;
253253
Cache cache;
254-
254+
private:
255255
/// TODO To speed up removal of stale entries, we could also add another container sorted on expiry times which maps keys to iterators
256256
/// into the cache. To insert an entry, add it to the cache + add the iterator to the sorted container. To remove stale entries, do a
257257
/// binary search on the sorted container and erase all left of the found key.

src/Core/ServerSettings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,9 @@ namespace DB
10251025
)", 0) \
10261026
DECLARE(Bool, storage_shared_set_join_use_inner_uuid, false, "If enabled, an inner UUID is generated during the creation of SharedSet and SharedJoin. ClickHouse Cloud only", 0) \
10271027
DECLARE(UInt64, input_format_parquet_metadata_cache_max_size, 500000000, "Maximum size of parquet file metadata cache", 0) \
1028+
DECLARE(UInt64, object_storage_list_objects_cache_size, 500000000, "Maximum size of ObjectStorage list objects cache in bytes. Zero means disabled.", 0) \
1029+
DECLARE(UInt64, object_storage_list_objects_cache_max_entries, 1000, "Maximum size of ObjectStorage list objects cache in entries. Zero means disabled.", 0) \
1030+
DECLARE(UInt64, object_storage_list_objects_cache_ttl, 3600, "Time to live of records in ObjectStorage list objects cache in seconds. Zero means unlimited", 0)
10281031
// clang-format on
10291032

10301033
/// If you add a setting which can be updated at runtime, please update 'changeable_settings' map in dumpToSystemServerSettingsColumns below

src/Core/Settings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6135,6 +6135,9 @@ Possible values:
61356135
/** Experimental tsToGrid aggregate function. */ \
61366136
DECLARE(Bool, allow_experimental_ts_to_grid_aggregate_function, false, R"(
61376137
Experimental tsToGrid aggregate function for Prometheus-like timeseries resampling. Cloud only
6138+
)", EXPERIMENTAL) \
6139+
DECLARE(Bool, use_object_storage_list_objects_cache, false, R"(
6140+
Cache the list of objects returned by list objects calls in object storage
61386141
)", EXPERIMENTAL) \
61396142
DECLARE(Bool, object_storage_remote_initiator, false, R"(
61406143
Execute request to object storage as remote on one of object_storage_cluster nodes.

src/Core/SettingsChangesHistory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const VersionToSettingsChangesMap & getSettingsChangesHistory()
7171
// Altinity Antalya modifications atop of 25.2
7272
{"object_storage_cluster", "", "", "New setting"},
7373
{"object_storage_max_nodes", 0, 0, "New setting"},
74+
{"use_object_storage_list_objects_cache", true, false, "New setting."},
7475
});
7576
addSettingsChanges(settings_changes_history, "25.3",
7677
{

src/Disks/ObjectStorages/AzureBlobStorage/AzureObjectStorage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class AzureObjectStorage : public IObjectStorage
3131
const String & object_namespace_,
3232
const String & description_);
3333

34+
bool supportsListObjectsCache() override { return true; }
35+
3436
void listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const override;
3537

3638
ObjectStorageIteratorPtr iterate(const std::string & path_prefix, size_t max_keys) const override;

src/Disks/ObjectStorages/IObjectStorage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ class IObjectStorage
276276
#endif
277277

278278

279+
virtual bool supportsListObjectsCache() { return false; }
280+
279281
private:
280282
mutable std::mutex throttlers_mutex;
281283
ThrottlerPtr remote_read_throttler;

src/Disks/ObjectStorages/S3/S3ObjectStorage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class S3ObjectStorage : public IObjectStorage
8181

8282
ObjectStorageType getType() const override { return ObjectStorageType::S3; }
8383

84+
bool supportsListObjectsCache() override { return true; }
85+
8486
bool exists(const StoredObject & object) const override;
8587

8688
std::unique_ptr<ReadBufferFromFileBase> readObject( /// NOLINT

0 commit comments

Comments
 (0)