Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
4742e0bc
Commit
4742e0bc
authored
Aug 10, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
ed0b3d33
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
6 deletions
+44
-6
wcfs/zblk.go
wcfs/zblk.go
+44
-6
No files found.
wcfs/zblk.go
View file @
4742e0bc
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment