@@ -77,8 +77,8 @@ type Options struct {
7777 Compression options.CompressionType
7878
7979 // Block cache is used to cache decompressed and decrypted blocks.
80- BlockCache * ristretto.Cache
81- IndexCache * ristretto.Cache
80+ BlockCache * ristretto.Cache [[] byte , * Block ]
81+ IndexCache * ristretto.Cache [ uint64 , * fb. TableIndex ]
8282
8383 AllocPool * z.AllocatorPool
8484
@@ -178,13 +178,11 @@ func (t *Table) DecrRef() error {
178178}
179179
180180// BlockEvictHandler is used to reuse the byte slice stored in the block on cache eviction.
181- func BlockEvictHandler (value interface {}) {
182- if b , ok := value .(* block ); ok {
183- b .decrRef ()
184- }
181+ func BlockEvictHandler (b * Block ) {
182+ b .decrRef ()
185183}
186184
187- type block struct {
185+ type Block struct {
188186 offset int
189187 data []byte
190188 checksum []byte
@@ -199,7 +197,7 @@ var NumBlocks atomic.Int32
199197
200198// incrRef increments the ref of a block and return a bool indicating if the
201199// increment was successful. A true value indicates that the block can be used.
202- func (b * block ) incrRef () bool {
200+ func (b * Block ) incrRef () bool {
203201 for {
204202 // We can't blindly add 1 to ref. We need to check whether it has
205203 // reached zero first, because if it did, then we should absolutely not
@@ -222,7 +220,7 @@ func (b *block) incrRef() bool {
222220 }
223221 }
224222}
225- func (b * block ) decrRef () {
223+ func (b * Block ) decrRef () {
226224 if b == nil {
227225 return
228226 }
@@ -242,12 +240,12 @@ func (b *block) decrRef() {
242240 }
243241 y .AssertTrue (b .ref .Load () >= 0 )
244242}
245- func (b * block ) size () int64 {
243+ func (b * Block ) size () int64 {
246244 return int64 (3 * intSize /* Size of the offset, entriesIndexStart and chkLen */ +
247245 cap (b .data ) + cap (b .checksum ) + cap (b .entryOffsets )* 4 )
248246}
249247
250- func (b * block ) verifyCheckSum () error {
248+ func (b * Block ) verifyCheckSum () error {
251249 cs := & pb.Checksum {}
252250 if err := proto .Unmarshal (b .checksum , cs ); err != nil {
253251 return y .Wrapf (err , "unable to unmarshal checksum for block" )
@@ -521,7 +519,7 @@ func (t *Table) fetchIndex() *fb.TableIndex {
521519 panic ("Index Cache must be set for encrypted workloads" )
522520 }
523521 if val , ok := t .opt .IndexCache .Get (t .indexKey ()); ok && val != nil {
524- return val .( * fb. TableIndex )
522+ return val
525523 }
526524
527525 index , err := t .readTableIndex ()
@@ -537,7 +535,7 @@ func (t *Table) offsets(ko *fb.BlockOffset, i int) bool {
537535// block function return a new block. Each block holds a ref and the byte
538536// slice stored in the block will be reused when the ref becomes zero. The
539537// caller should release the block by calling block.decrRef() on it.
540- func (t * Table ) block (idx int , useCache bool ) (* block , error ) {
538+ func (t * Table ) block (idx int , useCache bool ) (* Block , error ) {
541539 y .AssertTruef (idx >= 0 , "idx=%d" , idx )
542540 if idx >= t .offsetsLength () {
543541 return nil , errors .New ("block out of index" )
@@ -549,15 +547,15 @@ func (t *Table) block(idx int, useCache bool) (*block, error) {
549547 // Use the block only if the increment was successful. The block
550548 // could get evicted from the cache between the Get() call and the
551549 // incrRef() call.
552- if b := blk .( * block ); b .incrRef () {
553- return b , nil
550+ if blk .incrRef () {
551+ return blk , nil
554552 }
555553 }
556554 }
557555
558556 var ko fb.BlockOffset
559557 y .AssertTrue (t .offsets (& ko , idx ))
560- blk := & block {offset : int (ko .Offset ())}
558+ blk := & Block {offset : int (ko .Offset ())}
561559 blk .ref .Store (1 )
562560 defer blk .decrRef () // Deal with any errors, where blk would not be returned.
563561 NumBlocks .Add (1 )
@@ -795,7 +793,7 @@ func NewFilename(id uint64, dir string) string {
795793}
796794
797795// decompress decompresses the data stored in a block.
798- func (t * Table ) decompress (b * block ) error {
796+ func (t * Table ) decompress (b * Block ) error {
799797 var dst []byte
800798 var err error
801799
0 commit comments