Commit 3b1f7c94 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 50a09046
......@@ -67,6 +67,7 @@ import (
"context"
"fmt"
"io"
"log"
"os"
"sync"
......@@ -172,19 +173,23 @@ func Open(ctx context.Context, path string) (*FileStorage, error) {
return nil, err
}
// TODO recreate index if missing / not sane (cancel this job on ctx.Done)
index, err := LoadIndexFile(path + ".index")
err = fs.loadIndex()
if err != nil {
panic(err) // XXX err
log.Print(err)
log.Printf("%s: index recompute...", path)
fs.index, err = fs.computeIndex(ctx) // XXX better .reindex() which saves it?
if err != nil {
fs.file.Close() // XXX lclose
return nil, err
}
}
// TODO verify index sane / topPos matches
if index.TopPos != fs.txnhMax.Pos + fs.txnhMax.Len {
// XXX place
if fs.index.TopPos != fs.txnhMax.Pos + fs.txnhMax.Len {
panic("inconsistent index topPos") // XXX
}
fs.index = index
return fs, nil
}
......@@ -519,14 +524,16 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.ITxnIterator {
// --- rebuilding index ---
func (fs *FileStorage) computeIndex(ctx context.Context) (index *Index, err error) {
// XXX lock?
fsSeq := xbufio.NewSeqReaderAt(fs.file)
return BuildIndex(ctx, fsSeq, nil/*XXX no progress*/)
}
// loadIndex loads on-disk index to RAM
func (fs *FileStorage) loadIndex() (err error) {
// XXX LoadIndexFile already contains "%s: index load"
// XXX lock?
defer xerr.Contextf(&err, "%s: index load", fs.file.Name())
defer xerr.Contextf(&err, "%s", fs.file.Name())
index, err := LoadIndexFile(fs.file.Name() + ".index")
if err != nil {
......
......@@ -301,7 +301,7 @@ Dump transactions from a FileStorage
func dumpMain(argv []string) {
var verbose bool
flags := flag.FlagSet{Usage: func() { tailUsage(os.Stderr) }}
flags := flag.FlagSet{Usage: func() { dumpUsage(os.Stderr) }}
flags.Init("", flag.ExitOnError)
flags.BoolVar(&verbose, "v", verbose, "verbose mode")
flags.Parse(argv[1:])
......
......@@ -117,7 +117,7 @@ func reindexMain(argv []string) {
err = Reindex(context.Background(), storPath, progress)
if !quiet {
if !quiet && lastp != nil {
// (re-)display last update in case no progress was displayed so far
display(lastp)
fmt.Println()
......@@ -218,7 +218,7 @@ func verifyIdxMain(argv []string) {
err := VerifyIndexFor(context.Background(), storPath, ntxn, progress)
if !quiet {
if !quiet && lastp != nil {
// (re-)display last update in case no progress was displayed so far
display(lastp)
fmt.Println()
......
......@@ -215,7 +215,7 @@ type IndexLoadError struct {
func (e *IndexLoadError) Error() string {
s := "index load: "
if e.Filename != "" {
if e.Filename != "" && e.Pos != -1 /* not yet got to decoding - .Err is ~ os.PathError */ {
s += e.Filename + ": "
}
if e.Pos != -1 {
......
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