Compare commits

...

1 Commits

Author SHA1 Message Date
f41gh7
6768a34858 lib/storage: properly load metric_usage_tracker file content
Previously, if metric_usage_tracker file was corrupted. It prevented
VictoriaMetrics from start and required manual action. Corruption may happen in various reasons,
such as unclean shutdown of the process.

 This commit changes panic into error message, in the same way as other
caches do.

Related issue:
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9074
2025-06-05 13:33:07 +02:00
2 changed files with 16 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ See also [LTS releases](https://docs.victoriametrics.com/victoriametrics/lts-rel
* BUGFIX: [vmalert-tool](https://docs.victoriametrics.com/victoriametrics/vmalert-tool/): fix access conflicts for the temporary test folder when multiple users run tests on the same host. Thanks to @evkuzin for the [pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/9015).
* BUGFIX: [alerts](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/rules): fix the alerting rule `ScrapePoolHasNoTargets`. Previously, it may cause false positive in [sharding mode](https://docs.victoriametrics.com/victoriametrics/vmagent/#scraping-big-number-of-targets).
* BUGFIX: [vmgateway](https://docs.victoriametrics.com/victoriametrics/vmgateway/): add missing vmselect `vmui` related routes to the authorized requests routing. See [9003](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9003) issue for details.
* BUGFIX: [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/victoriametrics/cluster-victoriametrics/): properly load [metric names stats tracker](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#track-ingested-metrics-usage) state from disk. Now it ignores corrupted `metric_usage_tracker` file content and init tracker with empty state in the same way as other caches loaded. See [9074](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9074) issue for details.
* BUGFIX: [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): fixed a regression in downsampling logic introduced in [#7440](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7440) and released in [v1.106.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.106.0), where downsampling rules with filters `filter:offset:interval` could be incorrectly skipped in favor of unfiltered rules `offset:interval`. See [#8969](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8969).
* BUGFIX: [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/) and `vmselect` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): prevent panic caused by invalid label name in metric relabeling debugging interface. Error is now properly propagated and displayed in the interface. See [#8661](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8661).
* BUGFIX: [vmsingle](https://docs.victoriametrics.com/single-server-victoriametrics/) and `vmstorage` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/victoriametrics/cluster-victoriametrics/): properly apply `rententionFilter` on flag value changes. Previously, it ignored any `filter` value changes for historical data. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8885) for details.

View File

@@ -75,18 +75,16 @@ type recordForStore struct {
func MustLoadFrom(loadPath string, maxSizeBytes uint64) *Tracker {
mt, err := loadFrom(loadPath, maxSizeBytes)
if err != nil {
logger.Fatalf("unexpected error at tracker state load from path=%q: %s", loadPath, err)
// just log error in case of any error and return empty object as other caches do
logger.Errorf("metric names stats tracker file at path %s is invalid: %s; init new metric names stats tracker", loadPath, err)
return newTracker(loadPath, maxSizeBytes)
}
return mt
}
func loadFrom(loadPath string, maxSizeBytes uint64) (*Tracker, error) {
mt := &Tracker{
maxSizeBytes: maxSizeBytes,
cachePath: loadPath,
getCurrentTs: fasttime.UnixTimestamp,
}
mt.initEmpty()
mt := newTracker(loadPath, maxSizeBytes)
f, err := os.Open(loadPath)
if err != nil && !errors.Is(err, os.ErrNotExist) {
@@ -309,6 +307,16 @@ func (mt *Tracker) initEmpty() {
mt.creationTs.Store(mt.getCurrentTs())
}
func newTracker(loadPath string, maxSizeBytes uint64) *Tracker {
mt := &Tracker{
maxSizeBytes: maxSizeBytes,
cachePath: loadPath,
getCurrentTs: fasttime.UnixTimestamp,
}
mt.initEmpty()
return mt
}
// RegisterIngestRequest tracks metric name ingestion
func (mt *Tracker) RegisterIngestRequest(accountID, projectID uint32, metricName []byte) {
if mt == nil {