Commit 313bc6ab authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8081df49
......@@ -117,7 +117,7 @@ func (zb *zBlk1State) DropState() {
func (zb *zBlk1State) PySetState(pystate interface{}) error {
chunktab, ok := pystate.(*btree.IOBTree)
if !ok {
//return fmt.Errorf("expect IOBTree; got %T", pystate)
//return fmt.Errorf("expect IOBTree; got %T", pystate) XXX no details for Broken
return fmt.Errorf("expect IOBTree; got %#v", pystate)
}
......@@ -134,12 +134,6 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
}
defer zb.PDeactivate()
// // empty .chunktab -> ø
// ev := zb.chunktab.Entryv()
// if len(ev) == 0 {
// return nil, nil
// }
// get to all ZData objects; activate them and build
//
// {} offset -> ZData
......@@ -148,7 +142,7 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
var mu sync.Mutex
chunktab := make(map[int32]*ZData)
// on return deactivate all loaded ZData objects in chunktab
// on return deactivate all ZData objects loaded in chunktab
defer func() {
for _, zd := range chunktab {
zd.PDeactivate()
......@@ -166,15 +160,11 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
}
// no PDeactivate, zd remains live
fmt.Printf("@%d -> zdata #%s (%d)\n", offset, zd.POid(), len(zd.data))
//fmt.Printf("@%d -> zdata #%s (%d)\n", offset, zd.POid(), len(zd.data))
mu.Lock()
defer mu.Unlock()
// check dup keys
if _, already := chunktab[offset]; already {
panic(fmt.Sprintf("already %v", offset)) // XXX
}
chunktab[offset] = zd
return nil
}
......@@ -187,19 +177,21 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
}
defer b.PDeactivate()
// XXX go through all bucket key/v -> chunktab
// go through all bucket key/v -> chunktab
// XXX off < 0 !ok
// XXX off + len > blksize !ok
fmt.Printf("\nbucket: %v\n", b.Entryv())
//fmt.Printf("\nbucket: %v\n\n", b.Entryv())
for _, e := range b.Entryv() {
zd, ok := e.Value().(*ZData)
if !ok {
return fmt.Errorf("!ZData (%T)", e.Value()) // XXX
}
offset := e.Key()
wg.Go(func() error {
return loadZData(e.Key(), zd)
return loadZData(offset, zd)
})
}
......@@ -216,7 +208,7 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
}
defer t.PDeactivate()
fmt.Printf("\nbtree: %v\n", t.Entryv())
//fmt.Printf("\nbtree: %v\n\n", t.Entryv())
for _, e := range t.Entryv() {
switch child := e.Child().(type) {
......@@ -231,7 +223,7 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
})
default:
panic(0) // XXX
panic(fmt.Sprintf("IOBTree has %T child", child))
}
}
......@@ -261,8 +253,8 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
return offv[i] < offv[j]
})
fmt.Printf("#chunktab: %d\n", len(chunktab))
fmt.Printf("offv: %v\n", offv)
//fmt.Printf("#chunktab: %d\n", len(chunktab))
//fmt.Printf("offv: %v\n", offv)
// find out whole blk len via inspecting tail chunk
......@@ -279,10 +271,10 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
for _, start := range offv[:len(offv)-1] {
chunk := chunktab[start]
if !(start >= stop) { // verify chunks don't overlap
panic("!(start >= stop)") // XXX
return nil, fmt.Errorf("!(start >= stop)") // XXX
}
if !(start + int32(len(chunk.data)) <= int32(len(blkdata))) { // XXX overflow?
panic("blkdata overrun") // XXX
return nil, fmt.Errorf("blkdata overrun") // XXX
}
stop = start + int32(len(chunk.data)) // XXX overflow?
copy(blkdata[start:], chunk.data)
......
......@@ -21,6 +21,10 @@ package main
//go:generate ./testdata/zblk_test_gen.py
// XXX do not commit 4MB (ZBlk*) to testdata - generate them at test runtime.
// XXX save into git only small-sized ZBlk0 and ZBlk1 so that we can be sure
// their format does not change.
import (
"context"
"encoding/binary"
......
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