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

.

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