Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
e644777b
Commit
e644777b
authored
Jul 31, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
4a57fffd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
9 deletions
+31
-9
go/zodb/storage/fs1/index.go
go/zodb/storage/fs1/index.go
+9
-5
go/zodb/storage/fs1/index_test.go
go/zodb/storage/fs1/index_test.go
+22
-4
No files found.
go/zodb/storage/fs1/index.go
View file @
e644777b
...
@@ -21,6 +21,7 @@ package fs1
...
@@ -21,6 +21,7 @@ package fs1
// index for quickly finding oid -> latest data record
// index for quickly finding oid -> latest data record
import
(
import
(
"bufio"
"bytes"
"bytes"
"context"
"context"
"encoding/binary"
"encoding/binary"
...
@@ -182,14 +183,17 @@ func (fsi *Index) SaveFile(path string) error {
...
@@ -182,14 +183,17 @@ func (fsi *Index) SaveFile(path string) error {
return
&
IndexSaveError
{
err
}
// XXX needed?
return
&
IndexSaveError
{
err
}
// XXX needed?
}
}
// TODO use buffering for f (ogórek does not buffer itself on encoding)
// use buffering for f (ogórek does not buffer itself on encoding)
err1
:=
fsi
.
Save
(
f
)
fb
:=
bufio
.
NewWriter
(
f
)
err2
:=
f
.
Close
()
if
err1
!=
nil
||
err2
!=
nil
{
err1
:=
fsi
.
Save
(
fb
)
err2
:=
fb
.
Flush
()
err3
:=
f
.
Close
()
if
err1
!=
nil
||
err2
!=
nil
||
err3
!=
nil
{
os
.
Remove
(
f
.
Name
())
os
.
Remove
(
f
.
Name
())
err
=
err1
err
=
err1
if
err
==
nil
{
if
err
==
nil
{
err
=
&
IndexSaveError
{
err2
}
// XXX needed?
err
=
&
IndexSaveError
{
xerr
.
First
(
err2
,
err3
)
}
// XXX needed?
}
}
return
err
return
err
}
}
...
...
go/zodb/storage/fs1/index_test.go
View file @
e644777b
...
@@ -221,7 +221,7 @@ func TestIndexSaveToPy(t *testing.T) {
...
@@ -221,7 +221,7 @@ func TestIndexSaveToPy(t *testing.T) {
}
}
func
TestIndexBuildVerify
(
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
{
if
err
!=
nil
{
t
.
Fatalf
(
"index build: %v"
,
err
)
t
.
Fatalf
(
"index build: %v"
,
err
)
}
}
...
@@ -230,14 +230,14 @@ func TestIndexBuildVerify(t *testing.T) {
...
@@ -230,14 +230,14 @@ func TestIndexBuildVerify(t *testing.T) {
t
.
Fatal
(
"computed index differ from expected"
)
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
{
if
err
!=
nil
{
t
.
Fatalf
(
"index verify: %v"
,
err
)
t
.
Fatalf
(
"index verify: %v"
,
err
)
}
}
pos0
,
_
:=
index
.
Get
(
0
)
pos0
,
_
:=
index
.
Get
(
0
)
index
.
Set
(
0
,
pos0
+
1
)
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
{
if
err
==
nil
{
t
.
Fatalf
(
"index verify: expected error after tweak"
)
t
.
Fatalf
(
"index verify: expected error after tweak"
)
}
}
...
@@ -254,6 +254,24 @@ func BenchmarkIndexLoad(b *testing.B) {
...
@@ -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
)
{
func
BenchmarkIndexGet
(
b
*
testing
.
B
)
{
// FIXME small testdata/1.fs is not representative for benchmarks
// FIXME small testdata/1.fs is not representative for benchmarks
fsi
,
err
:=
LoadIndexFile
(
"testdata/1.fs.index"
)
fsi
,
err
:=
LoadIndexFile
(
"testdata/1.fs.index"
)
...
@@ -304,7 +322,7 @@ func needZODBPy(t *testing.T) {
...
@@ -304,7 +322,7 @@ func needZODBPy(t *testing.T) {
}
}
// create temp dir inside workRoot
// create temp dir inside workRoot
func
xworkdir
(
t
*
testing
.
T
)
string
{
func
xworkdir
(
t
testing
.
TB
)
string
{
work
,
err
:=
ioutil
.
TempDir
(
workRoot
,
""
)
work
,
err
:=
ioutil
.
TempDir
(
workRoot
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment