shotover / shotover-proxy

L7 data-layer proxy
https://docs.shotover.io
Apache License 2.0
84 stars 16 forks source link

KafkaSinkCluster - evict items from stored metadata when removed from cluster #1661

Open rukai opened 3 months ago

rukai commented 3 months ago

We need a way to remove dead items from the cluster state.

This includes KafkaSinkCluster::topic_by_name, KafkaSinkCluster::topic_by_id and KafkaSinkCluster::group_to_coordinator_broker.

Some possible ways to achieve this:

  1. Store a last updated timestamp for each item and then evict if not updated for more than X hours.
  2. Store a last used timestamp for each item and then evict if not used for more than X hours.
  3. run a background task every X hours:
    • fetch a clean set of metadata
    • iterate over existing metadata deleting any that doesnt exist in the fetched metadata.
  4. run a background task every X hours that just completely clears metadata.
  5. clear collection if collection exceeds N items BEFORE adding a new item.
  6. remove a random item from the collection if collection exceeds N items BEFORE adding a new item.

I think 6 is the best option:

The downsides are:

Having looked at the way topics/partitions end up being used in production, this approach is a bit naive. The limit will need to be enforced on the number of partitions not the number of topics, since number of topics tends to actually be quite low. But then its not clear which topic to evict. Should we prefer evicting topics with lots of partitions? Should we be evicting at the partition level instead of the topic level? no, because: partitions are already evicted automatically when new metadata is fetched for that topic. So we just need to delete old topics.

Maybe option 2 would be better after all.

reducing memory usage

Its also worth thinking about ways to reduce memory usage in the first place: