Commit baf0c4b6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c77264f9
...@@ -28,6 +28,8 @@ import ( ...@@ -28,6 +28,8 @@ import (
type FileStorage struct { type FileStorage struct {
f *os.File // XXX naming -> file ? f *os.File // XXX naming -> file ?
index *fsIndex index *fsIndex
topPos int64 // position pointing just past last committed transaction
// (= size(f) when no commit is in progress)
} }
// IStorage // IStorage
...@@ -188,8 +190,15 @@ func OpenFileStorage(path string) (*FileStorage, error) { ...@@ -188,8 +190,15 @@ func OpenFileStorage(path string) (*FileStorage, error) {
return nil, err // XXX err more context ? return nil, err // XXX err more context ?
} }
// TODO read file header // check file magic
//Read(f, 4) != "FS21" -> invalid header var xxx [4]byte
_, err = f.ReadAt(xxx[:], 0)
if err != nil {
return nil, err // XXX err more context
}
if string(xxx[:]) != "FS21" {
return nil, fmt.Errorf("%s: invalid magic %q", path, xxx) // XXX err?
}
// TODO recreate index if missing / not sane // TODO recreate index if missing / not sane
// TODO verify index sane / topPos matches // TODO verify index sane / topPos matches
...@@ -198,9 +207,7 @@ func OpenFileStorage(path string) (*FileStorage, error) { ...@@ -198,9 +207,7 @@ func OpenFileStorage(path string) (*FileStorage, error) {
panic(err) // XXX err panic(err) // XXX err
} }
_ = topPos return &FileStorage{f: f, index: index, topPos: topPos}, nil
return &FileStorage{f: f, index: index}, nil
} }
...@@ -314,11 +321,18 @@ func (fs *FileStorage) StorageName() string { ...@@ -314,11 +321,18 @@ func (fs *FileStorage) StorageName() string {
return "FileStorage v1" return "FileStorage v1"
} }
func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
if tidMin != zodb.Tid(0) || tidMax != zodb.TidMax {
panic("TODO tidMin/tidMax support")
}
type FileStorageIterator struct {
txnPos int64 // current (?) transaction position
tidMin, tidMax zodb.Tid // iteration range
}
func (fsi *FileStorageIterator) NextTxn(txnInfo *zodb.TxnInfo) (dataIter zodb.IStorageRecordIterator, stop bool, err error) {
// TODO // TODO
return nil return
}
func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
return &FileStorageIterator{-1, tidMin, tidMax} // XXX -1 ok ?
} }
...@@ -102,6 +102,7 @@ func TestLoad(t *testing.T) { ...@@ -102,6 +102,7 @@ func TestLoad(t *testing.T) {
} }
tidv = append(tidv, zodb.TidMax) tidv = append(tidv, zodb.TidMax)
// XXX i -> iMin, j -> iMax ?
for i, tidMin := range tidv { for i, tidMin := range tidv {
for j, tidMax := range tidv { for j, tidMax := range tidv {
_ = j // XXX _ = j // XXX
...@@ -114,18 +115,18 @@ func TestLoad(t *testing.T) { ...@@ -114,18 +115,18 @@ func TestLoad(t *testing.T) {
txni := zodb.TxnInfo{} txni := zodb.TxnInfo{}
datai := zodb.StorageRecordInformation{} datai := zodb.StorageRecordInformation{}
// XXX vvv assumes i < j for k := 0; ; k++ {
// FIXME first tidMin and last tidMax
for k := i; ; k++ {
dataIter, stop, err := iter.NextTxn(&txni) dataIter, stop, err := iter.NextTxn(&txni)
if stop || err != nil { if stop || err != nil {
break break
} }
dbe := _1fs_dbEntryv[k] // XXX vvv assumes i < j
// FIXME first tidMin and last tidMax
dbe := _1fs_dbEntryv[i + k]
if !reflect.DeepEqual(txni, dbe.Header.TxnInfo) { if !reflect.DeepEqual(txni, dbe.Header.TxnInfo) {
t.Errorf("iterating tidMin..tidMac (TODO): step XXX: unexpected txn entry.\nhave: %v\nwant: %v", txni, dbe.Header.TxnInfo) t.Errorf("iterating %v..%v: step %v: unexpected txn entry:\nhave: %q\nwant: %q", tidMin, tidMax, k, txni, dbe.Header.TxnInfo)
} }
for { for {
......
...@@ -147,7 +147,7 @@ type IStorage interface { ...@@ -147,7 +147,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)
Iterate(tidMin, tidMax Tid) IStorageIterator // XXX -> Iter() ? Iterate(tidMin, tidMax Tid) IStorageIterator // XXX , error ?
} }
type IStorageIterator interface { type IStorageIterator interface {
......
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