Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
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
Levin Zimmermann
neoppod
Commits
e6f9c797
Commit
e6f9c797
authored
Feb 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
929332cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
44 deletions
+38
-44
t/neo/storage/fs1/filestorage.go
t/neo/storage/fs1/filestorage.go
+38
-44
No files found.
t/neo/storage/fs1/filestorage.go
View file @
e6f9c797
...
...
@@ -41,14 +41,19 @@ var _ zodb.IStorage = (*FileStorage)(nil)
// TxnHeader represents header of a transaction record
type
TxnHeader
struct
{
// XXX consider reorder with zodb.TxnInfo ?
PrevRecLenm8
uint64
// 0 if no previous record
RecLenm8
uint64
// XXX -> TxnPos, TxnLen, PrevTxnLen ?
Pos
int64
// position of transaction start
PrevLen
int64
// whole previous transaction record length
// (0 if there is no previous txn record)
Len
int64
// whole transaction record length
// XXX recheck ^^^ Len are validated on load
// transaction metadata tself
zodb
.
TxnInfo
// underlying storage for user/desc/extension
strings
Ra
m
[]
byte
strings
Me
m
[]
byte
}
const
(
...
...
@@ -100,23 +105,26 @@ func (e *ErrDataRecord) Error() string {
var
ErrVersionNonZero
=
errors
.
New
(
"non-zero version"
)
//
decode
reads and decodes transaction record header from a readerAt
//
load
reads and decodes transaction record header from a readerAt
// pos: points to header begin XXX text
// no requirements are made to previous th state XXX text
// XXX io.ReaderAt -> *os.File (if iface conv costly)
func
(
th
*
TxnHeader
)
decode
(
r
io
.
ReaderAt
,
pos
int64
,
tmpBuf
*
[
txnXHeaderFixSize
]
byte
)
(
n
int
,
err
error
)
{
//func (th *TxnHeader) load(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize]byte) (n int, err error) {
func
(
th
*
TxnHeader
)
load
(
r
io
.
ReaderAt
,
pos
int64
,
tmpBuf
*
[
txnXHeaderFixSize
]
byte
)
error
{
th
.
Pos
=
pos
if
pos
>
4
+
8
{
// XXX -> magic
// read together with previous's txn record redundand length
n
,
err
=
r
.
ReadAt
(
tmpBuf
[
:
],
pos
-
8
)
n
-=
8
// relative to pos
if
n
>=
0
{
th
.
Prev
Rec
Lenm8
=
uint64
(
binary
.
BigEndian
.
Uint64
(
tmpBuf
[
8
-
8
:
]))
if
th
.
Prev
Rec
Lenm8
<
txnHeaderFixSize
{
th
.
PrevLenm8
=
uint64
(
binary
.
BigEndian
.
Uint64
(
tmpBuf
[
8
-
8
:
]))
if
th
.
PrevLenm8
<
txnHeaderFixSize
{
panic
(
"too small txn prev record length"
)
// XXX
}
}
}
else
{
th
.
Prev
Rec
Lenm8
=
0
th
.
PrevLenm8
=
0
n
,
err
=
r
.
ReadAt
(
tmpBuf
[
8
:
],
pos
)
}
...
...
@@ -135,10 +143,10 @@ func (th *TxnHeader) decode(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize
}
th
.
Tid
=
zodb
.
Tid
(
binary
.
BigEndian
.
Uint64
(
tmpBuf
[
8
+
0
:
]))
th
.
Rec
Lenm8
=
uint64
(
binary
.
BigEndian
.
Uint64
(
tmpBuf
[
8
+
8
:
]))
th
.
Lenm8
=
uint64
(
binary
.
BigEndian
.
Uint64
(
tmpBuf
[
8
+
8
:
]))
th
.
Status
=
zodb
.
TxnStatus
(
tmpBuf
[
8
+
16
])
if
th
.
Rec
Lenm8
<
txnHeaderFixSize
{
if
th
.
Lenm8
<
txnHeaderFixSize
{
panic
(
"too small txn record length"
)
// XXX
}
...
...
@@ -146,56 +154,42 @@ func (th *TxnHeader) decode(r io.ReaderAt, pos int64, tmpBuf *[txnXHeaderFixSize
ldesc
:=
binary
.
BigEndian
.
Uint16
(
tmpBuf
[
8
+
19
:
])
lext
:=
binary
.
BigEndian
.
Uint16
(
tmpBuf
[
8
+
21
:
])
// XXX load strings only optionally
lstr
:=
int
(
luser
)
+
int
(
ldesc
)
+
int
(
lext
)
if
lstr
<=
cap
(
th
.
strings
Ra
m
)
{
th
.
strings
Ram
=
th
.
stringsRa
m
[
:
lstr
]
if
lstr
<=
cap
(
th
.
strings
Me
m
)
{
th
.
strings
Mem
=
th
.
stringsMe
m
[
:
lstr
]
}
else
{
th
.
strings
Ra
m
=
make
([]
byte
,
lstr
)
th
.
strings
Me
m
=
make
([]
byte
,
lstr
)
}
nstr
,
err
=
r
.
ReadAt
(
th
.
strings
Ra
m
,
pos
+
txnHeaderFixSize
)
nstr
,
err
=
r
.
ReadAt
(
th
.
strings
Me
m
,
pos
+
txnHeaderFixSize
)
// XXX EOF after txn header is not good
if
err
!=
nil
{
return
0
,
&
ErrTxnRecord
{
pos
,
"read"
,
noEof
(
err
)}
}
th
.
User
=
th
.
strings
Ra
m
[
0
:
luser
]
th
.
User
=
th
.
strings
Me
m
[
0
:
luser
]
th
.
Description
=
th
.
strings
Ra
m
[
luser
:
luser
+
ldesc
]
th
.
Extension
=
th
.
strings
Ra
m
[
luser
+
ldesc
:
luser
+
ldesc
+
lext
]
th
.
Description
=
th
.
strings
Me
m
[
luser
:
luser
+
ldesc
]
th
.
Extension
=
th
.
strings
Me
m
[
luser
+
ldesc
:
luser
+
ldesc
+
lext
]
return
txnHeaderFixSize
+
lstr
,
nil
}
// decodePrev reads and decodes transaction record header from a readerAt XXX from next ...
// pos: points to header begin XXX text
// th should be already initialized by previous call to decode()
func
(
th
*
TxnHeader
)
decodePrev
(
r
io
.
ReaderAt
,
pos
int64
,
tmpBuf
*
[
txnXHeaderFixSize
]
byte
)
(
posPrev
int64
,
n
int
,
err
error
)
{
if
th
.
PrevRecLenm8
==
0
{
panic
(
"no prev"
)
// TODO
}
n
,
err
=
r
.
ReadAt
(
tmpBuf
[
:
8
],
pos
-
8
)
if
n
==
8
{
// -> to readAt() utility
err
=
nil
// we are ok to get EOF after reading it all
}
if
err
!=
nil
{
panic
(
err
)
// XXX
}
recLenm8
:=
binary
.
BigEndian
.
Uint64
(
tmpBuf
[
0
:
])
posPrev
=
pos
-
8
-
int64
(
recLenm8
)
// XXX overflow ?
n
,
err
=
th
.
decode
(
r
,
posPrev
,
tmpBuf
)
if
err
!=
nil
{
return
0
,
0
,
err
// XXX +context
// loadPrev reads and decodes previous transaction record header from a readerAt
// txnh should be already initialized by previous call to load()
func
(
txnh
*
TxnHeader
)
loadPrev
(
r
io
.
ReaderAt
,
tmpBuf
*
[
txnXHeaderFixSize
]
byte
)
error
{
if
txnh
.
PrevLen
==
0
{
return
io
.
EOF
}
if
th
.
RecLenm8
!=
recLenm8
{
panic
(
"redunant length mismatch"
)
// XXX
}
return
txnh
.
load
(
r
,
txnh
.
Pos
-
txnh
.
PrevLen
,
tmpBuf
)
}
return
posPrev
,
n
,
nil
// loadNext reads and decodes next transaction record header from a readerAt
// txnh should be already initialized by previous call to load()
func
(
txnh
*
TxnHeader
)
loadNext
(
r
io
.
ReaderAt
,
tmpBuf
*
[
txnXHeaderFixSize
]
byte
)
error
{
return
txnh
.
load
(
r
,
txnh
.
Pos
+
txnh
.
Len
,
tmpBuf
)
}
// XXX do we need Decode when decode() is there?
...
...
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