Commit c285c610 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e6f9c797
...@@ -47,8 +47,6 @@ type TxnHeader struct { ...@@ -47,8 +47,6 @@ type TxnHeader struct {
// (0 if there is no previous txn record) // (0 if there is no previous txn record)
Len int64 // whole transaction record length Len int64 // whole transaction record length
// XXX recheck ^^^ Len are validated on load
// transaction metadata tself // transaction metadata tself
zodb.TxnInfo zodb.TxnInfo
...@@ -106,25 +104,24 @@ var ErrVersionNonZero = errors.New("non-zero version") ...@@ -106,25 +104,24 @@ var ErrVersionNonZero = errors.New("non-zero version")
// load reads and decodes transaction record header from a readerAt // load reads and decodes transaction record header from a readerAt
// pos: points to header begin XXX text // pos: points to transaction start
// no requirements are made to previous th state XXX text // no requirements are made to previous txnh state
// XXX io.ReaderAt -> *os.File (if iface conv costly) // XXX io.ReaderAt -> *os.File (if iface conv costly)
//func (th *TxnHeader) load(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize]byte) (n int, err error) { func (txnh *TxnHeader) load(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize]byte) error {
func (th *TxnHeader) load(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize]byte) error { txnh.Pos = pos
th.Pos = pos
if pos > 4 + 8 { // XXX -> magic if pos > 4 + 8 { // XXX -> magic
// read together with previous's txn record redundand length // read together with previous's txn record redundand length
n, err = r.ReadAt(tmpBuf[:], pos - 8) n, err = r.ReadAt(tmpBuf[:], pos - 8)
n -= 8 // relative to pos n -= 8 // relative to pos
if n >= 0 { if n >= 0 {
th.PrevLenm8 = uint64(binary.BigEndian.Uint64(tmpBuf[8-8:])) txnh.PrevLen = 8 + int64(binary.BigEndian.Uint64(tmpBuf[8-8:]))
if th.PrevLenm8 < txnHeaderFixSize { if txnh.PrevLen < txnHeaderFixSize {
panic("too small txn prev record length") // XXX panic("too small txn prev record length") // XXX
} }
} }
} else { } else {
th.PrevLenm8 = 0 txnh.PrevLen = 0
n, err = r.ReadAt(tmpBuf[8:], pos) n, err = r.ReadAt(tmpBuf[8:], pos)
} }
...@@ -142,11 +139,11 @@ func (th *TxnHeader) load(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize]b ...@@ -142,11 +139,11 @@ func (th *TxnHeader) load(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize]b
return n, &ErrTxnRecord{pos, "read", err} return n, &ErrTxnRecord{pos, "read", err}
} }
th.Tid = zodb.Tid(binary.BigEndian.Uint64(tmpBuf[8+0:])) txnh.Tid = zodb.Tid(binary.BigEndian.Uint64(tmpBuf[8+0:]))
th.Lenm8 = uint64(binary.BigEndian.Uint64(tmpBuf[8+8:])) txnh.Len = 8 + int64(binary.BigEndian.Uint64(tmpBuf[8+8:]))
th.Status = zodb.TxnStatus(tmpBuf[8+16]) txnh.Status = zodb.TxnStatus(tmpBuf[8+16])
if th.Lenm8 < txnHeaderFixSize { if txnh.Len < txnHeaderFixSize {
panic("too small txn record length") // XXX panic("too small txn record length") // XXX
} }
...@@ -156,22 +153,22 @@ func (th *TxnHeader) load(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize]b ...@@ -156,22 +153,22 @@ func (th *TxnHeader) load(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize]b
// XXX load strings only optionally // XXX load strings only optionally
lstr := int(luser) + int(ldesc) + int(lext) lstr := int(luser) + int(ldesc) + int(lext)
if lstr <= cap(th.stringsMem) { if lstr <= cap(txnh.stringsMem) {
th.stringsMem = th.stringsMem[:lstr] txnh.stringsMem = txnh.stringsMem[:lstr]
} else { } else {
th.stringsMem = make([]byte, lstr) txnh.stringsMem = make([]byte, lstr)
} }
nstr, err = r.ReadAt(th.stringsMem, pos + txnHeaderFixSize) nstr, err = r.ReadAt(txnh.stringsMem, pos + txnHeaderFixSize)
// XXX EOF after txn header is not good // XXX EOF after txn header is not good
if err != nil { if err != nil {
return 0, &ErrTxnRecord{pos, "read", noEof(err)} return 0, &ErrTxnRecord{pos, "read", noEof(err)}
} }
th.User = th.stringsMem[0:luser] txnh.User = txnh.stringsMem[0:luser]
th.Description = th.stringsMem[luser:luser+ldesc] txnh.Description = txnh.stringsMem[luser:luser+ldesc]
th.Extension = th.stringsMem[luser+ldesc:luser+ldesc+lext] txnh.Extension = txnh.stringsMem[luser+ldesc:luser+ldesc+lext]
return txnHeaderFixSize + lstr, nil return txnHeaderFixSize + lstr, nil
} }
......
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