lib/mergeset: follow-up after a0e7432e42 (#3145)

* lib/mergeset: follow-up after a0e7432e42

Signed-off-by: hagen1778 <roman@victoriametrics.com>

* Apply suggestions from code review

Signed-off-by: hagen1778 <roman@victoriametrics.com>
Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
This commit is contained in:
Roman Khavronenko 2022-09-26 15:39:56 +02:00 committed by Aliaksandr Valialkin
parent 83a4865a45
commit d503ba0c42
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 6 additions and 3 deletions

View file

@ -26,6 +26,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix `RangeError: Maximum call stack size exceeded` error when the query returns too many data points at `Table` view. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3092/files). * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix `RangeError: Maximum call stack size exceeded` error when the query returns too many data points at `Table` view. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3092/files).
* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert.html): re-evaluate annotations per each alert evaluation. Previously, annotations were evaluated only on alert's value ch * BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert.html): re-evaluate annotations per each alert evaluation. Previously, annotations were evaluated only on alert's value ch
ange. This could result in stale annotations in some cases described in [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3119). ange. This could result in stale annotations in some cases described in [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3119).
* BUGFIX: prevent from excessive CPU usage when the storage enters [read-only mode](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#readonly-mode). The previous fix in [v1.79.3](https://docs.victoriametrics.com/CHANGELOG.html#v1793) wasn't complete.
## [v1.79.3](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.79.3) ## [v1.79.3](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.79.3)

View file

@ -710,7 +710,7 @@ func (tb *Table) mergeRawItemsBlocks(ibs []*inmemoryBlock, isFinal bool) {
atomic.AddUint64(&tb.assistedMerges, 1) atomic.AddUint64(&tb.assistedMerges, 1)
continue continue
} }
if errors.Is(err, errNothingToMerge) || errors.Is(err, errForciblyStopped) { if errors.Is(err, errNothingToMerge) || errors.Is(err, errForciblyStopped) || errors.Is(err, errReadOnlyMode) {
return return
} }
logger.Panicf("FATAL: cannot merge small parts: %s", err) logger.Panicf("FATAL: cannot merge small parts: %s", err)
@ -805,12 +805,14 @@ func (tb *Table) canBackgroundMerge() bool {
return atomic.LoadUint32(tb.isReadOnly) == 0 return atomic.LoadUint32(tb.isReadOnly) == 0
} }
var errReadOnlyMode = fmt.Errorf("storage is in readonly mode")
func (tb *Table) mergeExistingParts(isFinal bool) error { func (tb *Table) mergeExistingParts(isFinal bool) error {
if !tb.canBackgroundMerge() { if !tb.canBackgroundMerge() {
// Do not perform background merge in read-only mode // Do not perform background merge in read-only mode
// in order to prevent from disk space shortage. // in order to prevent from disk space shortage.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2603 // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2603
return nil return errReadOnlyMode
} }
n := fs.MustGetFreeSpace(tb.path) n := fs.MustGetFreeSpace(tb.path)
// Divide free space by the max number of concurrent merges. // Divide free space by the max number of concurrent merges.
@ -849,7 +851,7 @@ func (tb *Table) partMerger() error {
// The merger has been stopped. // The merger has been stopped.
return nil return nil
} }
if !errors.Is(err, errNothingToMerge) { if !errors.Is(err, errNothingToMerge) && !errors.Is(err, errReadOnlyMode) {
return err return err
} }
if fasttime.UnixTimestamp()-lastMergeTime > 30 { if fasttime.UnixTimestamp()-lastMergeTime > 30 {