mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
tsdb/index.Symbols: Drop context argument from Lookup method (#13058)
Drop context argument from tsdb/index.Symbols.Lookup since lookup should be fast and the context checking is a performance hit. Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
252c7ca939
commit
ae9221e152
|
@ -923,7 +923,7 @@ func (w *Writer) writePostingsToTmpFiles() error {
|
||||||
// Symbol numbers are in order, so the strings will also be in order.
|
// Symbol numbers are in order, so the strings will also be in order.
|
||||||
slices.Sort(values)
|
slices.Sort(values)
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
value, err := w.symbols.Lookup(w.ctx, v)
|
value, err := w.symbols.Lookup(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1295,7 +1295,7 @@ func NewSymbols(bs ByteSlice, version, off int) (*Symbols, error) {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Symbols) Lookup(ctx context.Context, o uint32) (string, error) {
|
func (s Symbols) Lookup(o uint32) (string, error) {
|
||||||
d := encoding.Decbuf{
|
d := encoding.Decbuf{
|
||||||
B: s.bs.Range(0, s.bs.Len()),
|
B: s.bs.Range(0, s.bs.Len()),
|
||||||
}
|
}
|
||||||
|
@ -1307,9 +1307,6 @@ func (s Symbols) Lookup(ctx context.Context, o uint32) (string, error) {
|
||||||
d.Skip(s.offsets[int(o/symbolFactor)])
|
d.Skip(s.offsets[int(o/symbolFactor)])
|
||||||
// Walk until we find the one we want.
|
// Walk until we find the one we want.
|
||||||
for i := o - (o / symbolFactor * symbolFactor); i > 0; i-- {
|
for i := o - (o / symbolFactor * symbolFactor); i > 0; i-- {
|
||||||
if ctx.Err() != nil {
|
|
||||||
return "", ctx.Err()
|
|
||||||
}
|
|
||||||
d.UvarintBytes()
|
d.UvarintBytes()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1441,7 +1438,7 @@ func (r *Reader) lookupSymbol(ctx context.Context, o uint32) (string, error) {
|
||||||
if s, ok := r.nameSymbols[o]; ok {
|
if s, ok := r.nameSymbols[o]; ok {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
return r.symbols.Lookup(ctx, o)
|
return r.symbols.Lookup(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Symbols returns an iterator over the symbols that exist within the index.
|
// Symbols returns an iterator over the symbols that exist within the index.
|
||||||
|
|
|
@ -519,7 +519,6 @@ func TestNewFileReaderErrorNoOpenFiles(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSymbols(t *testing.T) {
|
func TestSymbols(t *testing.T) {
|
||||||
ctx := context.Background()
|
|
||||||
buf := encoding.Encbuf{}
|
buf := encoding.Encbuf{}
|
||||||
|
|
||||||
// Add prefix to the buffer to simulate symbols as part of larger buffer.
|
// Add prefix to the buffer to simulate symbols as part of larger buffer.
|
||||||
|
@ -542,11 +541,11 @@ func TestSymbols(t *testing.T) {
|
||||||
require.Equal(t, 32, s.Size())
|
require.Equal(t, 32, s.Size())
|
||||||
|
|
||||||
for i := 99; i >= 0; i-- {
|
for i := 99; i >= 0; i-- {
|
||||||
s, err := s.Lookup(ctx, uint32(i))
|
s, err := s.Lookup(uint32(i))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, string(rune(i)), s)
|
require.Equal(t, string(rune(i)), s)
|
||||||
}
|
}
|
||||||
_, err = s.Lookup(ctx, 100)
|
_, err = s.Lookup(100)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
for i := 99; i >= 0; i-- {
|
for i := 99; i >= 0; i-- {
|
||||||
|
|
Loading…
Reference in a new issue