Skip to content

Commit 2a80fbb

Browse files
Enmkarthurpassos
authored andcommitted
Merge pull request #805 from Altinity/list_objects_object_storage_cache_25.3
1 parent efd42b3 commit 2a80fbb

21 files changed

+778
-20
lines changed

programs/server/Server.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include <Storages/System/attachSystemTables.h>
8484
#include <Storages/System/attachInformationSchemaTables.h>
8585
#include <Storages/Cache/registerRemoteFileMetadatas.h>
86+
#include <Storages/Cache/ObjectStorageListObjectsCache.h>
8687
#include <AggregateFunctions/registerAggregateFunctions.h>
8788
#include <Functions/UserDefined/IUserDefinedSQLObjectsStorage.h>
8889
#include <Functions/registerFunctions.h>
@@ -331,6 +332,9 @@ namespace ServerSetting
331332
namespace ErrorCodes
332333
{
333334
extern const int STARTUP_SCRIPTS_ERROR;
335+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_size;
336+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_max_entries;
337+
extern const ServerSettingsUInt64 object_storage_list_objects_cache_ttl;
334338
}
335339

336340
}
@@ -2421,6 +2425,10 @@ try
24212425
if (dns_cache_updater)
24222426
dns_cache_updater->start();
24232427

2428+
ObjectStorageListObjectsCache::instance().setMaxSizeInBytes(server_settings[ServerSetting::object_storage_list_objects_cache_size]);
2429+
ObjectStorageListObjectsCache::instance().setMaxCount(server_settings[ServerSetting::object_storage_list_objects_cache_max_entries]);
2430+
ObjectStorageListObjectsCache::instance().setTTL(server_settings[ServerSetting::object_storage_list_objects_cache_ttl]);
2431+
24242432
auto replicas_reconnector = ReplicasReconnector::init(global_context);
24252433

24262434
/// 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
@@ -184,6 +184,7 @@ enum class AccessType : uint8_t
184184
M(SYSTEM_DROP_SCHEMA_CACHE, "SYSTEM DROP SCHEMA CACHE, DROP SCHEMA CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
185185
M(SYSTEM_DROP_FORMAT_SCHEMA_CACHE, "SYSTEM DROP FORMAT SCHEMA CACHE, DROP FORMAT SCHEMA CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
186186
M(SYSTEM_DROP_S3_CLIENT_CACHE, "SYSTEM DROP S3 CLIENT, DROP S3 CLIENT 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,10 @@ The server successfully detected this situation and will download merged part fr
10471047
M(IndexBinarySearchAlgorithm, "Number of times the binary search algorithm is used over the index marks", ValueType::Number) \
10481048
M(IndexGenericExclusionSearchAlgorithm, "Number of times the generic exclusion search algorithm is used over the index marks", ValueType::Number) \
10491049
M(ParallelReplicasQueryCount, "Number of (sub)queries executed using parallel replicas during a query execution", ValueType::Number) \
1050-
1050+
M(ObjectStorageListObjectsCacheHits, "Number of times object storage list objects operation hit the cache.", ValueType::Number) \
1051+
M(ObjectStorageListObjectsCacheMisses, "Number of times object storage list objects operation miss the cache.", ValueType::Number) \
1052+
M(ObjectStorageListObjectsCacheExactMatchHits, "Number of times object storage list objects operation hit the cache with an exact match.", ValueType::Number) \
1053+
M(ObjectStorageListObjectsCachePrefixMatchHits, "Number of times object storage list objects operation miss the cache using prefix matching.", ValueType::Number) \
10511054

10521055
#ifdef APPLY_FOR_EXTERNAL_EVENTS
10531056
#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
@@ -271,10 +271,10 @@ class TTLCachePolicy : public ICachePolicy<Key, Mapped, HashFunction, WeightFunc
271271
return res;
272272
}
273273

274-
private:
274+
protected:
275275
using Cache = std::unordered_map<Key, MappedPtr, HashFunction>;
276276
Cache cache;
277-
277+
private:
278278
/// TODO To speed up removal of stale entries, we could also add another container sorted on expiry times which maps keys to iterators
279279
/// 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
280280
/// binary search on the sorted container and erase all left of the found key.

src/Core/ServerSettings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,9 @@ The policy on how to perform a scheduling of CPU slots specified by `concurrent_
10641064
See [Controlling behavior on server CPU overload](/operations/settings/server-overload) for more details.
10651065
)", 0) \
10661066
DECLARE(Float, distributed_cache_keep_up_free_connections_ratio, 0.1f, "Soft limit for number of active connection distributed cache will try to keep free. After the number of free connections goes below distributed_cache_keep_up_free_connections_ratio * max_connections, connections with oldest activity will be closed until the number goes above the limit.", 0) \
1067-
1068-
1067+
DECLARE(UInt64, object_storage_list_objects_cache_size, 500000000, "Maximum size of ObjectStorage list objects cache in bytes. Zero means disabled.", 0) \
1068+
DECLARE(UInt64, object_storage_list_objects_cache_max_entries, 1000, "Maximum size of ObjectStorage list objects cache in entries. Zero means disabled.", 0) \
1069+
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)
10691070
// clang-format on
10701071

10711072
/// 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6842,8 +6842,16 @@ Run all tasks of a distributed query plan locally. Useful for testing and debugg
68426842
DECLARE(UInt64, distributed_plan_default_shuffle_join_bucket_count, 8, R"(
68436843
Default number of buckets for distributed shuffle-hash-join.
68446844
)", EXPERIMENTAL) \
6845+
<<<<<<< HEAD
68456846
DECLARE(UInt64, distributed_plan_default_reader_bucket_count, 8, R"(
68466847
Default number of tasks for parallel reading in distributed query. Tasks are spread across between replicas.
6848+
=======
6849+
DECLARE(Bool, use_object_storage_list_objects_cache, false, R"(
6850+
Cache the list of objects returned by list objects calls in object storage
6851+
)", EXPERIMENTAL) \
6852+
DECLARE(Bool, object_storage_remote_initiator, false, R"(
6853+
Execute request to object storage as remote on one of object_storage_cluster nodes.
6854+
>>>>>>> ff42c3a62bd (Merge pull request #805 from Altinity/list_objects_object_storage_cache_25.3)
68476855
)", EXPERIMENTAL) \
68486856
DECLARE(Bool, distributed_plan_optimize_exchanges, true, R"(
68496857
Removes unnecessary exchanges in distributed query plan. Disable it for debugging.

src/Core/SettingsChangesHistory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ const VersionToSettingsChangesMap & getSettingsChangesHistory()
162162
{"parallel_replicas_insert_select_local_pipeline", false, false, "Use local pipeline during distributed INSERT SELECT with parallel replicas. Currently disabled due to performance issues"},
163163
{"parallel_hash_join_threshold", 0, 0, "New setting"},
164164
/// Release closed. Please use 25.5
165+
// Altinity Antalya modifications atop of 25.2
166+
{"object_storage_cluster", "", "", "New setting"},
167+
{"object_storage_max_nodes", 0, 0, "New setting"},
168+
{"use_object_storage_list_objects_cache", true, false, "New setting."},
165169
});
166170
addSettingsChanges(settings_changes_history, "25.3",
167171
{

src/Disks/ObjectStorages/AzureBlobStorage/AzureObjectStorage.h

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

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

3739
/// Sanitizer build may crash with max_keys=1; this looks like a false positive.

src/Disks/ObjectStorages/IObjectStorage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ class IObjectStorage
300300
#endif
301301

302302

303+
virtual bool supportsListObjectsCache() { return false; }
304+
303305
private:
304306
mutable std::mutex throttlers_mutex;
305307
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)