Commit b90ada39 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3529459c
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
pickle "github.com/kisielk/og-rek" pickle "github.com/kisielk/og-rek"
) )
// PyData represent data stored into ZODB by Python applications. // PyData represents data stored into ZODB by Python applications.
// //
// The format is based on python pickles. Basically every serialized object has // The format is based on python pickles. Basically every serialized object has
// two parts: class description and object state. See // two parts: class description and object state. See
......
...@@ -792,7 +792,7 @@ func Iterate(r io.ReaderAt, posStart int64, dir IterDir) *Iter { ...@@ -792,7 +792,7 @@ func Iterate(r io.ReaderAt, posStart int64, dir IterDir) *Iter {
case IterBackward: case IterBackward:
it.Txnh.LenPrev = lenIterStart it.Txnh.LenPrev = lenIterStart
default: default:
panic("invalid dir") panic("dir invalid")
} }
return it return it
} }
...@@ -1267,9 +1267,7 @@ func (fs *FileStorage) computeIndex(ctx context.Context) (index *Index, err erro ...@@ -1267,9 +1267,7 @@ func (fs *FileStorage) computeIndex(ctx context.Context) (index *Index, err erro
// not want to load actual data - only data headers. // not want to load actual data - only data headers.
fsSeq := xbufio.NewSeqReaderAt(fs.file) fsSeq := xbufio.NewSeqReaderAt(fs.file)
// pre-setup txnh so that txnh.LoadNext starts loading from the beginning of file it := Iterate(fsSeq, index.TopPos, IterForward)
txnh := &TxnHeader{Pos: index.TopPos, Len: lenIterStart}
dh := &DataHeader{}
loop: loop:
for { for {
...@@ -1280,7 +1278,7 @@ loop: ...@@ -1280,7 +1278,7 @@ loop:
default: default:
} }
err = txnh.LoadNext(fsSeq, LoadNoStrings) err = it.NextTxn(LoadNoStrings)
if err != nil { if err != nil {
err = okEOF(err) err = okEOF(err)
break break
...@@ -1288,14 +1286,10 @@ loop: ...@@ -1288,14 +1286,10 @@ loop:
// XXX check txnh.Status != TxnInprogress // XXX check txnh.Status != TxnInprogress
index.TopPos = txnh.Pos + txnh.Len index.TopPos = it.Txnh.Pos + it.Txnh.Len
// first data iteration will go to first data record
dh.Pos = txnh.DataPos()
dh.DataLen = -DataHeaderSize
for { for {
err = dh.LoadNext(fsSeq, txnh) err = it.NextData()
if err != nil { if err != nil {
err = okEOF(err) err = okEOF(err)
if err != nil { if err != nil {
...@@ -1304,7 +1298,7 @@ loop: ...@@ -1304,7 +1298,7 @@ loop:
break break
} }
index.Set(dh.Oid, dh.Pos) index.Set(it.Datah.Oid, it.Datah.Pos)
} }
} }
......
...@@ -288,7 +288,7 @@ func TestComputeIndex(t *testing.T) { ...@@ -288,7 +288,7 @@ func TestComputeIndex(t *testing.T) {
fs := xfsopen(t, "testdata/1.fs") // TODO open ro fs := xfsopen(t, "testdata/1.fs") // TODO open ro
defer exc.XRun(fs.Close) defer exc.XRun(fs.Close)
index, err := fs.computeIndex(context.TODO()) index, err := fs.computeIndex(context.Background())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -50,13 +50,12 @@ type Dumper interface { ...@@ -50,13 +50,12 @@ type Dumper interface {
// transaction if it needs to dump information about data records. // transaction if it needs to dump information about data records.
// //
// If dumper return io.EOF the whole dumping process finishes. // If dumper return io.EOF the whole dumping process finishes.
// XXX -> better dedicated err?
DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error
} }
// Dump dumps content of a FileStorage file @ path. // Dump dumps content of a FileStorage file @ path.
// To do so it reads file header and then iterates over all transactions in the file. // To do so it reads file header and then iterates over all transactions in the file.
// The logic to actually output information and if needed read/process data is implemented by Dumper d. // The logic to actually output information and, if needed read/process data, is implemented by Dumper d.
func Dump(w io.Writer, path string, dir fs1.IterDir, d Dumper) (err error) { func Dump(w io.Writer, path string, dir fs1.IterDir, d Dumper) (err error) {
defer xerr.Contextf(&err, "%s: %s", path, d.DumperName()) // XXX ok? defer xerr.Contextf(&err, "%s: %s", path, d.DumperName()) // XXX ok?
...@@ -78,7 +77,7 @@ func Dump(w io.Writer, path string, dir fs1.IterDir, d Dumper) (err error) { ...@@ -78,7 +77,7 @@ func Dump(w io.Writer, path string, dir fs1.IterDir, d Dumper) (err error) {
return err return err
} }
// make sure to flush buffer if we return prematurely e.g. with an error // make sure to flush buffer on return
defer func() { defer func() {
err2 := flushBuf() err2 := flushBuf()
err = xerr.First(err, err2) err = xerr.First(err, err2)
......
...@@ -94,3 +94,5 @@ func reindexMain(argv []string) { ...@@ -94,3 +94,5 @@ func reindexMain(argv []string) {
log.Fatal(err) log.Fatal(err)
} }
} }
// TODO verify-index
...@@ -28,7 +28,7 @@ var commands = zodbtools.CommandRegistry{ ...@@ -28,7 +28,7 @@ var commands = zodbtools.CommandRegistry{
// + fsstats? (fsstats.py) // + fsstats? (fsstats.py)
{"reindex", reindexSummary, reindexUsage, reindexMain}, {"reindex", reindexSummary, reindexUsage, reindexMain},
// XXX reindex -> reindex, verify-index {"verify-index", verifyIdxSummary, verifyIdxUsage, verifyIdxMaxin},
// recover (fsrecover.py) // recover (fsrecover.py)
// verify (fstest.py) // verify (fstest.py)
......
...@@ -198,7 +198,7 @@ def main(): ...@@ -198,7 +198,7 @@ def main():
with open("ztestdata_expect_test.go", "w") as f: with open("ztestdata_expect_test.go", "w") as f:
def emit(v): def emit(v):
print >>f, v print >>f, v
emit("// Code generated by %s; DO NOT EDIT." % __name__) emit("// Code generated by %s; DO NOT EDIT." % __file__)
emit("package fs1\n") emit("package fs1\n")
emit("import \"lab.nexedi.com/kirr/neo/go/zodb\"\n") emit("import \"lab.nexedi.com/kirr/neo/go/zodb\"\n")
......
// Code generated by py/gen-testdata; DO NOT EDIT. // Code generated by ./py/gen-testdata; DO NOT EDIT.
package fs1 package fs1
import "lab.nexedi.com/kirr/neo/go/zodb" import "lab.nexedi.com/kirr/neo/go/zodb"
......
...@@ -165,6 +165,7 @@ type IStorage interface { ...@@ -165,6 +165,7 @@ type IStorage interface {
// tpc_finish(txn, callback) XXX clarify about callback // tpc_finish(txn, callback) XXX clarify about callback
// tpc_abort(txn) // tpc_abort(txn)
// XXX allow iteration both ways (forward & backward)
// XXX text // XXX text
Iterate(tidMin, tidMax Tid) IStorageIterator // XXX , error ? Iterate(tidMin, tidMax Tid) IStorageIterator // XXX , error ?
} }
......
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