Browse Source

chunk group remove manifestChunks and reset sections in SetChunks()

pull/3942/merge
chrislu 2 years ago
parent
commit
340e7c3a2e
  1. 13
      weed/filer/filechunk_group.go

13
weed/filer/filechunk_group.go

@ -10,7 +10,6 @@ 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
} }
@ -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
} }

Loading…
Cancel
Save