Commit 2eee583e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fc80052c
...@@ -1028,11 +1028,11 @@ func (fs *FileStorage) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) ...@@ -1028,11 +1028,11 @@ func (fs *FileStorage) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error)
// --- ZODB-level iteration --- // --- ZODB-level iteration ---
// zIter is combined transaction/data-records iterator as specified by zodb.IStorage // zIter is combined transaction/data-records iterator as specified by zodb.IStorage.Iterate
type zIter struct { type zIter struct {
iter Iter iter Iter
TidStop zodb.Tid // iterate up to tid <= tidStop | tid >= tidStop depending on .dir TidStop zodb.Tid // iterate up to tid <= tidStop | tid >= tidStop depending on iter.dir
zFlags zIterFlags zFlags zIterFlags
...@@ -1043,7 +1043,7 @@ type zIter struct { ...@@ -1043,7 +1043,7 @@ type zIter struct {
// here to avoid allocations ) // here to avoid allocations )
dhLoading DataHeader dhLoading DataHeader
sri zodb.StorageRecordInformation // ptr to this will be returned by NextData sri zodb.StorageRecordInformation // ptr to this will be returned by .NextData
dataBuf []byte dataBuf []byte
} }
...@@ -1131,7 +1131,7 @@ func (e *iterStartError) NextTxn() (*zodb.TxnInfo, zodb.IStorageRecordIterator, ...@@ -1131,7 +1131,7 @@ func (e *iterStartError) NextTxn() (*zodb.TxnInfo, zodb.IStorageRecordIterator,
// Iterate creates zodb-level iterator for tidMin..tidMax range // Iterate creates zodb-level iterator for tidMin..tidMax range
func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator { func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
//fmt.Printf("iterate %v..%v\n", tidMin, tidMax) fmt.Printf("iterate %v..%v\n", tidMin, tidMax)
// FIXME case when only 0 or 1 txn present // FIXME case when only 0 or 1 txn present
if tidMin < fs.txnhMin.Tid { if tidMin < fs.txnhMin.Tid {
tidMin = fs.txnhMin.Tid tidMin = fs.txnhMin.Tid
...@@ -1140,12 +1140,12 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator { ...@@ -1140,12 +1140,12 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
tidMax = fs.txnhMax.Tid tidMax = fs.txnhMax.Tid
} }
ziter := &zIter{iter: Iter{}}
// when iterating use IO optimized for sequential access // when iterating use IO optimized for sequential access
// XXX -> IterateRaw ? // XXX -> IterateRaw ?
fsSeq := xbufio.NewSeqReaderAt(fs.file) fsSeq := xbufio.NewSeqReaderAt(fs.file)
ziter.iter.R = fsSeq ziter := &zIter{iter: Iter{R: fsSeq}}
iter := &ziter.iter
if tidMin > tidMax { if tidMin > tidMax {
ziter.zFlags |= zIterEOF // empty ziter.zFlags |= zIterEOF // empty
...@@ -1153,17 +1153,15 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator { ...@@ -1153,17 +1153,15 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
} }
// scan either from file start or end, depending which way it is likely closer, to tidMin // scan either from file start or end, depending which way it is likely closer, to tidMin
// XXX put iter into ptr to Iter ^^^
iter := &ziter.iter
if (tidMin - fs.txnhMin.Tid) < (fs.txnhMax.Tid - tidMin) { if (tidMin - fs.txnhMin.Tid) < (fs.txnhMax.Tid - tidMin) {
//fmt.Printf("forward %.1f%%\n", 100 * float64(tidMin - fs.txnhMin.Tid) / float64(fs.txnhMax.Tid - fs.txnhMin.Tid)) fmt.Printf("forward %.1f%%\n", 100 * float64(tidMin - fs.txnhMin.Tid) / float64(fs.txnhMax.Tid - fs.txnhMin.Tid))
iter.Dir = IterForward iter.Dir = IterForward
iter.Txnh.CloneFrom(&fs.txnhMin) iter.Txnh.CloneFrom(&fs.txnhMin)
ziter.zFlags = zIterPreloaded ziter.zFlags = zIterPreloaded
ziter.TidStop = tidMin - 1 // XXX overflow ziter.TidStop = tidMin - 1 // XXX overflow
} else { } else {
//fmt.Printf("backward %.1f%%\n", 100 * float64(tidMin - fs.txnhMin.Tid) / float64(fs.txnhMax.Tid - fs.txnhMin.Tid)) fmt.Printf("backward %.1f%%\n", 100 * float64(tidMin - fs.txnhMin.Tid) / float64(fs.txnhMax.Tid - fs.txnhMin.Tid))
iter.Dir = IterBackward iter.Dir = IterBackward
iter.Txnh.CloneFrom(&fs.txnhMax) iter.Txnh.CloneFrom(&fs.txnhMax)
ziter.zFlags = zIterPreloaded ziter.zFlags = zIterPreloaded
...@@ -1203,6 +1201,8 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator { ...@@ -1203,6 +1201,8 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
return ziter return ziter
} }
// --- rebuilding index ---
// computeIndex builds new in-memory index for FileStorage // computeIndex builds new in-memory index for FileStorage
// XXX naming // XXX naming
func (fs *FileStorage) computeIndex(ctx context.Context) (index *Index, err error) { func (fs *FileStorage) computeIndex(ctx context.Context) (index *Index, err error) {
......
...@@ -141,7 +141,12 @@ func TestLoad(t *testing.T) { ...@@ -141,7 +141,12 @@ func TestLoad(t *testing.T) {
// iterate tidMin..tidMax and expect db entries in expectv // iterate tidMin..tidMax and expect db entries in expectv
func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv []dbEntry) { func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv []dbEntry) {
iter := fs.Iterate(tidMin, tidMax) iter := fs.Iterate(tidMin, tidMax)
fsi := iter.(*zIter) fsi, ok := iter.(*zIter)
if !ok {
_, _, err := iter.NextTxn()
t.Fatalf("iterating %v..%v: iter type is %T ; want zIter\nNextTxn gives: _, _, %v", tidMin, tidMax, iter, err) // XXX Errorf
return
}
for k := 0; ; k++ { for k := 0; ; k++ {
txnErrorf := func(format string, a ...interface{}) { txnErrorf := func(format string, a ...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