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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
neo
Commits
3f5969b5
Commit
3f5969b5
authored
Mar 23, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
2cd4dc5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
14 deletions
+17
-14
t/neo/storage/fs1/xbufio.go
t/neo/storage/fs1/xbufio.go
+10
-12
t/neo/storage/fs1/xbufio_test.go
t/neo/storage/fs1/xbufio_test.go
+7
-2
No files found.
t/neo/storage/fs1/xbufio.go
View file @
3f5969b5
...
...
@@ -38,27 +38,26 @@ func NewSeqBufReaderSize(r io.ReaderAt, size int) *SeqBufReader {
func
(
sb
*
SeqBufReader
)
readFromBuf
(
p
[]
byte
,
pos
int64
)
(
int
,
[]
byte
,
int64
)
{
n
:=
0
switch
{
// use buffered data: start + forward
case
pos
>=
sb
.
pos
&&
pos
<
sb
.
pos
+
int64
(
len
(
sb
.
buf
))
:
if
sb
.
pos
<=
pos
&&
pos
<
sb
.
pos
+
int64
(
len
(
sb
.
buf
))
{
n
=
copy
(
p
,
sb
.
buf
[
pos
-
sb
.
pos
:
])
// NOTE len(p) can be < len(sb[copyPos:])
p
=
p
[
n
:
]
pos
+=
int64
(
n
)
// use buffered data: tail + backward
case
pos
+
int64
(
len
(
p
))
>
sb
.
pos
&&
pos
+
int64
(
len
(
p
))
<=
sb
.
pos
+
int64
(
len
(
sb
.
buf
))
:
// here we know pos is < sb.pos
}
else
if
posAfter
:=
pos
+
int64
(
len
(
p
));
len
(
p
)
!=
0
&&
sb
.
pos
<
posAfter
&&
posAfter
<=
sb
.
pos
+
int64
(
len
(
sb
.
buf
))
{
// here we know pos < sb.pos
//
// proof: consider if pos >= sb.pos.
// Then from `pos + len(p) > sb.pos` above it follows that:
// len(p) = 0 only if pos > sb.pos
// Then from `pos <= sb.pos + len(sb.buf) - len(p)` above it follow that:
//
pos < sb.pos + len(sb.buf) (NOTE strictly < because if len(p) = 0
//
FIXME ^^^
//
`pos < sb.pos + len(sb.buf)` (NOTE strictly < because if len(p) > 0)
//
and we come to condition which is used in `start + forward` if
n
=
copy
(
p
[
sb
.
pos
-
pos
:
],
sb
.
buf
)
// NOTE n == len(p[sb.pos - pos:])
p
=
p
[
:
sb
.
pos
-
pos
]
// pos
to
read stays the same
// pos
for actual
read stays the same
}
return
n
,
p
,
pos
...
...
@@ -84,13 +83,12 @@ func (sb *SeqBufReader) ReadAt(p []byte, pos int64) (n int, err error) {
// when there were big read requests which don't go through buffer, sb.pos remains not updated
// and this, on direction change, can result on 1 buffered read in the wrong direction
var
xpos
int64
if
pos
>
sb
.
pos
{
if
pos
>
=
sb
.
pos
{
// forward
xpos
=
pos
}
else
{
// backward
//xpos = max64(pos - cap(sb.buf), 0)
xpos
=
pos
-
int64
(
cap
(
sb
.
buf
))
xpos
=
pos
+
int64
(
len
(
p
))
-
int64
(
cap
(
sb
.
buf
))
if
xpos
<
0
{
xpos
=
0
}
...
...
t/neo/storage/fs1/xbufio_test.go
View file @
3f5969b5
...
...
@@ -9,6 +9,8 @@ import (
"errors"
"io"
"testing"
//"fmt"
)
...
...
@@ -20,8 +22,9 @@ type XReader struct {
var
EIO
=
errors
.
New
(
"input/output error"
)
func
(
r
*
XReader
)
ReadAt
(
p
[]
byte
,
pos
int64
)
(
n
int
,
err
error
)
{
//pos0 := pos
for
n
<
len
(
p
)
&&
pos
<
0x100
{
if
pos
>=
100
&&
pos
<=
104
{
if
100
<=
pos
&&
pos
<=
104
{
err
=
EIO
break
}
...
...
@@ -35,6 +38,7 @@ func (r *XReader) ReadAt(p []byte, pos int64) (n int, err error) {
err
=
io
.
EOF
}
//fmt.Printf("xread @%v #%v -> %v %#v\n", pos0, len(p), p[:n], err)
return
n
,
err
}
...
...
@@ -63,7 +67,7 @@ func TestSeqBufReader(t *testing.T) {
{
160
,
11
,
105
,
10
},
// big access backward, once more
{
155
,
5
,
155
,
10
},
// access backward - buffer refilled
// XXX refilled forward first time after big backward readings
{
150
,
5
,
1
50
,
10
},
// next access backward - buffer refilled backward
{
150
,
5
,
1
45
,
10
},
// next access backward - buffer refilled backward
// big backward
// small backward - refilled backward
...
...
@@ -78,6 +82,7 @@ func TestSeqBufReader(t *testing.T) {
pOk
:=
make
([]
byte
,
tt
.
Len
)
pB
:=
make
([]
byte
,
tt
.
Len
)
//fmt.Println("\n", tt)
nOk
,
errOk
:=
r
.
ReadAt
(
pOk
,
tt
.
pos
)
nB
,
errB
:=
rb
.
ReadAt
(
pB
,
tt
.
pos
)
...
...
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