Commit afbec0f4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 68f80523
...@@ -275,15 +275,21 @@ func OpenFileStorage(path string) (*FileStorage, error) { ...@@ -275,15 +275,21 @@ func OpenFileStorage(path string) (*FileStorage, error) {
// read tidMin/tidMax // read tidMin/tidMax
// FIXME support empty file case // FIXME support empty file case
var txnhMin, txnhMax TxnHeader var txnhMin, txnhMax TxnHeader
_, err = txnhMin.Decode(f, 4) err = txnhMin.Load(f, 4)
if err != nil { if err != nil {
return nil, err // XXX +context return nil, err // XXX +context
} }
_, _, err = txnhMax.DecodePrev(f, topPos) err = txnhMax.Load(f, topPos)
// XXX expect EOF but .PrevLen must be good
if err != nil { if err != nil {
return nil, err // XXX +context return nil, err // XXX +context
} }
err = txhhMax.LoadPrev(f)
if err != nil {
// XXX
}
return &FileStorage{ return &FileStorage{
f: f, f: f,
...@@ -406,10 +412,33 @@ func (fs *FileStorage) StorageName() string { ...@@ -406,10 +412,33 @@ func (fs *FileStorage) StorageName() string {
} }
type FileStorageIterator struct { type forwardIter struct {
txnPos int64 // current (?) transaction position //Pos int64 // current transaction position
tidMin, tidMax zodb.Tid // iteration range: [tidMin, tidMax] Txnh TxnHeader // current transaction information
TidMax zodb.Tid // iterate up to tid <= tidMax
}
func (fi *forwardIter) NextTxn() error {
// XXX from what we start? how to yield 1st elem?
err := fi.Txnh.LoadNext()
if err != nil {
return err
}
// how to make sure last good txnh is preserved?
if fi.Txnh.Tid > fi.TidMax {
return io.EOF
}
return nil
}
// TODO backwardIter
type FileStorageIterator struct {
forwardIter
tidMin zodb.Tid // iteration range: [tidMin, tidMax]
} }
func (fsi *FileStorageIterator) NextTxn(txnInfo *zodb.TxnInfo) (dataIter zodb.IStorageRecordIterator, stop bool, err error) { func (fsi *FileStorageIterator) NextTxn(txnInfo *zodb.TxnInfo) (dataIter zodb.IStorageRecordIterator, stop bool, err error) {
...@@ -425,11 +454,14 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator { ...@@ -425,11 +454,14 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
// -> XXX empty // -> XXX empty
} }
/*
(tidMin - fs.TidMin) vs (fs.TidMax - tidMin) (tidMin - fs.TidMin) vs (fs.TidMax - tidMin)
// if forward if forward {
iter := forwardIter{4, tidMin} iter = forwardIter{4, tidMin}
} else {
iter = backwardIter{fs.topPos, tidMin}
}
for { for {
iter.NextTxn(txnh, ...) iter.NextTxn(txnh, ...)
} }
...@@ -437,7 +469,6 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator { ...@@ -437,7 +469,6 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
// txnh should have .Tid <= tidMin but next txn's .Tid is > tidMin // txnh should have .Tid <= tidMin but next txn's .Tid is > tidMin
posStart := iter.txnPos posStart := iter.txnPos
if t if t
*/
return &FileStorageIterator{-1, tidMin, tidMax} // XXX -1 ok ? return &FileStorageIterator{-1, tidMin, tidMax} // XXX -1 ok ?
} }
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