Commit 675a9e86 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4615f651
...@@ -99,6 +99,7 @@ func fsTail(w io.Writer, path string, ntxn int) (err error) { ...@@ -99,6 +99,7 @@ func fsTail(w io.Writer, path string, ntxn int) (err error) {
// read raw data inside transaction record // read raw data inside transaction record
dataLen := txnh.DataLen() dataLen := txnh.DataLen()
if int64(cap(data)) < dataLen { if int64(cap(data)) < dataLen {
// TODO -> CeilPow2
data = make([]byte, dataLen) data = make([]byte, dataLen)
} else { } else {
data = data[:dataLen] data = data[:dataLen]
......
...@@ -19,6 +19,7 @@ package fs1 ...@@ -19,6 +19,7 @@ package fs1
import ( import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"math/bits"
"io" "io"
"os" "os"
...@@ -233,7 +234,7 @@ const ( ...@@ -233,7 +234,7 @@ const (
// LenPrev >= TxnHeaderFixSize LenPrev was read/checked normally // LenPrev >= TxnHeaderFixSize LenPrev was read/checked normally
func (txnh *TxnHeader) Load(r io.ReaderAt /* *os.File */, pos int64, flags TxnLoadFlags) error { func (txnh *TxnHeader) Load(r io.ReaderAt /* *os.File */, pos int64, flags TxnLoadFlags) error {
if cap(txnh.workMem) < txnXHeaderFixSize { if cap(txnh.workMem) < txnXHeaderFixSize {
txnh.workMem = make([]byte, txnXHeaderFixSize) txnh.workMem = make([]byte, txnXHeaderFixSize, 256 /* to later avoid allocation for typical strings */)
} }
work := txnh.workMem[:txnXHeaderFixSize] work := txnh.workMem[:txnXHeaderFixSize]
...@@ -314,7 +315,7 @@ func (txnh *TxnHeader) Load(r io.ReaderAt /* *os.File */, pos int64, flags TxnLo ...@@ -314,7 +315,7 @@ func (txnh *TxnHeader) Load(r io.ReaderAt /* *os.File */, pos int64, flags TxnLo
// NOTE we encode whole strings length into len(.workMem) // NOTE we encode whole strings length into len(.workMem)
if cap(txnh.workMem) < lstr { if cap(txnh.workMem) < lstr {
txnh.workMem = make([]byte, lstr) txnh.workMem = make([]byte, lstr, ceilPow2(uint64(lstr)))
} else { } else {
txnh.workMem = txnh.workMem[:lstr] txnh.workMem = txnh.workMem[:lstr]
} }
...@@ -548,13 +549,12 @@ func (dh *DataHeader) LoadBack(r io.ReaderAt /* *os.File */) error { ...@@ -548,13 +549,12 @@ func (dh *DataHeader) LoadBack(r io.ReaderAt /* *os.File */) error {
bug(dh, "LoadBack() on non-backpointer data header") bug(dh, "LoadBack() on non-backpointer data header")
} }
var xxx [8]byte // XXX escapes ? _, err := r.ReadAt(dh.workMem[:8], dh.Pos + DataHeaderSize)
_, err := r.ReadAt(xxx[:], dh.Pos + DataHeaderSize)
if err != nil { if err != nil {
return dh.err("read data", noEOF(err)) return dh.err("read data", noEOF(err))
} }
backPos := int64(binary.BigEndian.Uint64(xxx[:])) backPos := int64(binary.BigEndian.Uint64(dh.workMem[0:]))
if backPos == 0 { if backPos == 0 {
return io.EOF // oid was deleted return io.EOF // oid was deleted
} }
...@@ -635,6 +635,12 @@ func (dh *DataHeader) loadNext(r io.ReaderAt /* *os.File */, txnh *TxnHeader) er ...@@ -635,6 +635,12 @@ func (dh *DataHeader) loadNext(r io.ReaderAt /* *os.File */, txnh *TxnHeader) er
return nil return nil
} }
// XXX move me out of here
// ceilPow2 returns minimal y >= x, such as y = 2^i
func ceilPow2(x uint64) uint64 {
return 1 << uint(bits.Len64(x))
}
// LoadData loads data for the data record taking backpointers into account // LoadData loads data for the data record taking backpointers into account
// Data is loaded into *buf, which, if needed, is reallocated to hold all loading data size XXX // Data is loaded into *buf, which, if needed, is reallocated to hold all loading data size XXX
// NOTE on success dh state is changed to data header of original data transaction // NOTE on success dh state is changed to data header of original data transaction
...@@ -654,7 +660,9 @@ func (dh *DataHeader) LoadData(r io.ReaderAt /* *os.File */, buf *[]byte) error ...@@ -654,7 +660,9 @@ func (dh *DataHeader) LoadData(r io.ReaderAt /* *os.File */, buf *[]byte) error
// now read actual data // now read actual data
if int64(cap(*buf)) < dh.DataLen { if int64(cap(*buf)) < dh.DataLen {
*buf = make([]byte, dh.DataLen) // ceilPow2 reduces much allocations but is still not enogh to
// remove them all from BenchmarkIterate
*buf = make([]byte, dh.DataLen, ceilPow2(uint64(dh.DataLen)))
} else { } else {
*buf = (*buf)[:dh.DataLen] *buf = (*buf)[:dh.DataLen]
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment