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
2ef35dde
Commit
2ef35dde
authored
Jul 28, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
230cf05d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
42 deletions
+70
-42
go/zodb/storage/fs1/filestorage.go
go/zodb/storage/fs1/filestorage.go
+2
-6
go/zodb/storage/fs1/fs1tools/index.go
go/zodb/storage/fs1/fs1tools/index.go
+39
-25
go/zodb/storage/fs1/index.go
go/zodb/storage/fs1/index.go
+26
-11
go/zodb/zodbtools/driver.go
go/zodb/zodbtools/driver.go
+3
-0
No files found.
go/zodb/storage/fs1/filestorage.go
View file @
2ef35dde
...
@@ -524,17 +524,13 @@ func (fs *FileStorage) saveIndex() (err error) {
...
@@ -524,17 +524,13 @@ func (fs *FileStorage) saveIndex() (err error) {
// XXX lock?
// XXX lock?
defer
xerr
.
Contextf
(
&
err
,
"%s: index save"
,
fs
.
file
.
Name
())
defer
xerr
.
Contextf
(
&
err
,
"%s: index save"
,
fs
.
file
.
Name
())
idxname
:=
fs
.
file
.
Name
()
+
".index"
err
=
fs
.
index
.
SaveFile
(
fs
.
file
.
Name
()
+
".index"
)
idxtmp
:=
idxname
+
".index_tmp"
err
=
fs
.
index
.
SaveFile
(
idxtmp
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// XXX fsync here?
// XXX fsync here?
return
nil
err
=
os
.
Rename
(
idxtmp
,
idxname
)
return
err
}
}
// IndexCorruptError is the error returned when index verification fails
// IndexCorruptError is the error returned when index verification fails
...
...
go/zodb/storage/fs1/fs1tools/index.go
View file @
2ef35dde
...
@@ -32,54 +32,38 @@ import (
...
@@ -32,54 +32,38 @@ import (
// Reindex rebuilds index for FileStorage file @ path
// Reindex rebuilds index for FileStorage file @ path
func
Reindex
(
path
string
)
error
{
func
Reindex
(
path
string
)
error
{
// XXX
open read-only
// XXX
lock path.lock ?
fs
,
err
:=
fs1
.
Open
(
context
.
Background
(),
path
)
// XXX , fs1.OpenWithoutIndex
)
index
,
err
:=
fs1
.
BuildIndexForFile
(
context
.
Background
(),
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
// XXX err ctx
return
err
}
}
defer
fs
.
Close
()
// XXX err
err
=
fs
.
Reindex
(
nil
)
return
err
// XXX ok?
}
// VerifyIndexFor verifies that on-disk index for FileStorage file @ path is correct
err
=
index
.
SaveFile
(
path
+
".index"
)
func
VerifyIndexFor
(
path
string
)
error
{
// XXX open read-only
fs
,
err
:=
fs1
.
Open
(
context
.
Background
(),
path
)
// XXX , 0)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
// XXX err ctx
return
err
// XXX err ctx
}
}
defer
fs
.
Close
()
// XXX err
err
=
fs
.
VerifyIndex
(
nil
)
return
nil
return
err
//fs.Index()
//fs.ComputeIndex
}
}
// ----------------------------------------
const
reindexSummary
=
"rebuild database index"
const
reindexSummary
=
"XXX"
// XXX
func
reindexUsage
(
w
io
.
Writer
)
{
func
reindexUsage
(
w
io
.
Writer
)
{
fmt
.
Fprintf
(
w
,
fmt
.
Fprintf
(
w
,
`Usage: fs1 reindex [options] <storage>
`Usage: fs1 reindex [options] <storage>
Dump transactions from a FileStorage in reverse order XXX
Rebuild FileStorage index
<storage> is a path to FileStorage
<storage> is a path to FileStorage
options:
options:
-h --help this help text.
-h --help this help text.
-verify verify that existing index is correct; don't overwrite it
`
)
`
,
ntxnDefault
)
}
}
func
reindexMain
(
argv
[]
string
)
{
func
reindexMain
(
argv
[]
string
)
{
flags
:=
flag
.
FlagSet
{
Usage
:
func
()
{
reindexUsage
(
os
.
Stderr
)
}}
flags
:=
flag
.
FlagSet
{
Usage
:
func
()
{
reindexUsage
(
os
.
Stderr
)
}}
flags
.
Init
(
""
,
flag
.
ExitOnError
)
flags
.
Init
(
""
,
flag
.
ExitOnError
)
// XXX -verify
flags
.
Parse
(
argv
[
1
:
])
flags
.
Parse
(
argv
[
1
:
])
argv
=
flags
.
Args
()
argv
=
flags
.
Args
()
...
@@ -95,5 +79,35 @@ func reindexMain(argv []string) {
...
@@ -95,5 +79,35 @@ func reindexMain(argv []string) {
}
}
}
}
// ----------------------------------------
// TODO verify-index
// TODO verify-index
// TODO verify-index -quick (only small sanity check)
// TODO verify-index -quick (only small sanity check)
// VerifyIndexFor verifies that on-disk index for FileStorage file @ path is correct
func
VerifyIndexFor
(
path
string
)
error
{
panic
(
"TODO"
)
/*
// XXX open read-only
fs, err := fs1.Open(context.Background(), path) // XXX , 0)
if err != nil {
return nil // XXX err ctx
}
defer fs.Close() // XXX err
err = fs.VerifyIndex(nil)
return err
//fs.Index()
//fs.ComputeIndex
*/
}
const
verifyIdxSummary
=
"verify database index"
func
verifyIdxUsage
(
w
io
.
Writer
)
{
panic
(
"TODO"
)
// XXX
}
func
verifyIdxMaxin
(
argv
[]
string
)
{
panic
(
"TODO"
)
// XXX
}
go/zodb/storage/fs1/index.go
View file @
2ef35dde
...
@@ -26,8 +26,10 @@ import (
...
@@ -26,8 +26,10 @@ import (
"encoding/binary"
"encoding/binary"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"math/big"
"math/big"
"os"
"os"
"path/filepath"
"strconv"
"strconv"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb"
...
@@ -169,22 +171,35 @@ out:
...
@@ -169,22 +171,35 @@ out:
}
}
// SaveFile saves index to a file @ path
// SaveFile saves index to a file @ path
func
(
fsi
*
Index
)
SaveFile
(
path
string
)
(
err
error
)
{
//
f
,
err
:=
os
.
Create
(
path
)
// Index data is first saved to a temporary file and when complete the
// temporary is renamed to be at requested path. This way file @ path will be
// updated only with complete index data.
func
(
fsi
*
Index
)
SaveFile
(
path
string
)
error
{
dir
,
name
:=
filepath
.
Dir
(
path
),
filepath
.
Base
(
path
)
f
,
err
:=
ioutil
.
TempFile
(
dir
,
name
+
".tmp"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
&
IndexSaveError
{
err
}
return
&
IndexSaveError
{
err
}
// XXX needed?
}
}
// TODO use buffering for f (ogórek does not buffer itself on encoding)
// TODO use buffering for f (ogórek does not buffer itself on encoding)
err1
:=
fsi
.
Save
(
f
)
defer
func
()
{
err2
:=
f
.
Close
()
err2
:=
f
.
Close
()
if
err1
!=
nil
||
err2
!=
nil
{
if
err2
!=
nil
&&
err
==
nil
{
os
.
Remove
(
f
.
Name
())
err
=
&
IndexSaveError
{
err2
}
err
=
err1
if
err
==
nil
{
err
=
&
IndexSaveError
{
err2
}
// XXX needed?
}
}
}()
return
err
}
err
=
os
.
Rename
(
f
.
Name
(),
path
)
if
err
!=
nil
{
return
&
IndexSaveError
{
err
}
// XXX needed?
}
return
fsi
.
Save
(
f
)
return
nil
}
}
// IndexLoadError is the error type returned by index load routines
// IndexLoadError is the error type returned by index load routines
...
@@ -507,7 +522,7 @@ func BuildIndex(ctx context.Context, r io.ReaderAt) (*Index, error) {
...
@@ -507,7 +522,7 @@ func BuildIndex(ctx context.Context, r io.ReaderAt) (*Index, error) {
func
BuildIndexForFile
(
ctx
context
.
Context
,
path
string
)
(
index
*
Index
,
err
error
)
{
func
BuildIndexForFile
(
ctx
context
.
Context
,
path
string
)
(
index
*
Index
,
err
error
)
{
f
,
err
:=
os
.
Open
(
path
)
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
IndexNew
(),
err
return
IndexNew
(),
err
// XXX add err ctx?
}
}
defer
func
()
{
defer
func
()
{
...
...
go/zodb/zodbtools/driver.go
View file @
2ef35dde
...
@@ -121,6 +121,8 @@ Usage:
...
@@ -121,6 +121,8 @@ Usage:
The commands are:
The commands are:
`
,
prog
.
Summary
,
prog
.
Name
)
`
,
prog
.
Summary
,
prog
.
Name
)
// XXX 11 -> max width of cmd.Name
for
_
,
cmd
:=
range
prog
.
Commands
{
for
_
,
cmd
:=
range
prog
.
Commands
{
fmt
.
Fprintf
(
w
,
"
\t
%-11s %s
\n
"
,
cmd
.
Name
,
cmd
.
Summary
)
fmt
.
Fprintf
(
w
,
"
\t
%-11s %s
\n
"
,
cmd
.
Name
,
cmd
.
Summary
)
}
}
...
@@ -138,6 +140,7 @@ Additional help topics:
...
@@ -138,6 +140,7 @@ Additional help topics:
`
)
`
)
// XXX 11 -> max width of topic.Name
for
_
,
topic
:=
range
prog
.
HelpTopics
{
for
_
,
topic
:=
range
prog
.
HelpTopics
{
fmt
.
Fprintf
(
w
,
"
\t
%-11s %s
\n
"
,
topic
.
Name
,
topic
.
Summary
)
fmt
.
Fprintf
(
w
,
"
\t
%-11s %s
\n
"
,
topic
.
Name
,
topic
.
Summary
)
}
}
...
...
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