lib/{storage,mergeset}: cleanup: remove unused partSearch.indexBlockReuse

This commit is contained in:
Aliaksandr Valialkin 2020-05-14 14:02:52 +03:00
parent 4bc3d284fa
commit f442d81648
4 changed files with 15 additions and 57 deletions

View file

@ -256,9 +256,7 @@ func (idxbc *indexBlockCache) Get(k uint64) *indexBlock {
} }
// Put puts idxb under the key k into idxbc. // Put puts idxb under the key k into idxbc.
// func (idxbc *indexBlockCache) Put(k uint64, idxb *indexBlock) {
// Returns true if the idxb has been put into idxbc.
func (idxbc *indexBlockCache) Put(k uint64, idxb *indexBlock) bool {
idxbc.mu.Lock() idxbc.mu.Lock()
// Remove superflouos entries. // Remove superflouos entries.
@ -283,7 +281,6 @@ func (idxbc *indexBlockCache) Put(k uint64, idxb *indexBlock) bool {
} }
idxbc.m[k] = idxbe idxbc.m[k] = idxbe
idxbc.mu.Unlock() idxbc.mu.Unlock()
return true
} }
func (idxbc *indexBlockCache) Len() uint64 { func (idxbc *indexBlockCache) Len() uint64 {
@ -407,9 +404,7 @@ func (ibc *inmemoryBlockCache) Get(k inmemoryBlockCacheKey) *inmemoryBlock {
} }
// Put puts ib under key k into ibc. // Put puts ib under key k into ibc.
// func (ibc *inmemoryBlockCache) Put(k inmemoryBlockCacheKey, ib *inmemoryBlock) {
// Returns true if ib was put into ibc.
func (ibc *inmemoryBlockCache) Put(k inmemoryBlockCacheKey, ib *inmemoryBlock) bool {
ibc.mu.Lock() ibc.mu.Lock()
// Clean superflouos entries in cache. // Clean superflouos entries in cache.
@ -434,7 +429,6 @@ func (ibc *inmemoryBlockCache) Put(k inmemoryBlockCacheKey, ib *inmemoryBlock) b
} }
ibc.m[k] = ibe ibc.m[k] = ibe
ibc.mu.Unlock() ibc.mu.Unlock()
return true
} }
func (ibc *inmemoryBlockCache) Len() uint64 { func (ibc *inmemoryBlockCache) Len() uint64 {

View file

@ -25,9 +25,6 @@ type partSearch struct {
// The remaining block headers to scan in the current metaindexRow. // The remaining block headers to scan in the current metaindexRow.
bhs []blockHeader bhs []blockHeader
// Pointer to index block, which may be reused.
indexBlockReuse *indexBlock
// Pointer to inmemory block, which may be reused. // Pointer to inmemory block, which may be reused.
inmemoryBlockReuse *inmemoryBlock inmemoryBlockReuse *inmemoryBlock
@ -53,10 +50,6 @@ func (ps *partSearch) reset() {
ps.p = nil ps.p = nil
ps.mrs = nil ps.mrs = nil
ps.bhs = nil ps.bhs = nil
if ps.indexBlockReuse != nil {
putIndexBlock(ps.indexBlockReuse)
ps.indexBlockReuse = nil
}
if ps.inmemoryBlockReuse != nil { if ps.inmemoryBlockReuse != nil {
putInmemoryBlock(ps.inmemoryBlockReuse) putInmemoryBlock(ps.inmemoryBlockReuse)
ps.inmemoryBlockReuse = nil ps.inmemoryBlockReuse = nil
@ -275,40 +268,25 @@ func (ps *partSearch) nextBlock() error {
} }
func (ps *partSearch) nextBHS() error { func (ps *partSearch) nextBHS() error {
if ps.indexBlockReuse != nil {
putIndexBlock(ps.indexBlockReuse)
ps.indexBlockReuse = nil
}
if len(ps.mrs) == 0 { if len(ps.mrs) == 0 {
return io.EOF return io.EOF
} }
mr := &ps.mrs[0] mr := &ps.mrs[0]
ps.mrs = ps.mrs[1:] ps.mrs = ps.mrs[1:]
idxb, mayReuseIndexBlock, err := ps.getIndexBlock(mr) idxbKey := mr.indexBlockOffset
idxb := ps.idxbCache.Get(idxbKey)
if idxb == nil {
var err error
idxb, err = ps.readIndexBlock(mr)
if err != nil { if err != nil {
return fmt.Errorf("cannot get index block: %s", err) return fmt.Errorf("cannot read index block: %s", err)
} }
if mayReuseIndexBlock { ps.idxbCache.Put(idxbKey, idxb)
ps.indexBlockReuse = idxb
} }
ps.bhs = idxb.bhs ps.bhs = idxb.bhs
return nil return nil
} }
func (ps *partSearch) getIndexBlock(mr *metaindexRow) (*indexBlock, bool, error) {
idxbKey := mr.indexBlockOffset
idxb := ps.idxbCache.Get(idxbKey)
if idxb != nil {
return idxb, false, nil
}
idxb, err := ps.readIndexBlock(mr)
if err != nil {
return nil, false, err
}
ok := ps.idxbCache.Put(idxbKey, idxb)
return idxb, !ok, nil
}
func (ps *partSearch) readIndexBlock(mr *metaindexRow) (*indexBlock, error) { func (ps *partSearch) readIndexBlock(mr *metaindexRow) (*indexBlock, error) {
ps.compressedIndexBuf = bytesutil.Resize(ps.compressedIndexBuf, int(mr.indexBlockSize)) ps.compressedIndexBuf = bytesutil.Resize(ps.compressedIndexBuf, int(mr.indexBlockSize))
ps.p.indexFile.MustReadAt(ps.compressedIndexBuf, int64(mr.indexBlockOffset)) ps.p.indexFile.MustReadAt(ps.compressedIndexBuf, int64(mr.indexBlockOffset))
@ -347,8 +325,8 @@ func (ps *partSearch) getInmemoryBlock(bh *blockHeader) (*inmemoryBlock, bool, e
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }
ok := ps.ibCache.Put(ibKey, ib) ps.ibCache.Put(ibKey, ib)
return ib, !ok, nil return ib, false, nil
} }
func (ps *partSearch) readInmemoryBlock(bh *blockHeader) (*inmemoryBlock, error) { func (ps *partSearch) readInmemoryBlock(bh *blockHeader) (*inmemoryBlock, error) {

View file

@ -257,7 +257,7 @@ func (ibc *indexBlockCache) Get(k uint64) *indexBlock {
return nil return nil
} }
func (ibc *indexBlockCache) Put(k uint64, ib *indexBlock) bool { func (ibc *indexBlockCache) Put(k uint64, ib *indexBlock) {
ibc.mu.Lock() ibc.mu.Lock()
// Clean superflouos cache entries. // Clean superflouos cache entries.
@ -281,7 +281,6 @@ func (ibc *indexBlockCache) Put(k uint64, ib *indexBlock) bool {
} }
ibc.m[k] = ibe ibc.m[k] = ibe
ibc.mu.Unlock() ibc.mu.Unlock()
return true
} }
func (ibc *indexBlockCache) Requests() uint64 { func (ibc *indexBlockCache) Requests() uint64 {

View file

@ -36,9 +36,6 @@ type partSearch struct {
bhs []blockHeader bhs []blockHeader
// Pointer to index block, which may be reused
indexBlockReuse *indexBlock
compressedIndexBuf []byte compressedIndexBuf []byte
indexBuf []byte indexBuf []byte
@ -53,10 +50,6 @@ func (ps *partSearch) reset() {
ps.metaindex = nil ps.metaindex = nil
ps.ibCache = nil ps.ibCache = nil
ps.bhs = nil ps.bhs = nil
if ps.indexBlockReuse != nil {
putIndexBlock(ps.indexBlockReuse)
ps.indexBlockReuse = nil
}
ps.compressedIndexBuf = ps.compressedIndexBuf[:0] ps.compressedIndexBuf = ps.compressedIndexBuf[:0]
ps.indexBuf = ps.indexBuf[:0] ps.indexBuf = ps.indexBuf[:0]
ps.err = nil ps.err = nil
@ -161,10 +154,6 @@ func (ps *partSearch) nextBHS() bool {
// Found the index block which may contain the required data // Found the index block which may contain the required data
// for the ps.BlockRef.bh.TSID and the given timestamp range. // for the ps.BlockRef.bh.TSID and the given timestamp range.
if ps.indexBlockReuse != nil {
putIndexBlock(ps.indexBlockReuse)
ps.indexBlockReuse = nil
}
indexBlockKey := mr.IndexBlockOffset indexBlockKey := mr.IndexBlockOffset
ib := ps.ibCache.Get(indexBlockKey) ib := ps.ibCache.Get(indexBlockKey)
if ib == nil { if ib == nil {
@ -176,9 +165,7 @@ func (ps *partSearch) nextBHS() bool {
&ps.p.ph, mr.IndexBlockOffset, mr.IndexBlockSize, err) &ps.p.ph, mr.IndexBlockOffset, mr.IndexBlockSize, err)
return false return false
} }
if ok := ps.ibCache.Put(indexBlockKey, ib); !ok { ps.ibCache.Put(indexBlockKey, ib)
ps.indexBlockReuse = ib
}
} }
ps.bhs = ib.bhs ps.bhs = ib.bhs
return true return true