Fix db lookup for wal file

This commit is contained in:
Ben Johnson
2020-11-11 16:45:02 -07:00
parent 231b41b29f
commit bbcdb30cb3
3 changed files with 25 additions and 2 deletions

8
db.go
View File

@@ -244,7 +244,13 @@ func (db *DB) shadowWALExists() (bool, error) {
// contents of the database page.
func (db *DB) recoverShadowWALOnly() error {
db.logger.Printf("recovering: shadow WAL only")
panic("TODO")
// TODO: Verify last page in shadow WAL matches data in DB.
db.processedWALByteN = 0
db.pendingWALByteN = 0
return nil
}
// recoverRealAndShadowWALs verifies the last page of the real & shadow WALs match.

View File

@@ -1,9 +1,11 @@
package litestream
import (
"fmt"
"log"
"os"
"path/filepath"
"sort"
"sync"
"bazil.org/fuse/fs"
@@ -71,12 +73,24 @@ func (f *FileSystem) Open() error {
// DB returns the DB object associated with path.
func (f *FileSystem) DB(path string) *DB {
fmt.Println("dbg/dbs", path, "--", f.DBPaths())
f.mu.RLock()
defer f.mu.RUnlock()
db := f.dbs[path]
return db
}
// DBPaths returns a sorted list of all paths managed by the file system.
func (f *FileSystem) DBPaths() []string {
a := make([]string, 0, len(f.dbs))
for k := range f.dbs {
a = append(a, k)
}
sort.Strings(a)
return a
}
// OpenDB initializes a DB for a given path.
func (f *FileSystem) OpenDB(path string) error {
f.mu.Lock()

View File

@@ -64,9 +64,12 @@ func (n *Node) IsWAL() bool {
// DB returns the DB object associated with the node, if any.
// If node points to a "-wal" file then the associated DB is returned.
func (n *Node) DB() *DB {
if strings.HasPrefix(n.path, sqlite.WALSuffix) {
println("dbg/node.db", n.path, strings.HasPrefix(n.path, sqlite.WALSuffix))
if strings.HasSuffix(n.path, sqlite.WALSuffix) {
println("dbg/node.db.trim", n.path, strings.TrimSuffix(n.path, sqlite.WALSuffix))
return n.fs.DB(strings.TrimSuffix(n.path, sqlite.WALSuffix))
}
println("dbg/node.db.other", n.path)
return n.fs.DB(n.path)
}