Skip to content

Commit e92ba19

Browse files
Enmkarthurpassos
authored andcommitted
Merge pull request #743 from Altinity/list_objects_cache
Antalya: Cache the list objects operation on object storage using a TTL + prefix matching cache implementation
1 parent c4d9b13 commit e92ba19

21 files changed

+790
-19
lines changed

programs/server/Server.cpp

Lines changed: 9 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>
@@ -316,6 +317,10 @@ namespace ServerSetting
316317
extern const ServerSettingsUInt64 page_cache_max_size;
317318
extern const ServerSettingsDouble page_cache_free_memory_ratio;
318319
extern const ServerSettingsUInt64 page_cache_lookahead_blocks;
320+
extern const ServerSettingsUInt64 input_format_parquet_metadata_cache_max_size;
321+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_size;
322+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_max_entries;
323+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_ttl;
319324
}
320325

321326
}
@@ -2375,6 +2380,10 @@ try
23752380
if (dns_cache_updater)
23762381
dns_cache_updater->start();
23772382

2383+
ObjectStorageListObjectsCache::instance().setMaxSizeInBytes(server_settings[ServerSetting::object_storage_list_objects_cache_size]);
2384+
ObjectStorageListObjectsCache::instance().setMaxCount(server_settings[ServerSetting::object_storage_list_objects_cache_max_entries]);
2385+
ObjectStorageListObjectsCache::instance().setTTL(server_settings[ServerSetting::object_storage_list_objects_cache_ttl]);
2386+
23782387
auto replicas_reconnector = ReplicasReconnector::init(global_context);
23792388

23802389
/// Set current database name before loading tables and databases because

src/Access/Common/AccessType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ enum class AccessType : uint8_t
182182
M(SYSTEM_DROP_SCHEMA_CACHE, "SYSTEM DROP SCHEMA CACHE, DROP SCHEMA CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
183183
M(SYSTEM_DROP_FORMAT_SCHEMA_CACHE, "SYSTEM DROP FORMAT SCHEMA CACHE, DROP FORMAT SCHEMA CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
184184
M(SYSTEM_DROP_S3_CLIENT_CACHE, "SYSTEM DROP S3 CLIENT, DROP S3 CLIENT CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
185+
M(SYSTEM_DROP_OBJECT_STORAGE_LIST_OBJECTS_CACHE, "SYSTEM DROP OBJECT STORAGE LIST OBJECTS CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
185186
M(SYSTEM_DROP_CACHE, "DROP CACHE", GROUP, SYSTEM) \
186187
M(SYSTEM_RELOAD_CONFIG, "RELOAD CONFIG", GLOBAL, SYSTEM_RELOAD) \
187188
M(SYSTEM_RELOAD_USERS, "RELOAD USERS", GLOBAL, SYSTEM_RELOAD) \

src/Common/ProfileEvents.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,22 @@ The server successfully detected this situation and will download merged part fr
964964
M(MemoryWorkerRun, "Number of runs done by MemoryWorker in background", ValueType::Number) \
965965
M(MemoryWorkerRunElapsedMicroseconds, "Total time spent by MemoryWorker for background work", ValueType::Microseconds) \
966966
\
967+
<<<<<<< HEAD
967968
M(ParquetFetchWaitTimeMicroseconds, "Time of waiting fetching parquet data", ValueType::Microseconds) \
968969
M(FilterTransformPassedRows, "Number of rows that passed the filter in the query", ValueType::Number) \
969970
M(FilterTransformPassedBytes, "Number of bytes that passed the filter in the query", ValueType::Bytes) \
970971
M(QueryPreempted, "How many times tasks are paused and waiting due to 'priority' setting", ValueType::Number) \
971972

973+
=======
974+
M(ParquetFetchWaitTimeMicroseconds, "Time of waiting fetching parquet data", ValueType::Microseconds) \
975+
\
976+
M(ParquetMetaDataCacheHits, "Number of times the read from filesystem cache hit the cache.", ValueType::Number) \
977+
M(ParquetMetaDataCacheMisses, "Number of times the read from filesystem cache miss the cache.", ValueType::Number) \
978+
M(ObjectStorageListObjectsCacheHits, "Number of times object storage list objects operation hit the cache.", ValueType::Number) \
979+
M(ObjectStorageListObjectsCacheMisses, "Number of times object storage list objects operation miss the cache.", ValueType::Number) \
980+
M(ObjectStorageListObjectsCacheExactMatchHits, "Number of times object storage list objects operation hit the cache with an exact match.", ValueType::Number) \
981+
M(ObjectStorageListObjectsCachePrefixMatchHits, "Number of times object storage list objects operation miss the cache using prefix matching.", ValueType::Number) \
982+
>>>>>>> 60282dacee4 (Merge pull request #743 from Altinity/list_objects_cache)
972983

973984
#ifdef APPLY_FOR_EXTERNAL_EVENTS
974985
#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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,11 @@ namespace DB
10201020
```
10211021
)", 0) \
10221022
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)
1023-
1024-
1023+
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) \
1024+
DECLARE(UInt64, input_format_parquet_metadata_cache_max_size, 500000000, "Maximum size of parquet file metadata cache", 0) \
1025+
DECLARE(UInt64, object_storage_list_objects_cache_size, 500000000, "Maximum size of ObjectStorage list objects cache in bytes. Zero means disabled.", 0) \
1026+
DECLARE(UInt64, object_storage_list_objects_cache_max_entries, 1000, "Maximum size of ObjectStorage list objects cache in entries. Zero means disabled.", 0) \
1027+
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) \
10251028
// clang-format on
10261029

10271030
/// 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
@@ -6116,6 +6116,9 @@ Trigger processor to spill data into external storage adpatively. grace join is
61166116
/** Experimental tsToGrid aggregate function. */ \
61176117
DECLARE(Bool, allow_experimental_ts_to_grid_aggregate_function, false, R"(
61186118
Experimental tsToGrid aggregate function for Prometheus-like timeseries resampling. Cloud only
6119+
)", EXPERIMENTAL) \
6120+
DECLARE(Bool, use_object_storage_list_objects_cache, false, R"(
6121+
Cache the list of objects returned by list objects calls in object storage
61196122
)", EXPERIMENTAL) \
61206123
\
61216124
/* ####################################################### */ \

src/Core/SettingsChangesHistory.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ const VersionToSettingsChangesMap & getSettingsChangesHistory()
6868
/// Note: please check if the key already exists to prevent duplicate entries.
6969
addSettingsChanges(settings_changes_history, "25.4",
7070
{
71+
// Altinity Antalya modifications atop of 25.2
72+
{"object_storage_cluster", "", "", "New setting"},
73+
{"object_storage_max_nodes", 0, 0, "New setting"},
74+
{"use_iceberg_metadata_files_cache", true, true, "New setting"},
75+
{"iceberg_timestamp_ms", 0, 0, "New setting."},
76+
{"iceberg_snapshot_id", 0, 0, "New setting."},
77+
{"use_object_storage_list_objects_cache", true, false, "New setting."},
7178
});
7279
addSettingsChanges(settings_changes_history, "25.3",
7380
{

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
@@ -274,6 +274,8 @@ class IObjectStorage
274274
#endif
275275

276276

277+
virtual bool supportsListObjectsCache() { return false; }
278+
277279
private:
278280
mutable std::mutex throttlers_mutex;
279281
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)