mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
optimized code (#2103)
* optimized code ,because only the first error,so no need var errors []error * optimized code ,because only the first error,so no need var errors []error Co-authored-by: lirenzuo <lirenzuo@shein.com>
This commit is contained in:
parent
97947c5fcf
commit
1999bbfe82
4 changed files with 11 additions and 28 deletions
|
@ -89,24 +89,20 @@ func (ts *TableSearch) Seek(k []byte) {
|
|||
ts.err = nil
|
||||
|
||||
// Initialize the psHeap.
|
||||
var errors []error
|
||||
ts.psHeap = ts.psHeap[:0]
|
||||
for i := range ts.psPool {
|
||||
ps := &ts.psPool[i]
|
||||
ps.Seek(k)
|
||||
if !ps.NextItem() {
|
||||
if err := ps.Error(); err != nil {
|
||||
errors = append(errors, err)
|
||||
// Return only the first error, since it has no sense in returning all errors.
|
||||
ts.err = fmt.Errorf("cannot seek %q: %w", k, err)
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
ts.psHeap = append(ts.psHeap, ps)
|
||||
}
|
||||
if len(errors) > 0 {
|
||||
// Return only the first error, since it has no sense in returning all errors.
|
||||
ts.err = fmt.Errorf("cannot seek %q: %w", k, errors[0])
|
||||
return
|
||||
}
|
||||
if len(ts.psHeap) == 0 {
|
||||
ts.err = io.EOF
|
||||
return
|
||||
|
|
|
@ -92,23 +92,19 @@ func (pts *partitionSearch) Init(pt *partition, tsids []TSID, tr TimeRange) {
|
|||
}
|
||||
|
||||
// Initialize the psHeap.
|
||||
var errors []error
|
||||
pts.psHeap = pts.psHeap[:0]
|
||||
for i := range pts.psPool {
|
||||
ps := &pts.psPool[i]
|
||||
if !ps.NextBlock() {
|
||||
if err := ps.Error(); err != nil {
|
||||
errors = append(errors, err)
|
||||
// Return only the first error, since it has no sense in returning all errors.
|
||||
pts.err = fmt.Errorf("cannot initialize partition search: %w", err)
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
pts.psHeap = append(pts.psHeap, ps)
|
||||
}
|
||||
if len(errors) > 0 {
|
||||
// Return only the first error, since it has no sense in returning all errors.
|
||||
pts.err = fmt.Errorf("cannot initialize partition search: %w", errors[0])
|
||||
return
|
||||
}
|
||||
if len(pts.psHeap) == 0 {
|
||||
pts.err = io.EOF
|
||||
return
|
||||
|
|
|
@ -338,7 +338,6 @@ func (tb *table) AddRows(rows []rawRow) error {
|
|||
// Do this under tb.ptwsLock.
|
||||
minTimestamp, maxTimestamp := tb.getMinMaxTimestamps()
|
||||
tb.ptwsLock.Lock()
|
||||
var errors []error
|
||||
for i := range missingRows {
|
||||
r := &missingRows[i]
|
||||
|
||||
|
@ -362,18 +361,14 @@ func (tb *table) AddRows(rows []rawRow) error {
|
|||
|
||||
pt, err := createPartition(r.Timestamp, tb.smallPartitionsPath, tb.bigPartitionsPath, tb.getDeletedMetricIDs, tb.retentionMsecs)
|
||||
if err != nil {
|
||||
errors = append(errors, err)
|
||||
continue
|
||||
// Return only the first error, since it has no sense in returning all errors.
|
||||
return fmt.Errorf("errors while adding rows to table %q: %w", tb.path, err)
|
||||
}
|
||||
pt.AddRows(missingRows[i : i+1])
|
||||
tb.addPartitionNolock(pt)
|
||||
}
|
||||
tb.ptwsLock.Unlock()
|
||||
|
||||
if len(errors) > 0 {
|
||||
// Return only the first error, since it has no sense in returning all errors.
|
||||
return fmt.Errorf("errors while adding rows to table %q: %w", tb.path, errors[0])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -93,23 +93,19 @@ func (ts *tableSearch) Init(tb *table, tsids []TSID, tr TimeRange) {
|
|||
}
|
||||
|
||||
// Initialize the ptsHeap.
|
||||
var errors []error
|
||||
ts.ptsHeap = ts.ptsHeap[:0]
|
||||
for i := range ts.ptsPool {
|
||||
pts := &ts.ptsPool[i]
|
||||
if !pts.NextBlock() {
|
||||
if err := pts.Error(); err != nil {
|
||||
errors = append(errors, err)
|
||||
// Return only the first error, since it has no sense in returning all errors.
|
||||
ts.err = fmt.Errorf("cannot initialize table search: %w", err)
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
ts.ptsHeap = append(ts.ptsHeap, pts)
|
||||
}
|
||||
if len(errors) > 0 {
|
||||
// Return only the first error, since it has no sense in returning all errors.
|
||||
ts.err = fmt.Errorf("cannot initialize table search: %w", errors[0])
|
||||
return
|
||||
}
|
||||
if len(ts.ptsHeap) == 0 {
|
||||
ts.err = io.EOF
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue