VictoriaMetrics/app/vmselect/graphite
Aliaksandr Valialkin 7094fa38bc
lib/storage: switch from global to per-day index for MetricName -> TSID mapping
Previously all the newly ingested time series were registered in global `MetricName -> TSID` index.
This index was used during data ingestion for locating the TSID (internal series id)
for the given canonical metric name (the canonical metric name consists of metric name plus all its labels sorted by label names).

The `MetricName -> TSID` index is stored on disk in order to make sure that the data
isn't lost on VictoriaMetrics restart or unclean shutdown.

The lookup in this index is relatively slow, since VictoriaMetrics needs to read the corresponding
data block from disk, unpack it, put the unpacked block into `indexdb/dataBlocks` cache,
and then search for the given `MetricName -> TSID` entry there. So VictoriaMetrics
uses in-memory cache for speeding up the lookup for active time series.
This cache is named `storage/tsid`. If this cache capacity is enough for all the currently ingested
active time series, then VictoriaMetrics works fast, since it doesn't need to read the data from disk.

VictoriaMetrics starts reading data from `MetricName -> TSID` on-disk index in the following cases:

- If `storage/tsid` cache capacity isn't enough for active time series.
  Then just increase available memory for VictoriaMetrics or reduce the number of active time series
  ingested into VictoriaMetrics.

- If new time series is ingested into VictoriaMetrics. In this case it cannot find
  the needed entry in the `storage/tsid` cache, so it needs to consult on-disk `MetricName -> TSID` index,
  since it doesn't know that the index has no the corresponding entry too.
  This is a typical event under high churn rate, when old time series are constantly substituted
  with new time series.

Reading the data from `MetricName -> TSID` index is slow, so inserts, which lead to reading this index,
are counted as slow inserts, and they can be monitored via `vm_slow_row_inserts_total` metric exposed by VictoriaMetrics.

Prior to this commit the `MetricName -> TSID` index was global, e.g. it contained entries sorted by `MetricName`
for all the time series ever ingested into VictoriaMetrics during the configured -retentionPeriod.
This index can become very large under high churn rate and long retention. VictoriaMetrics
caches data from this index in `indexdb/dataBlocks` in-memory cache for speeding up index lookups.
The `indexdb/dataBlocks` cache may occupy significant share of available memory for storing
recently accessed blocks at `MetricName -> TSID` index when searching for newly ingested time series.

This commit switches from global `MetricName -> TSID` index to per-day index. This allows significantly
reducing the amounts of data, which needs to be cached in `indexdb/dataBlocks`, since now VictoriaMetrics
consults only the index for the current day when new time series is ingested into it.

The downside of this change is increased indexdb size on disk for workloads without high churn rate,
e.g. with static time series, which do no change over time, since now VictoriaMetrics needs to store
identical `MetricName -> TSID` entries for static time series for every day.

This change removes an optimization for reducing CPU and disk IO spikes at indexdb rotation,
since it didn't work correctly - see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1401 .

At the same time the change fixes the issue, which could result in lost access to time series,
which stop receving new samples during the first hour after indexdb rotation - see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2698

The issue with the increased CPU and disk IO usage during indexdb rotation will be addressed
in a separate commit according to https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1401#issuecomment-1553488685

This is a follow-up for 1f28b46ae9
2023-07-13 16:07:30 -07:00
..
aggr.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
aggr_state.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
eval.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
eval_test.go app/vmselect/graphite: fixes tests for arm (#4348) 2023-05-26 09:34:15 +02:00
functions.json app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
functions_api.go app/vmselect: move common http functionality from app/vmselect/searchutils to lib/httputils 2023-06-19 22:34:20 -07:00
metrics_api.go app/vmselect: move common http functionality from app/vmselect/searchutils to lib/httputils 2023-06-19 22:34:20 -07:00
metrics_api_test.go app/vmselect,lib/storage: properly parse Graphite selectors with inner wildcards 2021-02-03 20:14:22 +02:00
metrics_expand_response.qtpl app/vmselect: initial implementation of Graphite Metrics API 2020-09-11 00:30:01 +03:00
metrics_expand_response.qtpl.go app/vmselect: initial implementation of Graphite Metrics API 2020-09-11 00:30:01 +03:00
metrics_find_response.qtpl app/vmselect/graphite: do not substitute path and path. with path.. in /metrics/find/?format=completer output 2020-09-29 18:03:26 +03:00
metrics_find_response.qtpl.go app/vmselect/graphite: do not substitute path and path. with path.. in /metrics/find/?format=completer output 2020-09-29 18:03:26 +03:00
metrics_index_response.qtpl app/vmselect: initial implementation of Graphite Metrics API 2020-09-11 00:30:01 +03:00
metrics_index_response.qtpl.go app/vmselect: initial implementation of Graphite Metrics API 2020-09-11 00:30:01 +03:00
natural_compare.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
natural_compare_test.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
render_api.go app/vmselect: move common http functionality from app/vmselect/searchutils to lib/httputils 2023-06-19 22:34:20 -07:00
render_api_test.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
render_response.qtpl app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
render_response.qtpl.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
tag_values_response.qtpl app/vmselect/graphite: add /tags/<tag_name> handler for Graphite Tags API 2020-11-16 03:42:25 +02:00
tag_values_response.qtpl.go app/vmselect/graphite: add /tags/<tag_name> handler for Graphite Tags API 2020-11-16 03:42:25 +02:00
tags_api.go lib/storage: switch from global to per-day index for MetricName -> TSID mapping 2023-07-13 16:07:30 -07:00
tags_autocomplete_response.qtpl app/vmselect/graphite: add /tags/autoComplete/values handler from Graphite Tags API 2020-11-16 15:29:35 +02:00
tags_autocomplete_response.qtpl.go app/vmselect/graphite: add /tags/autoComplete/values handler from Graphite Tags API 2020-11-16 15:29:35 +02:00
tags_find_series_response.qtpl app/vmselect/graphite: add /tags/findSeries handler from Graphite Tags API 2020-11-16 12:53:13 +02:00
tags_find_series_response.qtpl.go app/vmselect/graphite: add /tags/findSeries handler from Graphite Tags API 2020-11-16 12:53:13 +02:00
tags_response.qtpl app/vmselect/graphite: add /tags handler from Graphite Tags API 2020-11-16 03:00:01 +02:00
tags_response.qtpl.go app/vmselect/graphite: add /tags handler from Graphite Tags API 2020-11-16 03:00:01 +02:00
tags_tag_multi_series_response.qtpl app/{vminsert,vmselect}: move /tags/tagSeries and /tags/tagMultiSeries api from vminsert to vmselect 2020-11-23 12:33:19 +02:00
tags_tag_multi_series_response.qtpl.go app/{vminsert,vmselect}: move /tags/tagSeries and /tags/tagMultiSeries api from vminsert to vmselect 2020-11-23 12:33:19 +02:00
transform.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00
transform_test.go app/vmselect/graphite: open source Graphite Render API 2023-03-31 23:25:04 -07:00