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