Commit 4742e0bc authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ed0b3d33
......@@ -25,6 +25,7 @@ import (
"context"
"fmt"
"reflect"
"sort"
"sync"
"golang.org/x/sync/errgroup"
......@@ -147,6 +148,14 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
var mu sync.Mutex
chunktab := make(map[int64]*ZData)
// on return deactivate all loaded ZData objects in chunktab
defer func() {
for _, zd := range chunktab {
zd.PDeactivate()
}
}()
wg, ctx := errgroup.WithContext(ctx)
// loadZData loads 1 ZData object into chunktab and leaves it activated.
......@@ -226,17 +235,46 @@ func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
})
err = wg.Wait()
if err != nil {
return nil, err // XXX err ctx
}
// deactivate all loaded ZData objects in chunktab
for _, zd := range chunktab {
zd.PDeactivate()
// empty .chunktab -> ø
if len(chunktab) == 0 {
return nil, nil
}
if err != nil {
panic(err) // XXX
// glue all chunks from chunktab
offv := make([]int64, 0, len(chunktab)) // ↑
for off := range(chunktab) {
offv = append(offv, off)
}
sort.Slice(offv, func(i, j int) bool {
return offv[i] < offv[j]
})
// find out whole blk len via inspecting tail chunk
tailStart := offv[len(offv)-1]
tailChunk := chunktab[tailStart]
blklen := tailStart + int64(len(tailChunk.data))
// whole buffer initialized as 0 + tail_chunk
blkdata := make([]byte, blklen)
copy(blkdata[tailStart:], tailChunk.data)
// 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)
stop = start + int64(len(chunk.data))
copy(blkdata[start:], chunk.data)
}
panic("TODO")
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