Commit 07b8e592 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent edee1820
...@@ -41,7 +41,7 @@ import ( ...@@ -41,7 +41,7 @@ import (
// organized as transactional log. // organized as transactional log.
type FileStorage struct { type FileStorage struct {
file *os.File file *os.File
index *fsIndex // oid -> data record position in transaction which last changed oid index *Index // oid -> data record position in transaction which last changed oid
// transaction headers for min/max transactions committed // transaction headers for min/max transactions committed
// XXX keep loaded with LoadNoStrings ? // XXX keep loaded with LoadNoStrings ?
......
...@@ -43,14 +43,14 @@ import ( ...@@ -43,14 +43,14 @@ import (
"lab.nexedi.com/kirr/neo/go/xcommon/xio" "lab.nexedi.com/kirr/neo/go/xcommon/xio"
) )
// fsIndex is Oid -> Data record position mapping used to associate Oid with // Index is Oid -> Data record position mapping used to associate Oid with
// Data record in latest transaction which changed it. // Data record in latest transaction which changed it.
type fsIndex struct { type Index struct {
*fsb.Tree *fsb.Tree
} }
func fsIndexNew() *fsIndex { func IndexNew() *Index {
return &fsIndex{fsb.TreeNew()} return &Index{fsb.TreeNew()}
} }
...@@ -86,7 +86,7 @@ func (e *IndexSaveError) Error() string { ...@@ -86,7 +86,7 @@ func (e *IndexSaveError) Error() string {
} }
// Save saves index to a writer // Save saves index to a writer
func (fsi *fsIndex) Save(topPos int64, w io.Writer) error { func (fsi *Index) Save(topPos int64, w io.Writer) error {
var err error var err error
{ {
...@@ -163,7 +163,7 @@ out: ...@@ -163,7 +163,7 @@ out:
} }
// SaveFile saves index to a file // SaveFile saves index to a file
func (fsi *fsIndex) SaveFile(topPos int64, path string) (err error) { func (fsi *Index) SaveFile(topPos int64, path string) (err error) {
f, err := os.Create(path) f, err := os.Create(path)
if err != nil { if err != nil {
return &IndexSaveError{err} return &IndexSaveError{err}
...@@ -217,7 +217,7 @@ func xint64(xv interface{}) (v int64, ok bool) { ...@@ -217,7 +217,7 @@ func xint64(xv interface{}) (v int64, ok bool) {
} }
// LoadIndex loads index from a reader // LoadIndex loads index from a reader
func LoadIndex(r io.Reader) (topPos int64, fsi *fsIndex, err error) { func LoadIndex(r io.Reader) (topPos int64, fsi *Index, err error) {
var picklePos int64 var picklePos int64
{ {
...@@ -239,7 +239,7 @@ func LoadIndex(r io.Reader) (topPos int64, fsi *fsIndex, err error) { ...@@ -239,7 +239,7 @@ func LoadIndex(r io.Reader) (topPos int64, fsi *fsIndex, err error) {
goto out goto out
} }
fsi = fsIndexNew() fsi = IndexNew()
var oidb [8]byte var oidb [8]byte
loop: loop:
...@@ -326,7 +326,7 @@ out: ...@@ -326,7 +326,7 @@ out:
} }
// LoadIndexFile loads index from a file @ path // LoadIndexFile loads index from a file @ path
func LoadIndexFile(path string) (topPos int64, fsi *fsIndex, err error) { func LoadIndexFile(path string) (topPos int64, fsi *Index, err error) {
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
return 0, nil, &IndexLoadError{path, -1, err} return 0, nil, &IndexLoadError{path, -1, err}
...@@ -343,3 +343,16 @@ func LoadIndexFile(path string) (topPos int64, fsi *fsIndex, err error) { ...@@ -343,3 +343,16 @@ func LoadIndexFile(path string) (topPos int64, fsi *fsIndex, err error) {
// NOTE no explicit bufferring needed - ogórek and LoadIndex use bufio.Reader internally // NOTE no explicit bufferring needed - ogórek and LoadIndex use bufio.Reader internally
return LoadIndex(f) return LoadIndex(f)
} }
// ----------------------------------------
// ComputeIndex builds new in-memory index for a file @ path
func Reindex(ctx context.Context, path string) (*Index, error) {
fs, err := open(path) // XXX open read-only
if err != nil {
return nil, err
}
defer fs.Close() // XXX err?
// TODO iterate - compute
}
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