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
2121ce8a
Commit
2121ce8a
authored
Mar 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a57f4275
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
188 additions
and
22 deletions
+188
-22
t/neo/storage/fs1/cmd/fstail/fstail_test.go
t/neo/storage/fs1/cmd/fstail/fstail_test.go
+1
-0
t/neo/storage/fs1/filestorage.go
t/neo/storage/fs1/filestorage.go
+3
-11
t/neo/xcommon/xcommon.go
t/neo/xcommon/xcommon.go
+3
-0
t/neo/xcommon/xfmt/fmt.go
t/neo/xcommon/xfmt/fmt.go
+16
-0
t/neo/xcommon/xmath/math.go
t/neo/xcommon/xmath/math.go
+20
-0
t/neo/xcommon/xmath/math_test.go
t/neo/xcommon/xmath/math_test.go
+41
-0
t/neo/xcommon/xslice/slice.go
t/neo/xcommon/xslice/slice.go
+56
-0
t/neo/xcommon/xslice/slice_test.go
t/neo/xcommon/xslice/slice_test.go
+14
-0
t/neo/zodb/cmd/zodbdump/zodbdump_test.go
t/neo/zodb/cmd/zodbdump/zodbdump_test.go
+34
-11
No files found.
t/neo/storage/fs1/cmd/fstail/fstail_test.go
View file @
2121ce8a
...
...
@@ -45,6 +45,7 @@ func TestFsTail(t *testing.T) {
}
func
BenchmarkFsTail
(
b
*
testing
.
B
)
{
// FIXME small testdata/1.fs is not representative for benchmarking
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
err
:=
fsTail
(
ioutil
.
Discard
,
"../../testdata/1.fs"
,
1000000
)
if
err
!=
nil
{
...
...
t/neo/storage/fs1/filestorage.go
View file @
2121ce8a
...
...
@@ -19,11 +19,11 @@ package fs1
import
(
"encoding/binary"
"fmt"
"math/bits"
"io"
"os"
"../../zodb"
"../../xcommon/xmath"
)
// FileStorage is a ZODB storage which stores data in simple append-only file
...
...
@@ -315,7 +315,7 @@ func (txnh *TxnHeader) Load(r io.ReaderAt /* *os.File */, pos int64, flags TxnLo
// NOTE we encode whole strings length into len(.workMem)
if
cap
(
txnh
.
workMem
)
<
lstr
{
txnh
.
workMem
=
make
([]
byte
,
lstr
,
c
eilPow2
(
uint64
(
lstr
)))
txnh
.
workMem
=
make
([]
byte
,
lstr
,
xmath
.
C
eilPow2
(
uint64
(
lstr
)))
}
else
{
txnh
.
workMem
=
txnh
.
workMem
[
:
lstr
]
}
...
...
@@ -635,12 +635,6 @@ func (dh *DataHeader) loadNext(r io.ReaderAt /* *os.File */, txnh *TxnHeader) er
return
nil
}
// XXX move me out of here
// ceilPow2 returns minimal y >= x, such as y = 2^i
func
ceilPow2
(
x
uint64
)
uint64
{
return
1
<<
uint
(
bits
.
Len64
(
x
))
}
// LoadData loads data for the data record taking backpointers into account
// Data is loaded into *buf, which, if needed, is reallocated to hold all loading data size XXX
// NOTE on success dh state is changed to data header of original data transaction
...
...
@@ -660,9 +654,7 @@ func (dh *DataHeader) LoadData(r io.ReaderAt /* *os.File */, buf *[]byte) error
// now read actual data
if
int64
(
cap
(
*
buf
))
<
dh
.
DataLen
{
// ceilPow2 reduces much allocations but is still not enogh to
// remove them all from BenchmarkIterate
*
buf
=
make
([]
byte
,
dh
.
DataLen
,
ceilPow2
(
uint64
(
dh
.
DataLen
)))
*
buf
=
make
([]
byte
,
dh
.
DataLen
,
xmath
.
CeilPow2
(
uint64
(
dh
.
DataLen
)))
}
else
{
*
buf
=
(
*
buf
)[
:
dh
.
DataLen
]
}
...
...
t/neo/xcommon/xcommon.go
0 → 100644
View file @
2121ce8a
// Package xcommon is a staging place for common utilities not yet sorted out
// to their proper homes
package
xcommon
t/neo/xcommon/xfmt/fmt.go
0 → 100644
View file @
2121ce8a
package
xfmt
import
(
"encoding/hex"
"../xslice"
)
// appendHex appends hex representation of x to b
func
AppendHex
(
b
[]
byte
,
x
[]
byte
)
[]
byte
{
lx
:=
hex
.
EncodedLen
(
len
(
x
))
lb
:=
len
(
b
)
b
=
xslice
.
Grow
(
b
,
lx
)
hex
.
Encode
(
b
[
lb
:
],
x
)
return
b
}
t/neo/xcommon/xmath/math.go
0 → 100644
View file @
2121ce8a
// Package xmath provides addons over std math package XXX text
package
xmath
import
(
"math/bits"
)
// CeilPow2 returns minimal y >= x, such that y = 2^i
// XXX naming to reflect it works on uint64 ? CeilPow264 looks ambigous
func
CeilPow2
(
x
uint64
)
uint64
{
switch
bits
.
OnesCount64
(
x
)
{
case
0
,
1
:
return
x
// either 0 or 2^i already
default
:
return
1
<<
uint
(
bits
.
Len64
(
x
))
}
}
// XXX if needed: NextPow2 (y > x, such that y = 2^i) is
// 1 << bits.Len64(x)
t/neo/xcommon/xmath/math_test.go
0 → 100644
View file @
2121ce8a
package
xmath
import
(
"testing"
)
func
TestCeilPow2
(
t
*
testing
.
T
)
{
testv
:=
[]
struct
{
in
,
out
uint64
}
{
{
0
,
0
},
{
1
,
1
},
{
2
,
2
},
{
3
,
4
},
{
4
,
4
},
{
5
,
8
},
{
5
,
8
},
{
6
,
8
},
{
7
,
8
},
{
8
,
8
},
{
9
,
16
},
{
10
,
16
},
{
11
,
16
},
{
12
,
16
},
{
13
,
16
},
{
14
,
16
},
{
15
,
16
},
{
16
,
16
},
{
1
<<
62
-
1
,
1
<<
62
},
{
1
<<
62
,
1
<<
62
},
{
1
<<
62
+
1
,
1
<<
63
},
{
1
<<
63
-
1
,
1
<<
63
},
{
1
<<
63
,
1
<<
63
},
}
for
_
,
tt
:=
range
testv
{
out
:=
CeilPow2
(
tt
.
in
)
if
out
!=
tt
.
out
{
t
.
Errorf
(
"CeilPow(%v) -> %v ; want %v"
,
tt
.
in
,
out
,
tt
.
out
)
}
}
}
t/neo/xcommon/xslice/slice.go
0 → 100644
View file @
2121ce8a
// Package xslice provides utilities for working with slices
package
xslice
import
(
"../xmath"
)
// Grow increase length of slice by n elements.
// If there is not enough capacity the slice is reallocated.
// The memory for grown elements are not initialized.
func
Grow
(
b
[]
byte
,
n
int
)
[]
byte
{
ln
:=
len
(
b
)
+
n
if
ln
<=
cap
(
b
)
{
return
b
[
:
ln
]
}
bb
:=
make
([]
byte
,
ln
,
xmath
.
CeilPow2
(
uint64
(
ln
)))
copy
(
bb
,
b
)
return
bb
}
// Resize resized the slice to be of length n.
// If slice length is increased and there is not enough capacity the slice is reallocated.
// The memory for grown elements, if any, is not initialized.
func
Resize
(
b
[]
byte
,
n
int
)
[]
byte
{
if
cap
(
b
)
>=
n
{
return
b
[
:
n
]
}
bb
:=
make
([]
byte
,
n
,
xmath
.
CeilPow2
(
uint64
(
n
)))
copy
(
bb
,
b
)
return
bb
}
// TODO Resize without copy ?
// // GrowSlice makes sure cap(b) >= n.
// // If not it reallocates/copies the slice appropriately.
// // len of returned slice remains original len(b).
// func GrowSlice(b []byte, n int) []byte {
// if cap(b) >= n {
// return b
// }
//
// bb := make([]byte, len(b), CeilPow2(uint64(n)))
// copy(bb, b)
// return bb
// }
//
// // makeRoom makes sure len([len(b):cap(b)]) >= n.
// // If it is not it reallocates the slice appropriately.
// // len of returned slice remains original len(b).
// func MakeRoom(b []byte, n int) []byte {
// return GrowSlice(b, len(b) + n)
// }
t/neo/xcommon/xslice/slice_test.go
0 → 100644
View file @
2121ce8a
package
xslice
//import (
// "testing"
//)
// TODO
// func TestGrowSlice(t *testing) {
// testv := []struct {in []byte, n int, Cap int} {
// {nil, 0, 0},
// }
//
// }
t/neo/zodb/cmd/zodbdump/zodbdump_test.go
View file @
2121ce8a
...
...
@@ -55,9 +55,7 @@ func loadZdumpPy(t *testing.T, path string) string {
return
string
(
dump
)
}
func
TestZodbDump
(
t
*
testing
.
T
)
{
buf
:=
bytes
.
Buffer
{}
func
withTestdata1Fs
(
t
testing
.
TB
,
f
func
(
fs
*
fs1
.
FileStorage
))
{
fs
,
err
:=
fs1
.
Open
(
"../../../storage/fs1/testdata/1.fs"
)
// XXX read-only, path?
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -65,7 +63,14 @@ func TestZodbDump(t *testing.T) {
defer
exc
.
XRun
(
fs
.
Close
)
err
=
zodbDump
(
&
buf
,
fs
,
0
,
zodb
.
TidMax
,
false
)
f
(
fs
)
}
func
TestZodbDump
(
t
*
testing
.
T
)
{
withTestdata1Fs
(
t
,
func
(
fs
*
fs1
.
FileStorage
)
{
buf
:=
bytes
.
Buffer
{}
err
:=
zodbDump
(
&
buf
,
fs
,
0
,
zodb
.
TidMax
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -75,4 +80,22 @@ func TestZodbDump(t *testing.T) {
if
dumpOk
!=
buf
.
String
()
{
t
.
Errorf
(
"dump different:
\n
%v"
,
diff
(
dumpOk
,
buf
.
String
()))
}
})
}
func
BenchmarkZodbDump
(
b
*
testing
.
B
)
{
// FIXME small testdata/1.fs is not representative for benchmarking
withTestdata1Fs
(
b
,
func
(
fs
*
fs1
.
FileStorage
)
{
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
err
:=
zodbDump
(
ioutil
.
Discard
,
fs
,
0
,
zodb
.
TidMax
,
false
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
}
b
.
StopTimer
()
})
}
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