Commit c5b00c4b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 40e2fe99
...@@ -1258,16 +1258,18 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator { ...@@ -1258,16 +1258,18 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
// computeIndex builds new in-memory index for FileStorage // computeIndex builds new in-memory index for FileStorage
// XXX naming // XXX naming
// XXX in case of error return partially built index? (index has .TopPos until which it covers the data)
func (fs *FileStorage) computeIndex(ctx context.Context) (index *Index, err error) { func (fs *FileStorage) computeIndex(ctx context.Context) (index *Index, err error) {
defer xerr.Contextf(&err, "%s: reindex", fs.file.Name()) defer xerr.Contextf(&err, "%s: reindex", fs.file.Name())
index = IndexNew() index = IndexNew()
index.TopPos = txnValidFrom index.TopPos = txnValidFrom
// similar to Iterate but we know we start from the beginning and do // XXX another way to compute index: iterate backwards - then
// not want to load actual data - only data headers. // 1. index entry for oid is ready right after we see oid the first time
fsSeq := xbufio.NewSeqReaderAt(fs.file) // 2. we can be sure we build the whole index if we saw all oids
fsSeq := xbufio.NewSeqReaderAt(fs.file)
it := Iterate(fsSeq, index.TopPos, IterForward) it := Iterate(fsSeq, index.TopPos, IterForward)
loop: loop:
...@@ -1312,6 +1314,7 @@ loop: ...@@ -1312,6 +1314,7 @@ loop:
// loadIndex loads on-disk index to RAM // loadIndex loads on-disk index to RAM
func (fs *FileStorage) loadIndex() error { func (fs *FileStorage) loadIndex() error {
// XXX lock? // XXX lock?
defer xerr.Contextf(&err, "%s: index load", fs.file.Name())
index, err := LoadIndexFile(fs.file.Name() + ".index") index, err := LoadIndexFile(fs.file.Name() + ".index")
if err != nil { if err != nil {
...@@ -1329,10 +1332,20 @@ func (fs *FileStorage) loadIndex() error { ...@@ -1329,10 +1332,20 @@ func (fs *FileStorage) loadIndex() error {
} }
// saveIndex flushes in-RAM index to disk // saveIndex flushes in-RAM index to disk
func (fs *FileStorage) saveIndex() error { func (fs *FileStorage) saveIndex() (err error) {
// XXX lock? // XXX lock?
defer xerr.Contextf(&err, "%s: index save", fs.file.Name())
idxname := fs.file.Name() + ".index"
idxtmp := idxname + ".index_tmp"
err := fs.index.SaveFile(idxtmp)
if err != nil {
return err
}
// XXX fsync here?
err := fs.index.SaveFile(fs.file.Name() + ".index") err = os.Rename(idxtmp, idxname)
return err return err
} }
......
...@@ -180,9 +180,7 @@ func (fsi *Index) SaveFile(path string) (err error) { ...@@ -180,9 +180,7 @@ func (fsi *Index) SaveFile(path string) (err error) {
} }
}() }()
err = fsi.Save(f) return fsi.Save(f)
return
} }
// IndexLoadError is the error type returned by index load routines // IndexLoadError is the error type returned by index load routines
......
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