VictoriaMetrics/app
Aliaksandr Valialkin e1cf962bad
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 17:03:50 -07:00
..
victoria-logs app/vlselect: handle vmui at /select/vmui path instead of /vmui 2023-07-06 21:36:28 -07:00
vlinsert app/vlselect: handle vmui at /select/vmui path instead of /vmui 2023-07-06 21:36:28 -07:00
vlselect app/{vmselect,vlselect}: run make vmui-update vmui-logs-update 2023-07-09 12:44:04 -07:00
vlstorage app/vlstorage: export vl_active_merges and vl_merges_total metrics 2023-07-06 21:38:09 -07:00
vmagent docs: make httpAuth.* flags description less ambiguous (#4588) 2023-07-09 12:36:14 -07:00
vmalert app/vmalert: silence golagci-lint at TestAlertingRule_Template 2023-07-13 12:16:00 -07:00
vmauth docs: make httpAuth.* flags description less ambiguous (#4588) 2023-07-09 12:36:14 -07:00
vmbackup docs: make httpAuth.* flags description less ambiguous (#4588) 2023-07-09 12:36:14 -07:00
vmbackupmanager docs: make httpAuth.* flags description less ambiguous (#4588) 2023-07-09 12:36:14 -07:00
vmctl app/vmctl: fix panic --remote-read-filter-time-start flag not defined (#4605) 2023-07-13 12:13:21 -07:00
vmgateway docs: make httpAuth.* flags description less ambiguous (#4588) 2023-07-09 12:36:14 -07:00
vminsert cluster: standardize default HTTP responses (#4368) 2023-06-01 10:26:52 +02:00
vmrestore docs: make httpAuth.* flags description less ambiguous (#4588) 2023-07-09 12:36:14 -07:00
vmselect app/{vmselect,vlselect}: run make vmui-update vmui-logs-update 2023-07-09 12:44:04 -07:00
vmstorage lib/storage: switch from global to per-day index for MetricName -> TSID mapping 2023-07-13 17:03:50 -07:00
vmui all: update Go builder from 1.20.5 to 1.20.6 2023-07-12 01:00:24 -07:00