refactor: add ReaderProvider to fetch registry from cache once per re… - #447
refactor: add ReaderProvider to fetch registry from cache once per re…#447forshev wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #447 +/- ##
==========================================
- Coverage 70.68% 70.52% -0.16%
==========================================
Files 233 234 +1
Lines 18399 18486 +87
==========================================
+ Hits 13005 13038 +33
- Misses 4416 4453 +37
- Partials 978 995 +17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@seqbenchbot up main search |
|
Oh-oh, @eguguchkin Something went wrong and I couldn't process your request. |
|
@seqbenchbot up main search-logbench |
|
Nice, @eguguchkin Your request was successfully served. Here is a list of helpful links: Have a great time! |
|
Nice, @eguguchkin The benchmark with identificator Show summary
Have a great time! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@seqbenchbot up main search-keyword-exact-match-warm |
|
Oh-oh, @eguguchkin Something went wrong and I couldn't process your request. |
|
@seqbenchbot up main search-keyword-exact-match-warm |
|
Nice, @eguguchkin Your request was successfully served. Here is a list of helpful links: Have a great time! |
|
@seqbenchbot down c98188f3 |
|
Nice, @eguguchkin The benchmark with identificator Show summary
Have a great time! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3827c8a to
bfab9ab
Compare
bfab9ab to
3ea793d
Compare
| } | ||
| } | ||
|
|
||
| func (r *ReaderProvider) GetReader() (IndexReader, error) { |
There was a problem hiding this comment.
nit: I think a more idiomatic name for this method would be just Reader?
| "github.com/ozontech/seq-db/cache" | ||
| ) | ||
|
|
||
| type ReaderProvider struct { |
There was a problem hiding this comment.
nit: Would it make sense to merge index_reader.go and index_provider.go into a single index_reader.go file?
| idReader = legacyReader | ||
| } else { | ||
| var err error | ||
| tokenReader, err = f.tokenReaderProvider.GetReader() |
There was a problem hiding this comment.
nit: This introduces a fair amount of error-handling boilerplate. What if we extracted this into a separate helper function?
func (f *Sealed) mustGetReader(p *storage.ReaderProvider) storage.IndexReader {
r, err := p.GetReader()
if err != nil {
logger.Fatal("error creating IndexReader", zap.String("fraction", f.BaseFileName), zap.Error(err))
}
return r
}We should also ensure that errors returned by provider include the filename to make it easier to pinpoint which specific index file caused the issue.
Something like this:
--- a/storage/reader_provider.go
+++ b/storage/reader_provider.go
@@ -48,10 +48,10 @@ func (r *ReaderProvider) readRegistry() ([]byte, error) {
n, err := r.limiter.ReadAt(r.reader, numBuf, 0)
if err != nil {
- return nil, fmt.Errorf("can't read disk registry, %s", err.Error())
+ return nil, fmt.Errorf("can't read disk registry from file %s: %w", r.readerName, err.Error())
}
if n == 0 {
- return nil, fmt.Errorf("can't read disk registry, n=0")
+ return nil, fmt.Errorf("can't read disk registry from file %s, n=0", r.readerName)
}
pos := binary.LittleEndian.Uint64(numBuf)
@@ -64,11 +64,11 @@ func (r *ReaderProvider) readRegistry() ([]byte, error) {
}
if uint64(n) != l {
- return nil, fmt.Errorf("can't read disk registry, read=%d, requested=%d", n, l)
+ return nil, fmt.Errorf("can't read disk registry, read=%d, requested=%d in file %s", n, l, r.readerName)
}
if len(buf)%IndexBlockHeaderSize != 0 {
- return nil, fmt.Errorf("wrong registry format")
+ return nil, fmt.Errorf("wrong registry format in file %s", r.readerName)
}
return buf, nilYes, having both the fraction name and the filename might be redundant since the filename already implies the fraction. However, I think we should aim for errors from fractions to always include a searchable fraction field to enable fast filtering in logs.
…quest
Description
add ReaderProvider struct that creates IndexReader for each request
Fixes #444
If you have used LLM/AI assistance please provide model name and full prompt: