Skip to content

Commit 28a5f11

Browse files
committed
blob: fix ValueFetcher value index lookup
Previously the ValueFetcher did not correctly translate the ValueID of a blob.Handle to the index of the value in the block if the blob file was rewritten. This commit fixes the bug. Unit tests covering this case will be added in future commits.
1 parent 6fcadae commit 28a5f11

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sstable/blob/fetcher.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,14 @@ func (cr *cachedReader) GetUnsafeValue(
291291
cr.currentValueBlock.loaded = true
292292
}
293293

294-
invariants.CheckBounds(int(valueID), cr.currentValueBlock.dec.bd.Rows())
295-
v := cr.currentValueBlock.dec.values.Slice(cr.currentValueBlock.dec.values.Offsets(int(valueID)))
294+
// Convert the ValueID to an index into the block's values. When a blob file
295+
// is first constructed, the ValueID == the index. However when a blob file
296+
// is rewritten, multiple blocks from the original blob file may be combined
297+
// into the same physical block. To translate the ValueID to the
298+
// apppropriate index, we need to add the 'virtual block' valueIDOffset.
299+
valueIndex := int(valueID) + int(cr.currentValueBlock.valueIDOffset)
300+
invariants.CheckBounds(valueIndex, cr.currentValueBlock.dec.bd.Rows())
301+
v := cr.currentValueBlock.dec.values.Slice(cr.currentValueBlock.dec.values.Offsets(valueIndex))
296302
return v, nil
297303
}
298304

0 commit comments

Comments
 (0)