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
eb3028a1
Commit
eb3028a1
authored
Mar 01, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
0f5cc13f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
12 deletions
+26
-12
t/neo/storage/fs1/filestorage.go
t/neo/storage/fs1/filestorage.go
+26
-12
No files found.
t/neo/storage/fs1/filestorage.go
View file @
eb3028a1
...
...
@@ -18,7 +18,7 @@ package fs1
import
(
"encoding/binary"
"errors"
//
"errors"
"fmt"
"io"
"os"
...
...
@@ -131,7 +131,16 @@ func (dh *DataHeader) err(subj string, err error) *ErrDataRecord {
return
&
ErrDataRecord
{
dh
.
Pos
,
subj
,
err
}
}
// TODO errf, decodeErr
// errf is syntatic shortcut for err and fmt.Errorf
func
(
dh
*
DataHeader
)
errf
(
subj
,
format
string
,
a
...
interface
{})
*
ErrDataRecord
{
return
dh
.
err
(
subj
,
fmt
.
Errorf
(
format
,
a
...
))
}
// TODO decodeErr
func
(
dh
*
DataHeader
)
bug
(
format
string
,
a
...
interface
{})
{
panic
(
dh
.
errf
(
"bug"
,
format
,
a
...
))
}
// // XXX -> zodb?
// var ErrVersionNonZero = errors.New("non-zero version")
...
...
@@ -163,10 +172,10 @@ const (
//
// rules for Len/LenPrev returns:
// Len == 0 transaction header could not be read
// Len == -1 EOF
is there when reading
forward
// Len == -1 EOF forward
// Len >= TxnHeaderFixSize transaction was read normally
//
// LenPrev == 0
error reading
// LenPrev == 0
prev record length could not be read
// LenPrev == -1 EOF backward
// LenPrev >= TxnHeaderFixSize LenPrev was read/checked normally
func
(
txnh
*
TxnHeader
)
Load
(
r
io
.
ReaderAt
/* *os.File */
,
pos
int64
,
flags
TxnLoadFlags
)
error
{
...
...
@@ -317,32 +326,37 @@ func (txnh *TxnHeader) LoadPrev(r io.ReaderAt, flags TxnLoadFlags) error {
// - TODO
func
(
txnh
*
TxnHeader
)
LoadNext
(
r
io
.
ReaderAt
,
flags
TxnLoadFlags
)
error
{
lenCur
:=
txnh
.
Len
posCur
:=
txnh
.
Pos
switch
lenCur
{
case
0
:
tx
hn
.
bug
(
"LoadNext() when .Len == error"
)
tx
nh
.
bug
(
"LoadNext() when .Len == error"
)
case
-
1
:
return
io
.
EOF
}
err
:=
txnh
.
Load
(
r
,
txnh
.
Pos
+
lenCur
,
flags
)
// TODO XXX
if
txnh
.
LenPrev
!=
lenCur
{
}
if
err
!=
nil
{
// before checking loading error for next txn, let's first check redundant length
// NOTE also: err could be EOF
if
txnh
.
LenPrev
!=
0
&&
txnh
.
LenPrev
!=
lenCur
{
err
:=
txnh
.
decodeErr
(
"head/tail lengths mismatch: %v, %v"
,
lenCur
,
txnh
.
LenPrev
)
err
.
Pos
=
posCur
// position of txn for which we discovered problem
return
err
}
return
err
}
// decode reads and decodes data record header
func
(
dh
*
DataHeader
)
load
(
r
io
.
ReaderAt
/* *os.File */
,
pos
int64
,
tmpBuf
*
[
DataHeaderSize
]
byte
)
error
{
dh
.
Pos
=
pos
if
pos
<
dataValidFrom
{
panic
(
&
ErrDataRecord
{
pos
,
"read"
,
bugPositionInvalid
}
)
dh
.
bug
(
"Load() on invalid position"
)
}
dh
.
Pos
=
pos
_
,
err
:=
r
.
ReadAt
(
tmpBuf
[
:
],
pos
)
if
err
!=
nil
{
return
&
ErrDataRecord
{
pos
,
"read"
,
noEOF
(
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