Commit eb3028a1 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0f5cc13f
...@@ -18,7 +18,7 @@ package fs1 ...@@ -18,7 +18,7 @@ package fs1
import ( import (
"encoding/binary" "encoding/binary"
"errors" //"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -131,7 +131,16 @@ func (dh *DataHeader) err(subj string, err error) *ErrDataRecord { ...@@ -131,7 +131,16 @@ func (dh *DataHeader) err(subj string, err error) *ErrDataRecord {
return &ErrDataRecord{dh.Pos, subj, err} return &ErrDataRecord{dh.Pos, subj, err}
} }
// TODO errf, decodeErr // errf is syntatic shortcut for err and fmt.Errorf
func (dh *DataHeader) errf(subj, format string, a ...interface{}) *ErrDataRecord {
return dh.err(subj, fmt.Errorf(format, a...))
}
// TODO decodeErr
func (dh *DataHeader) bug(format string, a ...interface{}) {
panic(dh.errf("bug", format, a...))
}
// // XXX -> zodb? // // XXX -> zodb?
// var ErrVersionNonZero = errors.New("non-zero version") // var ErrVersionNonZero = errors.New("non-zero version")
...@@ -163,10 +172,10 @@ const ( ...@@ -163,10 +172,10 @@ const (
// //
// rules for Len/LenPrev returns: // rules for Len/LenPrev returns:
// Len == 0 transaction header could not be read // Len == 0 transaction header could not be read
// Len == -1 EOF is there when reading forward // Len == -1 EOF forward
// Len >= TxnHeaderFixSize transaction was read normally // Len >= TxnHeaderFixSize transaction was read normally
// //
// LenPrev == 0 error reading // LenPrev == 0 prev record length could not be read
// LenPrev == -1 EOF backward // LenPrev == -1 EOF backward
// 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 {
...@@ -317,32 +326,37 @@ func (txnh *TxnHeader) LoadPrev(r io.ReaderAt, flags TxnLoadFlags) error { ...@@ -317,32 +326,37 @@ func (txnh *TxnHeader) LoadPrev(r io.ReaderAt, flags TxnLoadFlags) error {
// - TODO // - TODO
func (txnh *TxnHeader) LoadNext(r io.ReaderAt, flags TxnLoadFlags) error { func (txnh *TxnHeader) LoadNext(r io.ReaderAt, flags TxnLoadFlags) error {
lenCur := txnh.Len lenCur := txnh.Len
posCur := txnh.Pos
switch lenCur { switch lenCur {
case 0: case 0:
txhn.bug("LoadNext() when .Len == error") txnh.bug("LoadNext() when .Len == error")
case -1: case -1:
return io.EOF return io.EOF
} }
err := txnh.Load(r, txnh.Pos + lenCur, flags) err := txnh.Load(r, txnh.Pos + lenCur, flags)
// TODO XXX
if txnh.LenPrev != lenCur { // before checking loading error for next txn, let's first check redundant length
} // NOTE also: err could be EOF
if err != nil { if txnh.LenPrev != 0 && txnh.LenPrev != lenCur {
err := txnh.decodeErr("head/tail lengths mismatch: %v, %v", lenCur, txnh.LenPrev)
err.Pos = posCur // position of txn for which we discovered problem
return err return err
} }
return err
} }
// 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
if pos < dataValidFrom { if pos < dataValidFrom {
panic(&ErrDataRecord{pos, "read", bugPositionInvalid}) dh.bug("Load() on invalid position")
} }
dh.Pos = pos
_, err := r.ReadAt(tmpBuf[:], pos) _, err := r.ReadAt(tmpBuf[:], pos)
if err != nil { if err != nil {
return &ErrDataRecord{pos, "read", noEOF(err)} return &ErrDataRecord{pos, "read", noEOF(err)}
......
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