Strip checksum when returning block from ReadBytes

pull/5142/head
Jason Wilder 2015-12-10 18:24:29 -07:00
parent 97435b9124
commit 45e87cdfe4
2 changed files with 8 additions and 6 deletions

View File

@ -697,7 +697,7 @@ func (f *fileAccessor) readBlock(entry *IndexEntry, values []Value) ([]Value, er
}
//TODO: Validate checksum
values, err = DecodeBlock(b[4:], values)
values, err = DecodeBlock(b, values)
if err != nil {
return nil, err
}
@ -727,7 +727,7 @@ func (f *fileAccessor) readBytes(entry *IndexEntry, b []byte) ([]byte, error) {
return nil, err
}
return b[:n], nil
return b[4:n], nil
}
// ReadAll returns all values for a key in all blocks.
@ -751,7 +751,7 @@ func (f *fileAccessor) readAll(key string) ([]Value, error) {
//TODO: Validate checksum
temp = temp[:0]
temp, err = DecodeBlock(b[4:], temp)
temp, err = DecodeBlock(b, temp)
if err != nil {
return nil, err
}
@ -860,7 +860,7 @@ func (m *mmapAccessor) readBytes(entry *IndexEntry, b []byte) ([]byte, error) {
return nil, ErrTSMClosed
}
return m.b[entry.Offset : entry.Offset+int64(entry.Size)], nil
return m.b[entry.Offset+4 : entry.Offset+int64(entry.Size)], nil
}
// ReadAll returns all values for a key in all blocks.

View File

@ -518,12 +518,14 @@ func (t *tsmWriter) WriteBlock(key string, minTime, maxTime time.Time, block []b
}
}
n, err := t.w.Write(block)
checksum := crc32.ChecksumIEEE(block)
n, err := t.w.Write(append(u32tob(checksum), block...))
if err != nil {
return err
}
blockType, err := BlockType(block[4:])
blockType, err := BlockType(block)
if err != nil {
return err
}