Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
a3907113
Commit
a3907113
authored
Oct 10, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
9c7241dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
12 deletions
+30
-12
wcfs/wcfs_test.py
wcfs/wcfs_test.py
+14
-9
wcfs/zblk.go
wcfs/zblk.go
+16
-3
No files found.
wcfs/wcfs_test.py
View file @
a3907113
...
@@ -30,7 +30,7 @@ import transaction
...
@@ -30,7 +30,7 @@ import transaction
from
persistent
import
Persistent
from
persistent
import
Persistent
from
persistent.timestamp
import
TimeStamp
from
persistent.timestamp
import
TimeStamp
import
os
,
os
.
path
,
subprocess
import
os
,
os
.
path
,
s
ys
,
s
ubprocess
from
errno
import
EINVAL
from
errno
import
EINVAL
from
golang
import
func
,
method
,
defer
from
golang
import
func
,
method
,
defer
from
pytest
import
raises
from
pytest
import
raises
...
@@ -122,6 +122,7 @@ def test_join_autostart():
...
@@ -122,6 +122,7 @@ def test_join_autostart():
# Conn._sync makes sure that underlying wcfs is synced to last ZODB data
# Conn._sync makes sure that underlying wcfs is synced to last ZODB data
@
method
(
wcfs
.
Conn
)
@
method
(
wcfs
.
Conn
)
def
_sync
(
self
):
def
_sync
(
self
):
print
>>
sys
.
stderr
,
"
\
n
# >>> wcfs.Conn.sync"
zurl
=
readfile
(
self
.
mountpoint
+
"/.wcfs"
)
zurl
=
readfile
(
self
.
mountpoint
+
"/.wcfs"
)
bigfilev
=
os
.
listdir
(
self
.
mountpoint
+
"/bigfile"
)
bigfilev
=
os
.
listdir
(
self
.
mountpoint
+
"/bigfile"
)
self
.
close
()
self
.
close
()
...
@@ -135,6 +136,8 @@ def _sync(self):
...
@@ -135,6 +136,8 @@ def _sync(self):
for
bf
in
bigfilev
:
for
bf
in
bigfilev
:
os
.
mkdir
(
"%s/bigfile/%s"
%
(
self
.
mountpoint
,
bf
))
os
.
mkdir
(
"%s/bigfile/%s"
%
(
self
.
mountpoint
,
bf
))
print
>>
sys
.
stderr
,
"# <<< wcfs.Conn.sync
\
n
"
# XXX parametrize zblk0, zblk1
# XXX parametrize zblk0, zblk1
# XXX select !wcfs mode so that we prepare data through !wcfs path.
# XXX select !wcfs mode so that we prepare data through !wcfs path.
...
@@ -184,8 +187,9 @@ def test_bigfile_empty():
...
@@ -184,8 +187,9 @@ def test_bigfile_empty():
# commit data to f and make sure we can see it on wcfs
# commit data to f and make sure we can see it on wcfs
hole
=
10
fh
=
f
.
fileh_open
()
fh
=
f
.
fileh_open
()
vma
=
fh
.
mmap
(
10
,
1
)
# 1 page at offset=10
vma
=
fh
.
mmap
(
hole
,
1
)
# 1 page at offset=10
s
=
b"hello world"
s
=
b"hello world"
memcpy
(
vma
,
s
)
memcpy
(
vma
,
s
)
...
@@ -193,23 +197,24 @@ def test_bigfile_empty():
...
@@ -193,23 +197,24 @@ def test_bigfile_empty():
transaction
.
commit
()
transaction
.
commit
()
tidlast
=
last
.
_p_serial
tidlast
=
last
.
_p_serial
#
XXX force sync of wcfs - how?
#
sync wcfs to ZODB
wc
.
_sync
()
wc
.
_sync
()
fsize
=
10
*
blksize
+
len
(
s
)
# trailing \0 not counted XXX ok? -> XXX not ok
# we wrote "hello world" afte 10th block, but size is always mutiple of blksize.
fsize
=
(
hole
+
1
)
*
blksize
"""
st
=
os
.
stat
(
fpath
+
"/head/data"
)
st
=
os
.
stat
(
fpath
+
"/head/data"
)
assert
st
.
st_size
==
fsize
assert
st
.
st_size
==
fsize
assert st.st_mtime == tidtime(tidlast)
#assert st.st_mtime == tidtime(tidlast) FIXME proper sync
assert
readfile
(
fpath
+
"/head/at"
)
==
tidlast
.
encode
(
"hex"
)
assert
readfile
(
fpath
+
"/head/at"
)
==
tidlast
.
encode
(
"hex"
)
"""
data
=
readfile
(
fpath
+
"/head/data"
)
data
=
readfile
(
fpath
+
"/head/data"
)
assert
len
(
data
)
==
fsize
assert
len
(
data
)
==
fsize
for
i
in
range
(
10
):
for
i
in
range
(
hole
):
assert
data
[
i
*
blksize
:(
i
+
1
)
*
blksize
]
==
b'
\
0
'
*
blksize
assert
data
[
i
*
blksize
:(
i
+
1
)
*
blksize
]
==
b'
\
0
'
*
blksize
assert
data
[
10
*
blksize
:]
==
s
tail
=
data
[
hole
*
blksize
:]
assert
tail
[:
len
(
s
)]
==
s
assert
tail
[
len
(
s
):]
==
b'
\
0
'
*
(
blksize
-
len
(
s
))
...
...
wcfs/zblk.go
View file @
a3907113
...
@@ -39,6 +39,7 @@ package main
...
@@ -39,6 +39,7 @@ package main
import
(
import
(
"context"
"context"
"fmt"
"fmt"
"log"
"reflect"
"reflect"
"sort"
"sort"
"sync"
"sync"
...
@@ -60,7 +61,8 @@ import (
...
@@ -60,7 +61,8 @@ import (
type
zBlkLoader
interface
{
type
zBlkLoader
interface
{
// loadBlkData loads from database and returns data block stored by this ZBlk.
// loadBlkData loads from database and returns data block stored by this ZBlk.
//
//
// XXX trailing \0 can be stripped.
// If returned data size is less than the block size of containing ZBigFile,
// the block trailing is assumed to be trailing \0.
loadBlkData
(
ctx
context
.
Context
)
([]
byte
,
error
)
loadBlkData
(
ctx
context
.
Context
)
([]
byte
,
error
)
}
}
...
@@ -89,6 +91,7 @@ func (zb *zBlk0State) PySetState(pystate interface{}) error {
...
@@ -89,6 +91,7 @@ func (zb *zBlk0State) PySetState(pystate interface{}) error {
return
fmt
.
Errorf
(
"expect str; got %s"
,
typeOf
(
pystate
))
return
fmt
.
Errorf
(
"expect str; got %s"
,
typeOf
(
pystate
))
}
}
log
.
Printf
(
"ZBlk0.PySetState #%d"
,
len
(
blkdata
))
zb
.
blkdata
=
blkdata
zb
.
blkdata
=
blkdata
return
nil
return
nil
}
}
...
@@ -122,6 +125,7 @@ func (zd *zDataState) DropState() {
...
@@ -122,6 +125,7 @@ func (zd *zDataState) DropState() {
}
}
func
(
zd
*
zDataState
)
PySetState
(
pystate
interface
{})
error
{
func
(
zd
*
zDataState
)
PySetState
(
pystate
interface
{})
error
{
log
.
Printf
(
"ZData.PySetState"
)
data
,
ok
:=
pystate
.
(
string
)
data
,
ok
:=
pystate
.
(
string
)
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"expect str; got %s"
,
typeOf
(
pystate
))
return
fmt
.
Errorf
(
"expect str; got %s"
,
typeOf
(
pystate
))
...
@@ -145,6 +149,7 @@ func (zb *zBlk1State) DropState() {
...
@@ -145,6 +149,7 @@ func (zb *zBlk1State) DropState() {
}
}
func
(
zb
*
zBlk1State
)
PySetState
(
pystate
interface
{})
error
{
func
(
zb
*
zBlk1State
)
PySetState
(
pystate
interface
{})
error
{
log
.
Printf
(
"ZBlk1.PySetState"
)
chunktab
,
ok
:=
pystate
.
(
*
btree
.
IOBTree
)
chunktab
,
ok
:=
pystate
.
(
*
btree
.
IOBTree
)
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"expect IOBTree; got %s"
,
typeOf
(
pystate
))
return
fmt
.
Errorf
(
"expect IOBTree; got %s"
,
typeOf
(
pystate
))
...
@@ -395,11 +400,19 @@ func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, err error
...
@@ -395,11 +400,19 @@ func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, err error
return
nil
,
err
return
nil
,
err
}
}
if
l
:=
int64
(
len
(
blkdata
));
l
>
bf
.
blksize
{
l
:=
int64
(
len
(
blkdata
))
if
l
>
bf
.
blksize
{
return
nil
,
fmt
.
Errorf
(
"invalid blk: size = %d (> blksize = %d)"
,
l
,
bf
.
blksize
)
return
nil
,
fmt
.
Errorf
(
"invalid blk: size = %d (> blksize = %d)"
,
l
,
bf
.
blksize
)
}
}
// XXX append trailing \0 to reach .blksize ?
// append trailing \0 to data to reach .blksize
if
l
<
bf
.
blksize
{
d
:=
make
([]
byte
,
bf
.
blksize
)
copy
(
d
,
blkdata
)
blkdata
=
d
}
log
.
Printf
(
"ZBigFile.loadblk(%d) -> %dB"
,
blk
,
len
(
blkdata
))
return
blkdata
,
nil
return
blkdata
,
nil
}
}
...
...
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