Commit 4e0c9ad3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5ebd8119
......@@ -184,7 +184,7 @@ func (zb *ZBlk0) loadBlkData(ctx context.Context) (_ []byte, _ zodb.Tid, err err
type ZData struct {
zodb.Persistent
// XXX py source uses bytes(buf) but on python2 it still results in str
// NOTE py source uses bytes(buf) but on python2 it still results in str
data string
}
......@@ -199,7 +199,6 @@ func (zd *zDataState) PyGetState() interface{} {
}
func (zd *zDataState) PySetState(pystate interface{}) error {
//log.Printf("ZData.PySetState")
data, ok := pystate.(string)
if !ok {
return fmt.Errorf("expect str; got %s", typeOf(pystate))
......@@ -228,7 +227,6 @@ func (zb *zBlk1State) PyGetState() interface{} {
}
func (zb *zBlk1State) PySetState(pystate interface{}) error {
//log.Printf("ZBlk1.PySetState")
chunktab, ok := pystate.(*btree.IOBTree)
if !ok {
return fmt.Errorf("expect IOBTree; got %s", typeOf(pystate))
......@@ -266,8 +264,8 @@ func (zb *ZBlk1) loadBlkData(ctx context.Context) (_ []byte, _ zodb.Tid, err err
wg := xsync.NewWorkGroup(ctx)
// loadZData loads 1 ZData object into chunktab and leaves it activated.
loadZData := func(ctx context.Context, offset int32, zd *ZData) error {
err := zd.PActivate(ctx)
loadZData := func(ctx context.Context, offset int32, zd *ZData) (err error) {
err = zd.PActivate(ctx)
if err != nil {
return err
}
......@@ -277,32 +275,37 @@ func (zb *ZBlk1) loadBlkData(ctx context.Context) (_ []byte, _ zodb.Tid, err err
mu.Lock()
defer mu.Unlock()
_, already := chunktab[offset]
if already {
return fmt.Errorf("duplicate offset %d", offset)
}
chunktab[offset] = zd
return nil
}
// loadBucket loads all ZData objects from leaf BTree bucket.
loadBucket := func(ctx context.Context, b *btree.IOBucket) error {
err := b.PActivate(ctx)
loadBucket := func(ctx context.Context, b *btree.IOBucket) (err error) {
err = b.PActivate(ctx)
if err != nil {
return err
}
defer b.PDeactivate()
// go through all bucket key/v -> chunktab
// XXX off < 0 !ok
// XXX off + len > blksize !ok
defer xerr.Contextf(&err, "%s(%s)", typeOf(b), b.POid())
//fmt.Printf("\nbucket: %v\n\n", b.Entryv())
for _, e := range b.Entryv() {
for i, e := range b.Entryv() {
zd, ok := e.Value().(*ZData)
if !ok {
return fmt.Errorf("!ZData (%s)", typeOf(e.Value()))
return fmt.Errorf("[%d]: !ZData (%s)", i, typeOf(e.Value()))
}
offset := e.Key()
if offset < 0 {
return fmt.Errorf("[%d]: offset < 0 (%d)", i, offset)
}
wg.Go(func(ctx context.Context) error {
return loadZData(ctx, offset, zd)
})
......@@ -321,7 +324,6 @@ func (zb *ZBlk1) loadBlkData(ctx context.Context) (_ []byte, _ zodb.Tid, err err
defer t.PDeactivate()
//fmt.Printf("\nbtree: %v\n\n", t.Entryv())
for _, e := range t.Entryv() {
switch child := e.Child().(type) {
case *btree.IOBTree:
......@@ -348,7 +350,7 @@ func (zb *ZBlk1) loadBlkData(ctx context.Context) (_ []byte, _ zodb.Tid, err err
err = wg.Wait()
if err != nil {
return nil, 0, err // XXX err ctx
return nil, 0, err
}
// empty .chunktab -> ø
......
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