Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pointers instead of binary encoding #965

Merged
merged 6 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix test failures
  • Loading branch information
Ibrahim Jarif committed Aug 8, 2019
commit 4ae8135a7f6c50f7507aeec1f56d844836384b85
2 changes: 1 addition & 1 deletion table/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type header struct {

// Encode encodes the header.
func (h header) Encode() []byte {
var b [8]byte
var b [4]byte
*(*header)(unsafe.Pointer(&b[0])) = h
return b[:]
}
Expand Down
17 changes: 9 additions & 8 deletions table/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import (
)

type blockIterator struct {
data []byte
pos uint32
err error
baseKey []byte
numEntries int
entryOffsets []uint32
currentIdx int
data []byte
pos uint32
err error
baseKey []byte
numEntries int
entryOffsets []uint32
entriesIndexStart int
currentIdx int

key []byte
val []byte
Expand Down Expand Up @@ -159,7 +160,7 @@ func (itr *blockIterator) parseKV(h header) {
valEndOffset = uint32(itr.entriesIndexStart)
} else {
// Get starting offset of the next entry which is the end of the current entry.
valEndOffset = itr.getOffset(itr.currentIdx + 1)
valEndOffset = itr.entryOffsets[itr.currentIdx+1]
}

if valEndOffset > uint32(len(itr.data)) {
Expand Down
19 changes: 11 additions & 8 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ func (t *Table) DecrRef() error {
}

type block struct {
offset int
data []byte
numEntries int // number of entries present in the block
entryOffsets []uint32
chkLen int // checksum length
offset int
data []byte
numEntries int // number of entries present in the block
entryOffsets []uint32
entriesIndexStart int
chkLen int // checksum length
}

func (b block) verifyCheckSum() error {
Expand All @@ -145,9 +146,10 @@ func (b block) verifyCheckSum() error {

func (b block) NewIterator() *blockIterator {
bi := &blockIterator{
data: b.data,
numEntries: b.numEntries,
entryOffsets: b.entryOffsets,
data: b.data,
numEntries: b.numEntries,
entryOffsets: b.entryOffsets,
entriesIndexStart: b.entriesIndexStart,
}

return bi
Expand Down Expand Up @@ -331,6 +333,7 @@ func (t *Table) block(idx int) (*block, error) {

blk.entryOffsets = bytesToU32Slice(blk.data[entriesIndexStart:entriesIndexEnd])

blk.entriesIndexStart = entriesIndexStart
// Verify checksum on if checksum verification mode is OnRead on OnStartAndRead.
if t.opt.ChkMode == options.OnBlockRead || t.opt.ChkMode == options.OnTableAndBlockRead {
if err = blk.verifyCheckSum(); err != nil {
Expand Down