chunk group remove manifestChunks and reset sections in SetChunks()
This commit is contained in:
@@ -8,11 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ChunkGroup struct {
|
type ChunkGroup struct {
|
||||||
lookupFn wdclient.LookupFileIdFunctionType
|
lookupFn wdclient.LookupFileIdFunctionType
|
||||||
chunkCache chunk_cache.ChunkCache
|
chunkCache chunk_cache.ChunkCache
|
||||||
manifestChunks []*filer_pb.FileChunk
|
sections map[SectionIndex]*FileChunkSection
|
||||||
sections map[SectionIndex]*FileChunkSection
|
sectionsLock sync.RWMutex
|
||||||
sectionsLock sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChunkGroup(lookupFn wdclient.LookupFileIdFunctionType, chunkCache chunk_cache.ChunkCache, chunks []*filer_pb.FileChunk) (*ChunkGroup, error) {
|
func NewChunkGroup(lookupFn wdclient.LookupFileIdFunctionType, chunkCache chunk_cache.ChunkCache, chunks []*filer_pb.FileChunk) (*ChunkGroup, error) {
|
||||||
@@ -69,6 +68,9 @@ func (group *ChunkGroup) ReadDataAt(fileSize int64, buff []byte, offset int64) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (group *ChunkGroup) SetChunks(chunks []*filer_pb.FileChunk) error {
|
func (group *ChunkGroup) SetChunks(chunks []*filer_pb.FileChunk) error {
|
||||||
|
group.sectionsLock.RLock()
|
||||||
|
defer group.sectionsLock.RUnlock()
|
||||||
|
|
||||||
var dataChunks []*filer_pb.FileChunk
|
var dataChunks []*filer_pb.FileChunk
|
||||||
for _, chunk := range chunks {
|
for _, chunk := range chunks {
|
||||||
|
|
||||||
@@ -82,21 +84,24 @@ func (group *ChunkGroup) SetChunks(chunks []*filer_pb.FileChunk) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
group.manifestChunks = append(group.manifestChunks, chunk)
|
|
||||||
dataChunks = append(dataChunks, resolvedChunks...)
|
dataChunks = append(dataChunks, resolvedChunks...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sections := make(map[SectionIndex]*FileChunkSection)
|
||||||
|
|
||||||
for _, chunk := range dataChunks {
|
for _, chunk := range dataChunks {
|
||||||
sectionIndexStart, sectionIndexStop := SectionIndex(chunk.Offset/SectionSize), SectionIndex((chunk.Offset+int64(chunk.Size))/SectionSize)
|
sectionIndexStart, sectionIndexStop := SectionIndex(chunk.Offset/SectionSize), SectionIndex((chunk.Offset+int64(chunk.Size))/SectionSize)
|
||||||
for si := sectionIndexStart; si < sectionIndexStop+1; si++ {
|
for si := sectionIndexStart; si < sectionIndexStop+1; si++ {
|
||||||
section, found := group.sections[si]
|
section, found := sections[si]
|
||||||
if !found {
|
if !found {
|
||||||
section = NewFileChunkSection(si)
|
section = NewFileChunkSection(si)
|
||||||
group.sections[si] = section
|
sections[si] = section
|
||||||
}
|
}
|
||||||
section.chunks = append(section.chunks, chunk)
|
section.chunks = append(section.chunks, chunk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.sections = sections
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user