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
5f440f01
Commit
5f440f01
authored
Feb 13, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1395e9a5
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
222 additions
and
19 deletions
+222
-19
t/neo/storage/fs1/fsb/fsbtree.go
t/neo/storage/fs1/fsb/fsbtree.go
+15
-15
t/neo/storage/fs1/fsb/gen-fsbtree
t/neo/storage/fs1/fsb/gen-fsbtree
+3
-2
t/neo/storage/fs1/fsb/gen.go
t/neo/storage/fs1/fsb/gen.go
+1
-1
t/neo/storage/fs1/index.go
t/neo/storage/fs1/index.go
+192
-1
t/neo/storage/fs1/index_test.go
t/neo/storage/fs1/index_test.go
+11
-0
No files found.
t/neo/storage/fs1/b/fsbtree.go
→
t/neo/storage/fs1/
fs
b/fsbtree.go
View file @
5f440f01
// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from github.com/cznic/b bcff30a)
// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from github.com/cznic/b bcff30a)
// KEY=zodb.Oid VALUE=
uint64
// KEY=zodb.Oid VALUE=
zodb.Tid
// ---- 8< ----
// ---- 8< ----
// Copyright 2014 The b Authors. All rights reserved.
// Copyright 2014 The b Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
b
package
fs
b
import
"../../../zodb"
import
"../../../zodb"
...
@@ -72,7 +72,7 @@ type (
...
@@ -72,7 +72,7 @@ type (
de
struct
{
// d element
de
struct
{
// d element
k
zodb
.
Oid
k
zodb
.
Oid
v
uint64
v
zodb
.
Tid
}
}
// Enumerator captures the state of enumerating a tree. It is returned
// Enumerator captures the state of enumerating a tree. It is returned
...
@@ -338,7 +338,7 @@ func (t *Tree) Delete(k zodb.Oid) (ok bool) {
...
@@ -338,7 +338,7 @@ func (t *Tree) Delete(k zodb.Oid) (ok bool) {
}
}
}
}
func
(
t
*
Tree
)
extract
(
q
*
d
,
i
int
)
{
// (r
uint64
) {
func
(
t
*
Tree
)
extract
(
q
*
d
,
i
int
)
{
// (r
zodb.Tid
) {
t
.
ver
++
t
.
ver
++
//r = q.d[i].v // prepared for Extract
//r = q.d[i].v // prepared for Extract
q
.
c
--
q
.
c
--
...
@@ -388,7 +388,7 @@ func (t *Tree) find(q interface{}, k zodb.Oid) (i int, ok bool) {
...
@@ -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
// First returns the first item of the tree in the key collating order, or
// (zero-value, zero-value) if the tree is empty.
// (zero-value, zero-value) if the tree is empty.
func
(
t
*
Tree
)
First
()
(
k
zodb
.
Oid
,
v
uint64
)
{
func
(
t
*
Tree
)
First
()
(
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
if
q
:=
t
.
first
;
q
!=
nil
{
if
q
:=
t
.
first
;
q
!=
nil
{
q
:=
&
q
.
d
[
0
]
q
:=
&
q
.
d
[
0
]
k
,
v
=
q
.
k
,
q
.
v
k
,
v
=
q
.
k
,
q
.
v
...
@@ -398,7 +398,7 @@ func (t *Tree) First() (k zodb.Oid, v uint64) {
...
@@ -398,7 +398,7 @@ func (t *Tree) First() (k zodb.Oid, v uint64) {
// Get returns the value associated with k and true if it exists. Otherwise Get
// Get returns the value associated with k and true if it exists. Otherwise Get
// returns (zero-value, false).
// returns (zero-value, false).
func
(
t
*
Tree
)
Get
(
k
zodb
.
Oid
)
(
v
uint64
,
ok
bool
)
{
func
(
t
*
Tree
)
Get
(
k
zodb
.
Oid
)
(
v
zodb
.
Tid
,
ok
bool
)
{
q
:=
t
.
r
q
:=
t
.
r
if
q
==
nil
{
if
q
==
nil
{
return
return
...
@@ -424,7 +424,7 @@ func (t *Tree) Get(k zodb.Oid) (v uint64, ok bool) {
...
@@ -424,7 +424,7 @@ func (t *Tree) Get(k zodb.Oid) (v uint64, ok bool) {
}
}
}
}
func
(
t
*
Tree
)
insert
(
q
*
d
,
i
int
,
k
zodb
.
Oid
,
v
uint64
)
*
d
{
func
(
t
*
Tree
)
insert
(
q
*
d
,
i
int
,
k
zodb
.
Oid
,
v
zodb
.
Tid
)
*
d
{
t
.
ver
++
t
.
ver
++
c
:=
q
.
c
c
:=
q
.
c
if
i
<
c
{
if
i
<
c
{
...
@@ -439,7 +439,7 @@ func (t *Tree) insert(q *d, i int, k zodb.Oid, v uint64) *d {
...
@@ -439,7 +439,7 @@ func (t *Tree) insert(q *d, i int, k zodb.Oid, v uint64) *d {
// Last returns the last item of the tree in the key collating order, or
// Last returns the last item of the tree in the key collating order, or
// (zero-value, zero-value) if the tree is empty.
// (zero-value, zero-value) if the tree is empty.
func
(
t
*
Tree
)
Last
()
(
k
zodb
.
Oid
,
v
uint64
)
{
func
(
t
*
Tree
)
Last
()
(
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
if
q
:=
t
.
last
;
q
!=
nil
{
if
q
:=
t
.
last
;
q
!=
nil
{
q
:=
&
q
.
d
[
q
.
c
-
1
]
q
:=
&
q
.
d
[
q
.
c
-
1
]
k
,
v
=
q
.
k
,
q
.
v
k
,
v
=
q
.
k
,
q
.
v
...
@@ -452,7 +452,7 @@ func (t *Tree) Len() int {
...
@@ -452,7 +452,7 @@ func (t *Tree) Len() int {
return
t
.
c
return
t
.
c
}
}
func
(
t
*
Tree
)
overflow
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
zodb
.
Oid
,
v
uint64
)
{
func
(
t
*
Tree
)
overflow
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
t
.
ver
++
t
.
ver
++
l
,
r
:=
p
.
siblings
(
pi
)
l
,
r
:=
p
.
siblings
(
pi
)
...
@@ -533,7 +533,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
...
@@ -533,7 +533,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
}
}
// Set sets the value associated with k.
// Set sets the value associated with k.
func
(
t
*
Tree
)
Set
(
k
zodb
.
Oid
,
v
uint64
)
{
func
(
t
*
Tree
)
Set
(
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
//dbg("--- PRE Set(%v, %v)\n%s", k, v, t.dump())
//dbg("--- PRE Set(%v, %v)\n%s", k, v, t.dump())
//defer func() {
//defer func() {
// dbg("--- POST\n%s\n====\n", t.dump())
// dbg("--- POST\n%s\n====\n", t.dump())
...
@@ -598,11 +598,11 @@ func (t *Tree) Set(k zodb.Oid, v uint64) {
...
@@ -598,11 +598,11 @@ func (t *Tree) Set(k zodb.Oid, v uint64) {
// tree.Put(k, func(zodb.Oid, bool){ return v, true })
// tree.Put(k, func(zodb.Oid, bool){ return v, true })
//
//
// modulo the differing return values.
// modulo the differing return values.
func
(
t
*
Tree
)
Put
(
k
zodb
.
Oid
,
upd
func
(
oldV
uint64
,
exists
bool
)
(
newV
uint64
,
write
bool
))
(
oldV
uint64
,
written
bool
)
{
func
(
t
*
Tree
)
Put
(
k
zodb
.
Oid
,
upd
func
(
oldV
zodb
.
Tid
,
exists
bool
)
(
newV
zodb
.
Tid
,
write
bool
))
(
oldV
zodb
.
Tid
,
written
bool
)
{
pi
:=
-
1
pi
:=
-
1
var
p
*
x
var
p
*
x
q
:=
t
.
r
q
:=
t
.
r
var
newV
uint64
var
newV
zodb
.
Tid
if
q
==
nil
{
if
q
==
nil
{
// new KV pair in empty tree
// new KV pair in empty tree
newV
,
written
=
upd
(
newV
,
false
)
newV
,
written
=
upd
(
newV
,
false
)
...
@@ -664,7 +664,7 @@ func (t *Tree) Put(k zodb.Oid, upd func(oldV uint64, exists bool) (newV uint64,
...
@@ -664,7 +664,7 @@ func (t *Tree) Put(k zodb.Oid, upd func(oldV uint64, exists bool) (newV uint64,
}
}
}
}
func
(
t
*
Tree
)
split
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
zodb
.
Oid
,
v
uint64
)
{
func
(
t
*
Tree
)
split
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
zodb
.
Oid
,
v
zodb
.
Tid
)
{
t
.
ver
++
t
.
ver
++
r
:=
btDPool
.
Get
()
.
(
*
d
)
r
:=
btDPool
.
Get
()
.
(
*
d
)
if
q
.
n
!=
nil
{
if
q
.
n
!=
nil
{
...
@@ -826,7 +826,7 @@ func (e *Enumerator) Close() {
...
@@ -826,7 +826,7 @@ func (e *Enumerator) Close() {
// Next returns the currently enumerated item, if it exists and moves to the
// 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 ==
// next item in the key collation order. If there is no item to return, err ==
// io.EOF is returned.
// io.EOF is returned.
func
(
e
*
Enumerator
)
Next
()
(
k
zodb
.
Oid
,
v
uint64
,
err
error
)
{
func
(
e
*
Enumerator
)
Next
()
(
k
zodb
.
Oid
,
v
zodb
.
Tid
,
err
error
)
{
if
err
=
e
.
err
;
err
!=
nil
{
if
err
=
e
.
err
;
err
!=
nil
{
return
return
}
}
...
@@ -880,7 +880,7 @@ func (e *Enumerator) next() error {
...
@@ -880,7 +880,7 @@ func (e *Enumerator) next() error {
// Prev returns the currently enumerated item, if it exists and moves to the
// 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
// previous item in the key collation order. If there is no item to return, err
// == io.EOF is returned.
// == io.EOF is returned.
func
(
e
*
Enumerator
)
Prev
()
(
k
zodb
.
Oid
,
v
uint64
,
err
error
)
{
func
(
e
*
Enumerator
)
Prev
()
(
k
zodb
.
Oid
,
v
zodb
.
Tid
,
err
error
)
{
if
err
=
e
.
err
;
err
!=
nil
{
if
err
=
e
.
err
;
err
!=
nil
{
return
return
}
}
...
...
t/neo/storage/fs1/b/gen-fsbtree
→
t/neo/storage/fs1/
fs
b/gen-fsbtree
View file @
5f440f01
#!/bin/sh -e
#!/bin/sh -e
# generate b.Tree with compile-time KEY=zodb.Oid, VALUE=
uint64
# generate b.Tree with compile-time KEY=zodb.Oid, VALUE=
zodb.Tid
KEY
=
zodb.Oid
KEY
=
zodb.Oid
VALUE
=
uint64
VALUE
=
zodb.Tid
b
=
github.com/cznic/b
b
=
github.com/cznic/b
Bdir
=
`
go list
-f
'{{.Dir}}'
$b
`
Bdir
=
`
go list
-f
'{{.Dir}}'
$b
`
...
@@ -15,6 +15,7 @@ echo "// ---- 8< ----" >>$out
...
@@ -15,6 +15,7 @@ echo "// ---- 8< ----" >>$out
echo
>>
$out
echo
>>
$out
make
-s
-C
$Bdir
generic |sed
\
make
-s
-C
$Bdir
generic |sed
\
-e
'/package b/a \\nimport "../../../zodb"'
\
-e
'/package b/a \\nimport "../../../zodb"'
\
-e
's/package b/package fsb/g'
\
-e
"s/KEY/
$KEY
/g"
\
-e
"s/KEY/
$KEY
/g"
\
-e
"s/VALUE/
$VALUE
/g"
\
-e
"s/VALUE/
$VALUE
/g"
\
>>
$out
>>
$out
t/neo/storage/fs1/b/gen.go
→
t/neo/storage/fs1/
fs
b/gen.go
View file @
5f440f01
package
b
package
fs
b
//go:generate ./gen-fsbtree
//go:generate ./gen-fsbtree
t/neo/storage/fs1/index.go
View file @
5f440f01
...
@@ -16,9 +16,200 @@
...
@@ -16,9 +16,200 @@
package
fs1
package
fs1
import
(
import
(
"bytes"
"encoding/binary"
"io"
"../../zodb"
"./fsb"
"lab.nexedi.com/kirr/go123/mem"
//"github.com/hydrogen18/stalecucumber"
pickle
"github.com/kisielk/og-rek"
)
)
// fsIndex is Oid -> Tid's position mapping used to associate Oid with latest
// fsIndex is Oid -> Tid's position mapping used to associate Oid with latest
// transaction which changed it.
TODO more text
// transaction which changed it.
type
fsIndex
struct
{
type
fsIndex
struct
{
fsb
.
Tree
}
// 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
}
*/
// __setitem__ -> Set
// on-disk index format
// (changed in 2010 in https://github.com/zopefoundation/ZODB/commit/1bb14faf)
//
// pos (?) (int or long - INT_TYPES)
// (oid[:6], v.toString) # ._data[oid]-> v (fsBucket().toString())
// (oid[:6], v.toString)
// ...
// None
//
//
// fsBucket.toString():
// oid[6:8]oid[6:8]oid[6:8]...tid[0:6]tid[0:6]tid[0:6]...
const
oidPrefixMask
zodb
.
Oid
=
((
1
<<
64
-
1
)
^
(
1
<<
16
-
1
))
// 0xffffffffffff0000
// Save saves the index to a writer
// XXX proper error context
func
(
fsi
*
fsIndex
)
Save
(
fsPos
int64
,
w
io
.
Writer
)
error
{
p
:=
pickle
.
NewEncoder
(
w
)
err
:=
p
.
Encode
(
fsPos
)
if
err
!=
nil
{
return
err
}
var
oidb
[
8
]
byte
var
tidb
[
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]...
var
t
[
2
]
interface
{}
// tuple for (oid, fsBucket.toString())
e
,
err
:=
fsi
.
SeekFirst
()
if
err
==
io
.
EOF
{
goto
skip
// empty btree
}
for
{
oid
,
tid
,
errStop
:=
e
.
Next
()
oidPrefix
:=
oid
&
oidPrefixMask
if
oidPrefix
!=
oidPrefixCur
{
// emit pickle for current oid06
binary
.
BigEndian
.
PutUint64
(
oidb
[
:
],
uint64
(
oid
))
t
[
0
]
=
oidb
[
0
:
6
]
t
[
1
]
=
bytes
.
Join
([][]
byte
{
oidBuf
,
tidBuf
},
nil
)
err
=
p
.
Encode
(
t
)
if
err
!=
nil
{
return
err
}
oidPrefixCur
=
oidPrefix
oidBuf
=
oidBuf
[
:
0
]
tidBuf
=
tidBuf
[
:
0
]
}
if
errStop
!=
nil
{
break
}
binary
.
BigEndian
.
PutUint64
(
oidb
[
:
],
uint64
(
oid
))
binary
.
BigEndian
.
PutUint64
(
tidb
[
:
],
uint64
(
tid
))
oidBuf
=
append
(
oidBuf
,
oidb
[
6
:
8
]
...
)
tidBuf
=
append
(
tidBuf
,
tidb
[
0
:
6
]
...
)
}
e
.
Close
()
skip
:
err
=
p
.
Encode
(
pickle
.
None
{})
return
err
}
// LoadIndex loads index from a reader
func
LoadIndex
(
r
io
.
Reader
)
(
fsPos
int64
,
fsi
*
fsIndex
,
err
error
)
{
p
:=
pickle
.
NewDecoder
(
r
)
// if we can know file position we can show it in error context
rseek
,
_
:=
r
.
(
io
.
Seeker
)
var
rpos
int64
decode
:=
func
()
(
interface
{},
error
)
{
if
rseek
!=
nil
{
rpos
=
rseek
.
Seek
(
...
)
// XXX not ok as p buffers r internally
}
}
xpos
,
err
:=
p
.
Decode
()
if
err
!=
nil
{
// TODO err
}
fsPos
,
ok
:=
xpos
.
(
int64
)
if
!
ok
{
// TODO err
}
fsi
=
&
fsIndex
{}
// TODO cmpFunc ...
var
oidb
[
8
]
byte
var
tidb
[
8
]
byte
loop
:
for
{
xv
,
err
:=
p
.
Decode
()
if
err
!=
nil
{
// TODO err
}
switch
xv
.
(
type
)
{
default
:
// TODO err
break
case
pickle
.
None
:
break
loop
case
[]
interface
{}
:
// so far ok
}
v
:=
xv
.
([]
interface
{})
if
len
(
v
)
!=
2
{
// TODO err
}
xoidPrefixStr
:=
v
[
0
]
oidPrefixStr
,
ok
:=
xoidPrefixStr
.
(
string
)
if
!
ok
||
len
(
oidPrefixStr
)
!=
6
{
// TODO
}
copy
(
oidb
[
:
],
oidPrefixStr
)
oidPrefix
:=
zodb
.
Oid
(
binary
.
BigEndian
.
Uint64
(
oidb
[
:
]))
xkvStr
:=
v
[
1
]
kvStr
,
ok
:=
xkvStr
.
(
string
)
if
!
ok
||
len
(
kvStr
)
%
8
!=
0
{
// TODO
}
kvBuf
:=
mem
.
Bytes
(
kvStr
)
n
:=
len
(
kvBuf
)
/
8
oidBuf
:=
kvBuf
[
:
n
*
2
]
tidBuf
:=
kvBuf
[
n
*
2
:
]
for
i
:=
0
;
i
<
n
;
i
++
{
oid
:=
zodb
.
Oid
(
binary
.
BigEndian
.
Uint16
(
oidBuf
[
i
*
2
:
]))
oid
|=
oidPrefix
copy
(
tidb
[
2
:
],
tidBuf
[
i
*
6
:
])
tid
:=
zodb
.
Tid
(
binary
.
BigEndian
.
Uint64
(
tidb
[
:
]))
fsi
.
Set
(
oid
,
tid
)
}
}
return
fsPos
,
fsi
,
nil
xerror
:
// same for file name
rname
,
_
:=
r
.
(
interface
{
Name
()
string
})
}
}
t/neo/storage/fs1/index_test.go
0 → 100644
View file @
5f440f01
// XXX license/copyright
package
fs1
import
(
"testing"
)
func
TestXXX
(
t
*
testing
.
T
)
{
// TODO
}
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