aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2023-01-10 00:49:31 -0800
committerchrislu <chris.lu@gmail.com>2023-01-10 00:49:31 -0800
commit340e7c3a2e3b6fa64018bad1960b7afcf1f222eb (patch)
tree5c5171664980b382fa2686a0760052f5a6b8b426
parente650c8397daa0572e848ce425d92ac1d2294f531 (diff)
downloadseaweedfs-340e7c3a2e3b6fa64018bad1960b7afcf1f222eb.tar.xz
seaweedfs-340e7c3a2e3b6fa64018bad1960b7afcf1f222eb.zip
chunk group remove manifestChunks and reset sections in SetChunks()
-rw-r--r--weed/filer/filechunk_group.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/weed/filer/filechunk_group.go b/weed/filer/filechunk_group.go
index 5dbf16a5c..de469f310 100644
--- a/weed/filer/filechunk_group.go
+++ b/weed/filer/filechunk_group.go
@@ -8,11 +8,10 @@ import (
)
type ChunkGroup struct {
- lookupFn wdclient.LookupFileIdFunctionType
- chunkCache chunk_cache.ChunkCache
- manifestChunks []*filer_pb.FileChunk
- sections map[SectionIndex]*FileChunkSection
- sectionsLock sync.RWMutex
+ lookupFn wdclient.LookupFileIdFunctionType
+ chunkCache chunk_cache.ChunkCache
+ sections map[SectionIndex]*FileChunkSection
+ sectionsLock sync.RWMutex
}
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 {
+ group.sectionsLock.RLock()
+ defer group.sectionsLock.RUnlock()
+
var dataChunks []*filer_pb.FileChunk
for _, chunk := range chunks {
@@ -82,21 +84,24 @@ func (group *ChunkGroup) SetChunks(chunks []*filer_pb.FileChunk) error {
return err
}
- group.manifestChunks = append(group.manifestChunks, chunk)
dataChunks = append(dataChunks, resolvedChunks...)
}
+ sections := make(map[SectionIndex]*FileChunkSection)
+
for _, chunk := range dataChunks {
sectionIndexStart, sectionIndexStop := SectionIndex(chunk.Offset/SectionSize), SectionIndex((chunk.Offset+int64(chunk.Size))/SectionSize)
for si := sectionIndexStart; si < sectionIndexStop+1; si++ {
- section, found := group.sections[si]
+ section, found := sections[si]
if !found {
section = NewFileChunkSection(si)
- group.sections[si] = section
+ sections[si] = section
}
section.chunks = append(section.chunks, chunk)
}
}
+
+ group.sections = sections
return nil
}