From fe58462bef9f6c211a036fa1e4f9cf3ced4b9ad4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 6 Jul 2020 21:56:14 +0300 Subject: [PATCH] lib/storage: reset MetricName->TSID cache after deleting time series This should prevent from adding new data points to deleted time series without the need to check for the deleted time series. This improves ingestion performance a bit when the `deleted time series ids` aka `dmis` set contains big number of time series. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/596 Based on the idea from @n4mine at https://github.com/VictoriaMetrics/VictoriaMetrics/pull/604 --- lib/storage/storage.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index d13c093e3..3670b7ec9 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -942,12 +942,13 @@ func (s *Storage) DeleteMetrics(tfss []*TagFilters) (int, error) { if err != nil { return deletedCount, fmt.Errorf("cannot delete tsids: %w", err) } - // Do not reset MetricName -> TSID cache (tsidCache), since the obtained - // entries must be checked against deleted metricIDs. - // See Storage.add for details. - // + // Reset MetricName->TSID cache in order to prevent from adding new data points + // to deleted time series in Storage.add. + s.tsidCache.Reset() + // Do not reset MetricID -> MetricName cache, since it must be used only // after filtering out deleted metricIDs. + return deletedCount, nil } @@ -1127,7 +1128,6 @@ var ( func (s *Storage) add(rows []rawRow, mrs []MetricRow, precisionBits uint8) ([]rawRow, error) { idb := s.idb() - dmis := idb.getDeletedMetricIDs() rowsLen := len(rows) if n := rowsLen + len(mrs) - cap(rows); n > 0 { rows = append(rows[:cap(rows)], make([]rawRow, n)...) @@ -1179,7 +1179,7 @@ func (s *Storage) add(rows []rawRow, mrs []MetricRow, precisionBits uint8) ([]ra r.TSID = prevTSID continue } - if s.getTSIDFromCache(&r.TSID, mr.MetricNameRaw) && !dmis.Has(r.TSID.MetricID) { + if s.getTSIDFromCache(&r.TSID, mr.MetricNameRaw) { // Fast path - the TSID for the given MetricName has been found in cache and isn't deleted. prevTSID = r.TSID prevMetricNameRaw = mr.MetricNameRaw @@ -1225,7 +1225,7 @@ func (s *Storage) add(rows []rawRow, mrs []MetricRow, precisionBits uint8) ([]ra r.TSID = prevTSID continue } - if s.getTSIDFromCache(&r.TSID, mr.MetricNameRaw) && !dmis.Has(r.TSID.MetricID) { + if s.getTSIDFromCache(&r.TSID, mr.MetricNameRaw) { // Fast path - the TSID for the given MetricName has been found in cache and isn't deleted. prevTSID = r.TSID prevMetricNameRaw = mr.MetricNameRaw