Commit a3907113 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9c7241dc
...@@ -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, sys, subprocess
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))
......
...@@ -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
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment