Commit e644777b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4a57fffd
......@@ -21,6 +21,7 @@ package fs1
// index for quickly finding oid -> latest data record
import (
"bufio"
"bytes"
"context"
"encoding/binary"
......@@ -182,14 +183,17 @@ func (fsi *Index) SaveFile(path string) error {
return &IndexSaveError{err} // XXX needed?
}
// TODO use buffering for f (ogórek does not buffer itself on encoding)
err1 := fsi.Save(f)
err2 := f.Close()
if err1 != nil || err2 != nil {
// use buffering for f (ogórek does not buffer itself on encoding)
fb := bufio.NewWriter(f)
err1 := fsi.Save(fb)
err2 := fb.Flush()
err3 := f.Close()
if err1 != nil || err2 != nil || err3 != nil {
os.Remove(f.Name())
err = err1
if err == nil {
err = &IndexSaveError{err2} // XXX needed?
err = &IndexSaveError{xerr.First(err2, err3)} // XXX needed?
}
return err
}
......
......@@ -221,7 +221,7 @@ func TestIndexSaveToPy(t *testing.T) {
}
func TestIndexBuildVerify(t *testing.T) {
index, err := BuildIndexForFile(context.Background(), "testdata/1.fs")
index, err := BuildIndexForFile(context.Background(), "testdata/1.fs", nil)
if err != nil {
t.Fatalf("index build: %v", err)
}
......@@ -230,14 +230,14 @@ func TestIndexBuildVerify(t *testing.T) {
t.Fatal("computed index differ from expected")
}
_, err = index.VerifyForFile(context.Background(), "testdata/1.fs", -1)
_, err = index.VerifyForFile(context.Background(), "testdata/1.fs", -1, nil)
if err != nil {
t.Fatalf("index verify: %v", err)
}
pos0, _ := index.Get(0)
index.Set(0, pos0 + 1)
_, err = index.VerifyForFile(context.Background(), "testdata/1.fs", -1)
_, err = index.VerifyForFile(context.Background(), "testdata/1.fs", -1, nil)
if err == nil {
t.Fatalf("index verify: expected error after tweak")
}
......@@ -254,6 +254,24 @@ func BenchmarkIndexLoad(b *testing.B) {
}
}
func BenchmarkIndexSave(b *testing.B) {
// FIXME small testdata/1.fs is not representative for benchmarks
index, err := LoadIndexFile("testdata/1.fs.index")
if err != nil {
b.Fatal(err)
}
workdir := xworkdir(b)
b.ResetTimer()
for i := 0; i < b.N; i++ {
err = index.SaveFile(workdir + "/1.fs.index")
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkIndexGet(b *testing.B) {
// FIXME small testdata/1.fs is not representative for benchmarks
fsi, err := LoadIndexFile("testdata/1.fs.index")
......@@ -304,7 +322,7 @@ func needZODBPy(t *testing.T) {
}
// create temp dir inside workRoot
func xworkdir(t *testing.T) string {
func xworkdir(t testing.TB) string {
work, err := ioutil.TempDir(workRoot, "")
if err != nil {
t.Fatal(err)
......
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