Commit adea442b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7904412f
......@@ -34,6 +34,7 @@ type FileStorage struct {
var _ zodb.IStorage = (*FileStorage)(nil)
// TxnHeader represents header of a transaction record
type TxnHeader struct {
Tid zodb.Tid
RecLenm8 uint64
......@@ -52,9 +53,9 @@ type TxnHeader struct {
type DataHeader struct {
Oid zodb.Oid
Tid zodb.Tid
PrevDataRecPos int64 // previous-record file-position
PrevDataRecPos int64 // previous-record file-position XXX name
TxnPos int64 // position of transaction record this data record belongs to
_ uint16 // 2-bytes with zero values. (Was version length.)
//_ uint16 // 2-bytes with zero values. (Was version length.)
DataLen uint64 // length of following data. if 0 -> following = 8 bytes backpointer XXX -> int64 too ?
// if backpointer == 0 -> oid deleted
//Data []byte
......@@ -120,11 +121,20 @@ func NewFileStorage(path string) (*FileStorage, error) {
if err != nil {
return nil, err // XXX err more context ?
}
// TODO read file header
//Read(f, 4) != "FS21" -> invalid header
return &FileStorage{f: f}, nil
// TODO read/recreate index
// TODO recreate index if missing / not sane
// TODO verify index sane / topPos matches
topPos, index, err := LoadIndexFile(path + ".index")
if err != nil {
panic(err) // XXX err
}
_ = topPos
return &FileStorage{f: f, index: index}, nil
}
......
......@@ -2,6 +2,14 @@
package fs1
import (
"bytes"
"strconv"
"testing"
"../../zodb"
)
// one entry inside transaction
type txnEntry struct {
header DataHeader
......@@ -10,6 +18,33 @@ type txnEntry struct {
type dbEntry struct {
header TxnHeader
// TODO user, desc, ext
Recordv []txnEntry
entryv []txnEntry
}
func TestLoad(t *testing.T) {
fs, err := NewFileStorage("testdata/1.fs")
if err != nil {
t.Fatal(err)
}
for _, dbe := range _1fs_dbEntryv {
for _, txe := range dbe.entryv {
txh := txe.header
if txh.DataLen == 0 {
continue // FIXME skipping backpointers
}
xid := zodb.Xid{zodb.XTid{txh.Tid, false}, txh.Oid} // loadSerial
data, tid, err := fs.Load(xid)
if err != nil {
t.Errorf("load %v: %v", xid, err)
}
if tid != txh.Tid {
t.Errorf("load %v: returned tid unexpected: %v", xid)
}
if !bytes.Equal(data, txe.data) {
t.Errorf("load %v: different data:\nhave: %s\nwant: %s", xid, strconv.Quote(string(data)), strconv.Quote(string(txe.data)))
}
}
}
}
......@@ -58,7 +58,7 @@ func bint(b bool) int {
func (xtid XTid) String() string {
// XXX also print "tid:" prefix ?
return fmt.Sprintf("%c%v", "=<"[bint(xtid.TidBefore)], xtid)
return fmt.Sprintf("%c%v", "=<"[bint(xtid.TidBefore)], xtid.Tid)
}
func (xid Xid) String() string {
......
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