Commit 605e2e88 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent eb3028a1
...@@ -18,7 +18,6 @@ package fs1 ...@@ -18,7 +18,6 @@ package fs1
import ( import (
"encoding/binary" "encoding/binary"
//"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -48,7 +47,7 @@ type TxnHeader struct { ...@@ -48,7 +47,7 @@ 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
// transaction metadata tself // transaction metadata itself
zodb.TxnInfo zodb.TxnInfo
// underlying memory for header loading and for user/desc/extension strings // underlying memory for header loading and for user/desc/extension strings
...@@ -101,15 +100,17 @@ func (txnh *TxnHeader) err(subj string, err error) *ErrTxnRecord { ...@@ -101,15 +100,17 @@ func (txnh *TxnHeader) err(subj string, err error) *ErrTxnRecord {
return &ErrTxnRecord{txnh.Pos, subj, err} return &ErrTxnRecord{txnh.Pos, subj, err}
} }
// errf is syntatic shortcut for err and fmt.Errorf // errf is syntactic shortcut for err and fmt.Errorf
func (txnh *TxnHeader) errf(subj, format string, a ...interface{}) *ErrTxnRecord { func (txnh *TxnHeader) errf(subj, format string, a ...interface{}) *ErrTxnRecord {
return txnh.err(subj, fmt.Errorf(format, a...)) return txnh.err(subj, fmt.Errorf(format, a...))
} }
// decodeErr is syntactic shortcut for errf("decode", ...)
func (txnh *TxnHeader) decodeErr(format string, a ...interface{}) *ErrTxnRecord { func (txnh *TxnHeader) decodeErr(format string, a ...interface{}) *ErrTxnRecord {
return txnh.errf("decode", format, a...) return txnh.errf("decode", format, a...)
} }
// bug panics with errf("bug", ...)
func (txnh *TxnHeader) bug(format string, a ...interface{}) { func (txnh *TxnHeader) bug(format string, a ...interface{}) {
panic(txnh.errf("bug", format, a...)) panic(txnh.errf("bug", format, a...))
} }
...@@ -131,20 +132,21 @@ func (dh *DataHeader) err(subj string, err error) *ErrDataRecord { ...@@ -131,20 +132,21 @@ func (dh *DataHeader) err(subj string, err error) *ErrDataRecord {
return &ErrDataRecord{dh.Pos, subj, err} return &ErrDataRecord{dh.Pos, subj, err}
} }
// errf is syntatic shortcut for err and fmt.Errorf // errf is syntactic shortcut for err and fmt.Errorf
func (dh *DataHeader) errf(subj, format string, a ...interface{}) *ErrDataRecord { func (dh *DataHeader) errf(subj, format string, a ...interface{}) *ErrDataRecord {
return dh.err(subj, fmt.Errorf(format, a...)) return dh.err(subj, fmt.Errorf(format, a...))
} }
// TODO decodeErr // decodeErr is syntactic shortcut for errf("decode", ...)
func (dh *DataHeader) decodeErr(format string, a ...interface{}) *ErrDataRecord {
return dh.errf("decode", format, a...)
}
// bug panics with errf("bug", ...)
func (dh *DataHeader) bug(format string, a ...interface{}) { func (dh *DataHeader) bug(format string, a ...interface{}) {
panic(dh.errf("bug", format, a...)) panic(dh.errf("bug", format, a...))
} }
// // XXX -> zodb?
// var ErrVersionNonZero = errors.New("non-zero version")
// noEOF returns err, but changes io.EOF -> io.ErrUnexpectedEOF // noEOF returns err, but changes io.EOF -> io.ErrUnexpectedEOF
func noEOF(err error) error { func noEOF(err error) error {
if err == io.EOF { if err == io.EOF {
...@@ -161,10 +163,6 @@ const ( ...@@ -161,10 +163,6 @@ const (
LoadNoStrings = 0x01 // do not load user/desc/ext strings LoadNoStrings = 0x01 // do not load user/desc/ext strings
) )
// // it is software bug to pass invalid position to Load*()
// // this error will be panicked
// var bugPositionInvalid = errors.New("software bug: invalid position")
// Load reads and decodes transaction record header // Load reads and decodes transaction record header
// pos: points to transaction start // pos: points to transaction start
// no prerequisite requirements are made to previous txnh state // no prerequisite requirements are made to previous txnh state
...@@ -352,6 +350,7 @@ func (txnh *TxnHeader) LoadNext(r io.ReaderAt, flags TxnLoadFlags) error { ...@@ -352,6 +350,7 @@ func (txnh *TxnHeader) LoadNext(r io.ReaderAt, flags TxnLoadFlags) error {
// decode reads and decodes data record header // decode reads and decodes data record header
func (dh *DataHeader) load(r io.ReaderAt /* *os.File */, pos int64, tmpBuf *[DataHeaderSize]byte) error { func (dh *DataHeader) load(r io.ReaderAt /* *os.File */, pos int64, tmpBuf *[DataHeaderSize]byte) error {
dh.Pos = pos dh.Pos = pos
// XXX .Len = 0 = read error ?
if pos < dataValidFrom { if pos < dataValidFrom {
dh.bug("Load() on invalid position") dh.bug("Load() on invalid position")
...@@ -362,10 +361,6 @@ func (dh *DataHeader) load(r io.ReaderAt /* *os.File */, pos int64, tmpBuf *[Dat ...@@ -362,10 +361,6 @@ func (dh *DataHeader) load(r io.ReaderAt /* *os.File */, pos int64, tmpBuf *[Dat
return &ErrDataRecord{pos, "read", noEOF(err)} return &ErrDataRecord{pos, "read", noEOF(err)}
} }
decodeErr := func(format string, a ...interface{}) *ErrDataRecord {
return &ErrDataRecord{pos, "decode", fmt.Errorf(format, a...)}
}
// XXX also check oid.Valid() ? // XXX also check oid.Valid() ?
dh.Oid = zodb.Oid(binary.BigEndian.Uint64(tmpBuf[0:])) // XXX -> zodb.Oid.Decode() ? dh.Oid = zodb.Oid(binary.BigEndian.Uint64(tmpBuf[0:])) // XXX -> zodb.Oid.Decode() ?
dh.Tid = zodb.Tid(binary.BigEndian.Uint64(tmpBuf[8:])) // XXX -> zodb.Tid.Decode() ? dh.Tid = zodb.Tid(binary.BigEndian.Uint64(tmpBuf[8:])) // XXX -> zodb.Tid.Decode() ?
......
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