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
dacbb6cf
Commit
dacbb6cf
authored
Feb 14, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5f440f01
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
56 deletions
+108
-56
t/neo/storage/fs1/fsb/fsbtree.go
t/neo/storage/fs1/fsb/fsbtree.go
+14
-14
t/neo/storage/fs1/fsb/gen-fsbtree
t/neo/storage/fs1/fsb/gen-fsbtree
+2
-2
t/neo/storage/fs1/index.go
t/neo/storage/fs1/index.go
+92
-40
No files found.
t/neo/storage/fs1/fsb/fsbtree.go
View file @
dacbb6cf
// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from github.com/cznic/b bcff30a)
// KEY=zodb.Oid VALUE=
zodb.Tid
// KEY=zodb.Oid VALUE=
int64
// ---- 8< ----
// Copyright 2014 The b Authors. All rights reserved.
...
...
@@ -72,7 +72,7 @@ type (
de
struct
{
// d element
k
zodb
.
Oid
v
zodb
.
Tid
v
int64
}
// Enumerator captures the state of enumerating a tree. It is returned
...
...
@@ -338,7 +338,7 @@ func (t *Tree) Delete(k zodb.Oid) (ok bool) {
}
}
func
(
t
*
Tree
)
extract
(
q
*
d
,
i
int
)
{
// (r
zodb.Tid
) {
func
(
t
*
Tree
)
extract
(
q
*
d
,
i
int
)
{
// (r
int64
) {
t
.
ver
++
//r = q.d[i].v // prepared for Extract
q
.
c
--
...
...
@@ -388,7 +388,7 @@ func (t *Tree) find(q interface{}, k zodb.Oid) (i int, ok bool) {
// First returns the first item of the tree in the key collating order, or
// (zero-value, zero-value) if the tree is empty.
func
(
t
*
Tree
)
First
()
(
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
func
(
t
*
Tree
)
First
()
(
k
zodb
.
Oid
,
v
int64
)
{
if
q
:=
t
.
first
;
q
!=
nil
{
q
:=
&
q
.
d
[
0
]
k
,
v
=
q
.
k
,
q
.
v
...
...
@@ -398,7 +398,7 @@ func (t *Tree) First() (k zodb.Oid, v zodb.Tid) {
// Get returns the value associated with k and true if it exists. Otherwise Get
// returns (zero-value, false).
func
(
t
*
Tree
)
Get
(
k
zodb
.
Oid
)
(
v
zodb
.
Tid
,
ok
bool
)
{
func
(
t
*
Tree
)
Get
(
k
zodb
.
Oid
)
(
v
int64
,
ok
bool
)
{
q
:=
t
.
r
if
q
==
nil
{
return
...
...
@@ -424,7 +424,7 @@ func (t *Tree) Get(k zodb.Oid) (v zodb.Tid, ok bool) {
}
}
func
(
t
*
Tree
)
insert
(
q
*
d
,
i
int
,
k
zodb
.
Oid
,
v
zodb
.
Tid
)
*
d
{
func
(
t
*
Tree
)
insert
(
q
*
d
,
i
int
,
k
zodb
.
Oid
,
v
int64
)
*
d
{
t
.
ver
++
c
:=
q
.
c
if
i
<
c
{
...
...
@@ -439,7 +439,7 @@ func (t *Tree) insert(q *d, i int, k zodb.Oid, v zodb.Tid) *d {
// Last returns the last item of the tree in the key collating order, or
// (zero-value, zero-value) if the tree is empty.
func
(
t
*
Tree
)
Last
()
(
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
func
(
t
*
Tree
)
Last
()
(
k
zodb
.
Oid
,
v
int64
)
{
if
q
:=
t
.
last
;
q
!=
nil
{
q
:=
&
q
.
d
[
q
.
c
-
1
]
k
,
v
=
q
.
k
,
q
.
v
...
...
@@ -452,7 +452,7 @@ func (t *Tree) Len() int {
return
t
.
c
}
func
(
t
*
Tree
)
overflow
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
func
(
t
*
Tree
)
overflow
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
zodb
.
Oid
,
v
int64
)
{
t
.
ver
++
l
,
r
:=
p
.
siblings
(
pi
)
...
...
@@ -533,7 +533,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
}
// Set sets the value associated with k.
func
(
t
*
Tree
)
Set
(
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
func
(
t
*
Tree
)
Set
(
k
zodb
.
Oid
,
v
int64
)
{
//dbg("--- PRE Set(%v, %v)\n%s", k, v, t.dump())
//defer func() {
// dbg("--- POST\n%s\n====\n", t.dump())
...
...
@@ -598,11 +598,11 @@ func (t *Tree) Set(k zodb.Oid, v zodb.Tid) {
// tree.Put(k, func(zodb.Oid, bool){ return v, true })
//
// modulo the differing return values.
func
(
t
*
Tree
)
Put
(
k
zodb
.
Oid
,
upd
func
(
oldV
zodb
.
Tid
,
exists
bool
)
(
newV
zodb
.
Tid
,
write
bool
))
(
oldV
zodb
.
Tid
,
written
bool
)
{
func
(
t
*
Tree
)
Put
(
k
zodb
.
Oid
,
upd
func
(
oldV
int64
,
exists
bool
)
(
newV
int64
,
write
bool
))
(
oldV
int64
,
written
bool
)
{
pi
:=
-
1
var
p
*
x
q
:=
t
.
r
var
newV
zodb
.
Tid
var
newV
int64
if
q
==
nil
{
// new KV pair in empty tree
newV
,
written
=
upd
(
newV
,
false
)
...
...
@@ -664,7 +664,7 @@ func (t *Tree) Put(k zodb.Oid, upd func(oldV zodb.Tid, exists bool) (newV zodb.T
}
}
func
(
t
*
Tree
)
split
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
func
(
t
*
Tree
)
split
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
zodb
.
Oid
,
v
int64
)
{
t
.
ver
++
r
:=
btDPool
.
Get
()
.
(
*
d
)
if
q
.
n
!=
nil
{
...
...
@@ -826,7 +826,7 @@ func (e *Enumerator) Close() {
// Next returns the currently enumerated item, if it exists and moves to the
// next item in the key collation order. If there is no item to return, err ==
// io.EOF is returned.
func
(
e
*
Enumerator
)
Next
()
(
k
zodb
.
Oid
,
v
zodb
.
Tid
,
err
error
)
{
func
(
e
*
Enumerator
)
Next
()
(
k
zodb
.
Oid
,
v
int64
,
err
error
)
{
if
err
=
e
.
err
;
err
!=
nil
{
return
}
...
...
@@ -880,7 +880,7 @@ func (e *Enumerator) next() error {
// Prev returns the currently enumerated item, if it exists and moves to the
// previous item in the key collation order. If there is no item to return, err
// == io.EOF is returned.
func
(
e
*
Enumerator
)
Prev
()
(
k
zodb
.
Oid
,
v
zodb
.
Tid
,
err
error
)
{
func
(
e
*
Enumerator
)
Prev
()
(
k
zodb
.
Oid
,
v
int64
,
err
error
)
{
if
err
=
e
.
err
;
err
!=
nil
{
return
}
...
...
t/neo/storage/fs1/fsb/gen-fsbtree
View file @
dacbb6cf
#!/bin/sh -e
# generate b.Tree with compile-time KEY=zodb.Oid, VALUE=
zodb.Tid
# generate b.Tree with compile-time KEY=zodb.Oid, VALUE=
int64
KEY
=
zodb.Oid
VALUE
=
zodb.Tid
VALUE
=
int64
b
=
github.com/cznic/b
Bdir
=
`
go list
-f
'{{.Dir}}'
$b
`
...
...
t/neo/storage/fs1/index.go
View file @
dacbb6cf
...
...
@@ -36,25 +36,15 @@ type fsIndex struct {
}
// TODO Encode (__getstate__)
// TODO Decode (__setstate__)
// TODO ? save(pos, fname)
// TODO ? klass.load(fname)
/*
// __getitem__
func (fsi *fsIndex) Get(oid zodb.Oid) zodb.Tid { // XXX ,ok ?
tid, ok := fsi.oid2tid.Get(oid)
return tid, ok
}
*/
// TODO Encode (__getstate__) ?
// TODO Decode (__setstate__) ?
//
__setitem__ -> Set
//
NOTE Get/Set/... are taken as-is from fsb.Tree
// on-disk index format
// (changed in 2010 in https://github.com/zopefoundation/ZODB/commit/1bb14faf)
//
//
pos (?) (int or long - INT_TYPES)
//
topPos position pointing just past the last committed transaction
// (oid[:6], v.toString) # ._data[oid]-> v (fsBucket().toString())
// (oid[:6], v.toString)
// ...
...
...
@@ -62,51 +52,61 @@ func (fsi *fsIndex) Get(oid zodb.Oid) zodb.Tid { // XXX ,ok ?
//
//
// fsBucket.toString():
// oid[6:8]oid[6:8]oid[6:8]...
tid[0:6]tid[0:6]tid
[0:6]...
// oid[6:8]oid[6:8]oid[6:8]...
pos[0:6]pos[0:6]pos
[0:6]...
const
oidPrefixMask
zodb
.
Oid
=
((
1
<<
64
-
1
)
^
(
1
<<
16
-
1
))
// 0xffffffffffff0000
// IndexIOError is the error type returned by index save and load routines
type
IndexIOError
struct
{
Op
string
// operation performed - "save" or "load"
Err
error
// error that occured during the operation
}
func
(
e
*
IndexIOError
)
Error
()
string
{
s
:=
"index "
+
e
.
Op
+
": "
+
e
.
Err
.
Error
()
return
s
}
// Save saves the index to a writer
// XXX proper error context
func
(
fsi
*
fsIndex
)
Save
(
fsPos
int64
,
w
io
.
Writer
)
error
{
func
(
fsi
*
fsIndex
)
Save
(
topPos
int64
,
w
io
.
Writer
)
error
{
p
:=
pickle
.
NewEncoder
(
w
)
err
:=
p
.
Encode
(
fs
Pos
)
err
:=
p
.
Encode
(
top
Pos
)
if
err
!=
nil
{
return
err
goto
out
}
var
oidb
[
8
]
byte
var
tid
b
[
8
]
byte
var
pos
b
[
8
]
byte
var
oidPrefixCur
zodb
.
Oid
// current oid[0:6] with [6:8] = 00
oidBuf
:=
[]
byte
{}
// current oid[6:8]oid[6:8]...
tidBuf
:=
[]
byte
{}
// current tid[0:6]tid
[0:6]...
posBuf
:=
[]
byte
{}
// current pos[0:6]pos
[0:6]...
var
t
[
2
]
interface
{}
// tuple for (oid, fsBucket.toString())
e
,
err
:=
fsi
.
SeekFirst
()
if
err
==
io
.
EOF
{
goto
skip
// empty btree
if
err
==
io
.
EOF
{
// always only io.EOF indicating an empty btree
goto
skip
}
for
{
oid
,
tid
,
errStop
:=
e
.
Next
()
oid
,
pos
,
errStop
:=
e
.
Next
()
oidPrefix
:=
oid
&
oidPrefixMask
if
oidPrefix
!=
oidPrefixCur
{
// emit
pickle for current oid06
// emit
(oid[:6], oid[6:8]oid[6:8]...pos[0:6]pos[0:6]...)
binary
.
BigEndian
.
PutUint64
(
oidb
[
:
],
uint64
(
oid
))
t
[
0
]
=
oidb
[
0
:
6
]
t
[
1
]
=
bytes
.
Join
([][]
byte
{
oidBuf
,
tid
Buf
},
nil
)
t
[
1
]
=
bytes
.
Join
([][]
byte
{
oidBuf
,
pos
Buf
},
nil
)
err
=
p
.
Encode
(
t
)
if
err
!=
nil
{
return
err
goto
out
}
oidPrefixCur
=
oidPrefix
oidBuf
=
oidBuf
[
:
0
]
tidBuf
=
tid
Buf
[
:
0
]
posBuf
=
pos
Buf
[
:
0
]
}
if
errStop
!=
nil
{
...
...
@@ -114,21 +114,34 @@ func (fsi *fsIndex) Save(fsPos int64, w io.Writer) error {
}
binary
.
BigEndian
.
PutUint64
(
oidb
[
:
],
uint64
(
oid
))
binary
.
BigEndian
.
PutUint64
(
tidb
[
:
],
uint64
(
tid
))
binary
.
BigEndian
.
PutUint64
(
posb
[
:
],
uint64
(
pos
))
// XXX check pos does not overflow 6 bytes
oidBuf
=
append
(
oidBuf
,
oidb
[
6
:
8
]
...
)
tidBuf
=
append
(
tidBuf
,
tid
b
[
0
:
6
]
...
)
posBuf
=
append
(
posBuf
,
pos
b
[
0
:
6
]
...
)
}
e
.
Close
()
skip
:
err
=
p
.
Encode
(
pickle
.
None
{})
out
:
if
err
==
nil
{
return
err
}
if
_
,
ok
:=
err
.
(
pikle
.
TypeError
);
ok
{
panic
(
err
)
// all our types are expected to be supported by pickle
}
// otherwise it is an error returned by writer, which should already
// have filename & op as context.
return
&
IndexIOError
{
"save"
,
err
}
}
// LoadIndex loads index from a reader
func
LoadIndex
(
r
io
.
Reader
)
(
fs
Pos
int64
,
fsi
*
fsIndex
,
err
error
)
{
func
LoadIndex
(
r
io
.
Reader
)
(
top
Pos
int64
,
fsi
*
fsIndex
,
err
error
)
{
p
:=
pickle
.
NewDecoder
(
r
)
// if we can know file position we can show it in error context
...
...
@@ -140,18 +153,18 @@ func LoadIndex(r io.Reader) (fsPos int64, fsi *fsIndex, err error) {
}
}
x
p
os
,
err
:=
p
.
Decode
()
x
topP
os
,
err
:=
p
.
Decode
()
if
err
!=
nil
{
// TODO err
}
fsPos
,
ok
:=
xp
os
.
(
int64
)
topPos
,
ok
:=
xtopP
os
.
(
int64
)
if
!
ok
{
// TODO err
}
fsi
=
&
fsIndex
{}
// TODO cmpFunc ...
var
oidb
[
8
]
byte
var
tid
b
[
8
]
byte
var
pos
b
[
8
]
byte
loop
:
for
{
...
...
@@ -194,22 +207,61 @@ loop:
n
:=
len
(
kvBuf
)
/
8
oidBuf
:=
kvBuf
[
:
n
*
2
]
tid
Buf
:=
kvBuf
[
n
*
2
:
]
pos
Buf
:=
kvBuf
[
n
*
2
:
]
for
i
:=
0
;
i
<
n
;
i
++
{
oid
:=
zodb
.
Oid
(
binary
.
BigEndian
.
Uint16
(
oidBuf
[
i
*
2
:
]))
oid
|=
oidPrefix
copy
(
tidb
[
2
:
],
tid
Buf
[
i
*
6
:
])
tid
:=
zodb
.
Tid
(
binary
.
BigEndian
.
Uint64
(
tid
b
[
:
]))
copy
(
posb
[
2
:
],
pos
Buf
[
i
*
6
:
])
tid
:=
zodb
.
Tid
(
binary
.
BigEndian
.
Uint64
(
pos
b
[
:
]))
fsi
.
Set
(
oid
,
tid
)
}
}
return
fsPos
,
fsi
,
nil
return
topPos
,
fsi
,
nil
out
:
if
err
==
nil
{
return
topPos
,
fsi
,
err
}
rname
:=
IOName
(
r
)
xerror
:
// same for file name
rname
,
_
:=
r
.
(
interface
{
Name
()
string
})
}
// IOName returns a "filename" associated with io.Reader, io.Writer, net.Conn, ...
// if name cannot be deterined - "" is returned.
func
IOName
(
f
interface
{})
string
{
switch
f
:=
f
.
(
type
)
{
case
*
os
.
File
:
// XXX better via interface { Name() string } ?
// but Name() is too broad compared to FileName()
return
f
.
Name
()
case
net
.
Conn
:
// XXX not including LocalAddr is ok?
return
f
.
RemoteAddr
.
String
()
case
*
io
.
LimitedReader
:
return
IOName
(
f
.
R
)
case
*
io
.
PipeReader
:
fallthrough
case
*
io
.
PipeWriter
:
return
"pipe"
// XXX SectionReader MultiReader TeeReader
// bufio.Reader bufio.Writer bufio.Scanner
default
:
return
""
}
}
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