Commit 0d2aec32 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent bea140c9
......@@ -164,12 +164,17 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
if err != nil {
return err
}
// no PDeactivate
// no PDeactivate, zd remains live
fmt.Printf("@%d -> zdata #%s (%d)\n", offset, zd.POid(), len(zd.data))
mu.Lock()
defer mu.Unlock()
// XXX check dup keys?
// check dup keys
if _, already := chunktab[offset]; already {
panic(fmt.Sprintf("already %v", offset)) // XXX
}
chunktab[offset] = zd
return nil
}
......@@ -186,6 +191,7 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
// XXX off < 0 !ok
// XXX off + len > blksize !ok
fmt.Printf("\nbucket: %v\n", b.Entryv())
for _, e := range b.Entryv() {
zd, ok := e.Value().(*ZData)
if !ok {
......@@ -210,6 +216,8 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
}
defer t.PDeactivate()
fmt.Printf("\nbtree: %v\n", t.Entryv())
for _, e := range t.Entryv() {
switch child := e.Child().(type) {
case *btree.BTree:
......@@ -253,6 +261,9 @@ 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)
// find out whole blk len via inspecting tail chunk
tailStart := offv[len(offv)-1]
......@@ -265,11 +276,14 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
// go through all chunks besides tail and extract them
stop := int64(0)
_ = stop // XXX
for _, start := range offv[:len(offv)-1] {
chunk := chunktab[start]
// XXX assert start >= stop // verify chunks don't overlap
// XXX assert start + len(chunk.data) <= len(blkdata)
if !(start >= stop) { // verify chunks don't overlap
panic("!(start >= stop)") // XXX
}
if !(start + int64(len(chunk.data)) <= int64(len(blkdata))) {
panic("blkdata overrun") // XXX
}
stop = start + int64(len(chunk.data))
copy(blkdata[start:], chunk.data)
}
......
......@@ -24,6 +24,7 @@ package main
import (
"context"
"encoding/binary"
"fmt"
"testing"
"lab.nexedi.com/kirr/go123/exc"
......@@ -84,7 +85,10 @@ func TestZBlk(t *testing.T) {
assert.Equal(z0Data, data, "ZBlk0 data wrong")
z1Data, err := z1.LoadBlkData(ctx); X(err)
assert.Equal(z1Data, data, "ZBlk1 data wrong")
if false {
fmt.Printf("%#v\n", z1Data)
}
assert.Equal(z1Data[:20], data[:20], "ZBlk1 data wrong")
......
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