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
adea442b
Commit
adea442b
authored
Feb 22, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
7904412f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
7 deletions
+52
-7
t/neo/storage/fs1/filestorage.go
t/neo/storage/fs1/filestorage.go
+14
-4
t/neo/storage/fs1/filestorage_test.go
t/neo/storage/fs1/filestorage_test.go
+37
-2
t/neo/zodb/zodb.go
t/neo/zodb/zodb.go
+1
-1
No files found.
t/neo/storage/fs1/filestorage.go
View file @
adea442b
...
@@ -34,6 +34,7 @@ type FileStorage struct {
...
@@ -34,6 +34,7 @@ type FileStorage struct {
var
_
zodb
.
IStorage
=
(
*
FileStorage
)(
nil
)
var
_
zodb
.
IStorage
=
(
*
FileStorage
)(
nil
)
// TxnHeader represents header of a transaction record
type
TxnHeader
struct
{
type
TxnHeader
struct
{
Tid
zodb
.
Tid
Tid
zodb
.
Tid
RecLenm8
uint64
RecLenm8
uint64
...
@@ -52,9 +53,9 @@ type TxnHeader struct {
...
@@ -52,9 +53,9 @@ type TxnHeader struct {
type
DataHeader
struct
{
type
DataHeader
struct
{
Oid
zodb
.
Oid
Oid
zodb
.
Oid
Tid
zodb
.
Tid
Tid
zodb
.
Tid
PrevDataRecPos
int64
// previous-record file-position
PrevDataRecPos
int64
// previous-record file-position
XXX name
TxnPos
int64
// position of transaction record this data record belongs to
TxnPos
int64
// position of transaction record this data record belongs to
_
uint16
// 2-bytes with zero values. (Was version length.)
//
_ uint16 // 2-bytes with zero values. (Was version length.)
DataLen
uint64
// length of following data. if 0 -> following = 8 bytes backpointer XXX -> int64 too ?
DataLen
uint64
// length of following data. if 0 -> following = 8 bytes backpointer XXX -> int64 too ?
// if backpointer == 0 -> oid deleted
// if backpointer == 0 -> oid deleted
//Data []byte
//Data []byte
...
@@ -120,11 +121,20 @@ func NewFileStorage(path string) (*FileStorage, error) {
...
@@ -120,11 +121,20 @@ func NewFileStorage(path string) (*FileStorage, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
// XXX err more context ?
return
nil
,
err
// XXX err more context ?
}
}
// TODO read file header
// TODO read file header
//Read(f, 4) != "FS21" -> invalid header
//Read(f, 4) != "FS21" -> invalid header
return
&
FileStorage
{
f
:
f
},
nil
// TODO read/recreate index
// TODO recreate index if missing / not sane
// TODO verify index sane / topPos matches
topPos
,
index
,
err
:=
LoadIndexFile
(
path
+
".index"
)
if
err
!=
nil
{
panic
(
err
)
// XXX err
}
_
=
topPos
return
&
FileStorage
{
f
:
f
,
index
:
index
},
nil
}
}
...
...
t/neo/storage/fs1/filestorage_test.go
View file @
adea442b
...
@@ -2,6 +2,14 @@
...
@@ -2,6 +2,14 @@
package
fs1
package
fs1
import
(
"bytes"
"strconv"
"testing"
"../../zodb"
)
// one entry inside transaction
// one entry inside transaction
type
txnEntry
struct
{
type
txnEntry
struct
{
header
DataHeader
header
DataHeader
...
@@ -10,6 +18,33 @@ type txnEntry struct {
...
@@ -10,6 +18,33 @@ type txnEntry struct {
type
dbEntry
struct
{
type
dbEntry
struct
{
header
TxnHeader
header
TxnHeader
// TODO user, desc, ext
entryv
[]
txnEntry
Recordv
[]
txnEntry
}
func
TestLoad
(
t
*
testing
.
T
)
{
fs
,
err
:=
NewFileStorage
(
"testdata/1.fs"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
_
,
dbe
:=
range
_1fs_dbEntryv
{
for
_
,
txe
:=
range
dbe
.
entryv
{
txh
:=
txe
.
header
if
txh
.
DataLen
==
0
{
continue
// FIXME skipping backpointers
}
xid
:=
zodb
.
Xid
{
zodb
.
XTid
{
txh
.
Tid
,
false
},
txh
.
Oid
}
// loadSerial
data
,
tid
,
err
:=
fs
.
Load
(
xid
)
if
err
!=
nil
{
t
.
Errorf
(
"load %v: %v"
,
xid
,
err
)
}
if
tid
!=
txh
.
Tid
{
t
.
Errorf
(
"load %v: returned tid unexpected: %v"
,
xid
)
}
if
!
bytes
.
Equal
(
data
,
txe
.
data
)
{
t
.
Errorf
(
"load %v: different data:
\n
have: %s
\n
want: %s"
,
xid
,
strconv
.
Quote
(
string
(
data
)),
strconv
.
Quote
(
string
(
txe
.
data
)))
}
}
}
}
}
t/neo/zodb/zodb.go
View file @
adea442b
...
@@ -58,7 +58,7 @@ func bint(b bool) int {
...
@@ -58,7 +58,7 @@ func bint(b bool) int {
func
(
xtid
XTid
)
String
()
string
{
func
(
xtid
XTid
)
String
()
string
{
// XXX also print "tid:" prefix ?
// XXX also print "tid:" prefix ?
return
fmt
.
Sprintf
(
"%c%v"
,
"=<"
[
bint
(
xtid
.
TidBefore
)],
xtid
)
return
fmt
.
Sprintf
(
"%c%v"
,
"=<"
[
bint
(
xtid
.
TidBefore
)],
xtid
.
Tid
)
}
}
func
(
xid
Xid
)
String
()
string
{
func
(
xid
Xid
)
String
()
string
{
...
...
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