ClickHouse/ClickHouse

`dictEvict` or `dictExpire` command for cached dictionaries.

Ouverte

#41 007 ouverte le 5 sept. 2022

 (4 commentaires) (4 réactions) (0 personne assignée)C++ (8 400 forks)batch import
comp-dictionaryfeaturehelp wantedminor

Métriques du dépôt

Stars
 (47 419 étoiles)
Métriques de merge PR
 (Merge moyen 2j 2h) (1 000 PRs mergées en 30 j)

Description

Use case

We have a moderately sized reference dataset that we reference in Clickhouse queries, that fits comfortably in memory. A small portion of the dataset is updated every second.

We have a stream of change data capture data with the keys that are updated that's processed by our ingestion service (a Kafka consumer application, not part of Clickhouse).

We would like to be able to create a dictionary with LAYOUT(CACHE) and a very long TTL, and evict or expire keys manually based on the stream of changes we receive. This would allow most keys, which are not getting updated, to remain in memory, but also allow the keys that have been modified to be reloaded, while keeping the dictionary updates to a minimum.

Describe the solution you'd like

A dictExpire('dict_name', id_expr) function that expires or evicts the key that's passed as argument. This would allow our process to invalidate the cache keys it has just updated.

For our use case we don't need the eviction to take effect immediately after the statement, as long as we can configure the upper bound for the eviction to take place. In that scenario dictExpire conveys the idea that the key might be removed asynchronously, if the eviction were to by synchronous, then dictEvict would be a better name I think.

Describe alternatives you've considered

We've tried several dictionary backends with LAYOUT(DIRECT) but the in memory cache is incredibly fast and nothing even gets close. For our solution we need the in-memory cache.

We looked at memory tables but it's not optimized for key value lookup.

Guide contributeur