Commit cd186bf8 authored by Kirill Smelkov's avatar Kirill Smelkov

X fs1: switch error/EOF from (0, -1) -> (-1, 0)

parent 23870baf
...@@ -476,9 +476,9 @@ func open(path string) (_ *FileStorage, err error) { ...@@ -476,9 +476,9 @@ func open(path string) (_ *FileStorage, err error) {
// .LenPrev must be good or EOF backward // .LenPrev must be good or EOF backward
switch fs.txnhMax.LenPrev { switch fs.txnhMax.LenPrev {
case 0:
return nil, fmt.Errorf("%s: could not read LenPrev @%d (last transaction)", f.Name(), fs.txnhMax.Pos)
case -1: case -1:
return nil, fmt.Errorf("%s: could not read LenPrev @%d (last transaction)", f.Name(), fs.txnhMax.Pos)
case 0:
// ok - EOF backward // ok - EOF backward
default: default:
......
...@@ -210,13 +210,13 @@ const ( ...@@ -210,13 +210,13 @@ const (
// //
// Rules for .Len/.LenPrev returns: // Rules for .Len/.LenPrev returns:
// //
// .Len == 0 transaction header could not be read // .Len = -1 transaction header could not be read
// .Len == -1 EOF forward // .Len = 0 EOF forward
// .Len >= TxnHeaderFixSize transaction was read normally // .Len > 0 transaction was read normally
// //
// .LenPrev == 0 prev record length could not be read // .LenPrev = -1 prev record length could not be read
// .LenPrev == -1 EOF backward // .LenPrev = 0 EOF backward
// .LenPrev >= TxnHeaderFixSize LenPrev was read/checked normally // .LenPrev > 0 LenPrev was read/checked normally
// //
// For example when pos points to the end of file .Len will be returned = -1, but // For example when pos points to the end of file .Len will be returned = -1, but
// .LenPrev will be usually valid if file has at least 1 transaction. // .LenPrev will be usually valid if file has at least 1 transaction.
...@@ -227,8 +227,8 @@ func (txnh *TxnHeader) Load(r io.ReaderAt, pos int64, flags TxnLoadFlags) error ...@@ -227,8 +227,8 @@ func (txnh *TxnHeader) Load(r io.ReaderAt, pos int64, flags TxnLoadFlags) error
work := txnh.workMem[:txnXHeaderFixSize] work := txnh.workMem[:txnXHeaderFixSize]
txnh.Pos = pos txnh.Pos = pos
txnh.Len = 0 // read error txnh.Len = -1 // read error
txnh.LenPrev = 0 // read error txnh.LenPrev = -1 // read error
if pos < txnValidFrom { if pos < txnValidFrom {
bug(r, txnh, "Load() on invalid position") bug(r, txnh, "Load() on invalid position")
...@@ -258,13 +258,13 @@ func (txnh *TxnHeader) Load(r io.ReaderAt, pos int64, flags TxnLoadFlags) error ...@@ -258,13 +258,13 @@ func (txnh *TxnHeader) Load(r io.ReaderAt, pos int64, flags TxnLoadFlags) error
} else { } else {
// read only current txn without previous record length // read only current txn without previous record length
n, err = r.ReadAt(work[8:], pos) n, err = r.ReadAt(work[8:], pos)
txnh.LenPrev = -1 // EOF backward txnh.LenPrev = 0 // EOF backward
} }
if err != nil { if err != nil {
if err == io.EOF && n == 0 { if err == io.EOF && n == 0 {
txnh.Len = -1 // EOF forward txnh.Len = 0 // EOF forward
return err // end of stream return err // end of stream
} }
...@@ -354,9 +354,9 @@ func (txnh *TxnHeader) loadStrings(r io.ReaderAt) error { ...@@ -354,9 +354,9 @@ func (txnh *TxnHeader) loadStrings(r io.ReaderAt) error {
func (txnh *TxnHeader) LoadPrev(r io.ReaderAt, flags TxnLoadFlags) error { func (txnh *TxnHeader) LoadPrev(r io.ReaderAt, flags TxnLoadFlags) error {
lenPrev := txnh.LenPrev lenPrev := txnh.LenPrev
switch lenPrev { switch lenPrev {
case 0:
bug(r, txnh, "LoadPrev() when .LenPrev == error")
case -1: case -1:
bug(r, txnh, "LoadPrev() when .LenPrev == error")
case 0:
return io.EOF return io.EOF
case lenIterStart: case lenIterStart:
...@@ -364,7 +364,7 @@ func (txnh *TxnHeader) LoadPrev(r io.ReaderAt, flags TxnLoadFlags) error { ...@@ -364,7 +364,7 @@ func (txnh *TxnHeader) LoadPrev(r io.ReaderAt, flags TxnLoadFlags) error {
// read LenPrev @pos, then tail to LoadPrev // read LenPrev @pos, then tail to LoadPrev
pos := txnh.Pos pos := txnh.Pos
err := txnh.Load(r, pos, flags) err := txnh.Load(r, pos, flags)
if txnh.LenPrev == 0 { if txnh.LenPrev == -1 {
if err == nil { if err == nil {
panic("nil err with txnh.LenPrev = error") panic("nil err with txnh.LenPrev = error")
} }
...@@ -406,9 +406,9 @@ func (txnh *TxnHeader) LoadNext(r io.ReaderAt, flags TxnLoadFlags) error { ...@@ -406,9 +406,9 @@ func (txnh *TxnHeader) LoadNext(r io.ReaderAt, flags TxnLoadFlags) error {
lenCur := txnh.Len lenCur := txnh.Len
posCur := txnh.Pos posCur := txnh.Pos
switch lenCur { switch lenCur {
case 0:
bug(r, txnh, "LoadNext() when .Len == error")
case -1: case -1:
bug(r, txnh, "LoadNext() when .Len == error")
case 0:
return io.EOF return io.EOF
case lenIterStart: case lenIterStart:
...@@ -423,7 +423,7 @@ func (txnh *TxnHeader) LoadNext(r io.ReaderAt, flags TxnLoadFlags) error { ...@@ -423,7 +423,7 @@ func (txnh *TxnHeader) LoadNext(r io.ReaderAt, flags TxnLoadFlags) error {
// before checking loading error for next txn, let's first check redundant length // before checking loading error for next txn, let's first check redundant length
// NOTE also: err could be EOF // NOTE also: err could be EOF
if txnh.LenPrev != 0 && txnh.LenPrev != lenCur { if txnh.LenPrev >= 0 && txnh.LenPrev != lenCur {
t := &TxnHeader{Pos: posCur} // txn for which we discovered problem t := &TxnHeader{Pos: posCur} // txn for which we discovered problem
return checkErr(r, t, "head/tail lengths mismatch: %v, %v", lenCur, txnh.LenPrev) return checkErr(r, t, "head/tail lengths mismatch: %v, %v", lenCur, txnh.LenPrev)
} }
......
...@@ -59,7 +59,7 @@ def main(): ...@@ -59,7 +59,7 @@ def main():
# database records # database records
emit("\nvar _1fs_dbEntryv = [...]dbEntry{") emit("\nvar _1fs_dbEntryv = [...]dbEntry{")
txnLenPrev = -1 txnLenPrev = 0
for txn in stor.iterator(): # txn is TransactionRecord for txn in stor.iterator(): # txn is TransactionRecord
# txn.extension is already depickled dict - we want to put raw data from file # txn.extension is already depickled dict - we want to put raw data from file
# also we need to access txn record length which is not provided by higher-level iterator # also we need to access txn record length which is not provided by higher-level iterator
......
...@@ -21,7 +21,7 @@ var _1fs_dbEntryv = [...]dbEntry{ ...@@ -21,7 +21,7 @@ var _1fs_dbEntryv = [...]dbEntry{
{ {
TxnHeader{ TxnHeader{
Pos: 4, Pos: 4,
LenPrev: -1, LenPrev: 0,
Len: 159, Len: 159,
TxnInfo: zodb.TxnInfo{ TxnInfo: zodb.TxnInfo{
Tid: 0x0285cbac258bf266, Tid: 0x0285cbac258bf266,
......
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