Commit 459b6060 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent bbe228d8
...@@ -1046,17 +1046,19 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator { ...@@ -1046,17 +1046,19 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
return &Iter return &Iter
} }
// ComputeIndex builds new in-memory index for FileStorage // ComputeIndex from scratch builds new in-memory index for FileStorage
func (fs *FileStorage) ComputeIndex(ctx context.Context, path string) (topPos int64, index *Index, err error) { // XXX naming
topPos = txnValidFrom func (fs *FileStorage) ComputeIndex(ctx context.Context) (index *Index, err error) {
// XXX handle ctx cancel
index = IndexNew() index = IndexNew()
index.TopPos = txnValidFrom
// similar to Iterate but we know we start from the beginning and do // similar to Iterate but we know we start from the beginning and do
// not 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 // pre-setup txnh so that txnh.LoadNext starts loading from the beginning of file
txnh := &TxnHeader{Pos: 0, Len: topPos, TxnInfo: zodb.TxnInfo{Tid: 0}} txnh := &TxnHeader{Pos: 0, Len: index.TopPos, TxnInfo: zodb.TxnInfo{Tid: 0}}
dh := &DataHeader{} dh := &DataHeader{}
loop: loop:
...@@ -1067,7 +1069,7 @@ loop: ...@@ -1067,7 +1069,7 @@ loop:
break break
} }
topPos = txnh.Pos + txnh.Len index.TopPos = txnh.Pos + txnh.Len
// first data iteration will go to first data record // first data iteration will go to first data record
dh.Pos = txnh.DataPos() dh.Pos = txnh.DataPos()
...@@ -1088,7 +1090,7 @@ loop: ...@@ -1088,7 +1090,7 @@ loop:
} }
if err != nil { if err != nil {
return 0, nil, err return nil, err
} }
return topPos, index, nil return index, nil
} }
...@@ -277,6 +277,25 @@ func TestIterate(t *testing.T) { ...@@ -277,6 +277,25 @@ func TestIterate(t *testing.T) {
testIterate(t, fs, 0, zodb.TidMax, _1fs_dbEntryv[:]) testIterate(t, fs, 0, zodb.TidMax, _1fs_dbEntryv[:])
} }
func TestComputeIndex(t *testing.T) {
fs := xfsopen(t, "testdata/1.fs") // TODO open ro
defer exc.XRun(fs.Close)
index, err := fs.ComputeIndex(context.TODO())
if err != nil {
t.Fatal(err)
}
indexOk, err := LoadIndexFile("testdata/1.fs.index")
if err != nil {
t.Fatal(err)
}
if !index.Equal(indexOk) {
t.Fatal("computed index differ from expected")
}
}
func BenchmarkIterate(b *testing.B) { func BenchmarkIterate(b *testing.B) {
fs := xfsopen(b, "testdata/1.fs") // TODO open ro fs := xfsopen(b, "testdata/1.fs") // TODO open ro
defer exc.XRun(fs.Close) defer exc.XRun(fs.Close)
......
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