incrementally calculate visible intervals

This commit is contained in:
Chris Lu 2019-01-05 22:23:44 -08:00
parent 6b5d6bb5a6
commit be9a7592a1
2 changed files with 22 additions and 12 deletions

View file

@ -118,7 +118,7 @@ var bufPool = sync.Pool{
},
}
func mergeIntoVisibles(visibles, newVisibles []VisibleInterval, chunk *filer_pb.FileChunk) []VisibleInterval {
func MergeIntoVisibles(visibles, newVisibles []VisibleInterval, chunk *filer_pb.FileChunk) []VisibleInterval {
newV := newVisibleInterval(
chunk.Offset,
@ -185,12 +185,12 @@ func NonOverlappingVisibleIntervals(chunks []*filer_pb.FileChunk) (visibles []Vi
return chunks[i].Mtime < chunks[j].Mtime
})
var newVislbles []VisibleInterval
var newVisibles []VisibleInterval
for _, chunk := range chunks {
newVislbles = mergeIntoVisibles(visibles, newVislbles, chunk)
newVisibles = MergeIntoVisibles(visibles, newVisibles, chunk)
t := visibles[:0]
visibles = newVislbles
newVislbles = t
visibles = newVisibles
newVisibles = t
logPrintf("add", visibles)

View file

@ -2,14 +2,16 @@ package filesys
import (
"context"
"os"
"path/filepath"
"sort"
"time"
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/fuse"
"github.com/seaweedfs/fuse/fs"
"os"
"path/filepath"
"time"
)
const blockSize = 512
@ -179,12 +181,20 @@ func (file *File) addChunk(chunk *filer_pb.FileChunk) {
}
func (file *File) addChunks(chunks []*filer_pb.FileChunk) {
sort.Slice(chunks, func(i, j int) bool {
return chunks[i].Mtime < chunks[j].Mtime
})
var newVisibles []filer2.VisibleInterval
for _, chunk := range chunks {
file.entry.Chunks = append(file.entry.Chunks, chunk)
file.entryViewCache = nil
glog.V(4).Infof("uploaded %s/%s to %s [%d,%d)", file.dir.Path, file.Name, chunk.FileId, chunk.Offset, chunk.Offset+int64(chunk.Size))
newVisibles = filer2.MergeIntoVisibles(file.entryViewCache, newVisibles, chunk)
t := file.entryViewCache[:0]
file.entryViewCache = newVisibles
newVisibles = t
}
file.entryViewCache = filer2.NonOverlappingVisibleIntervals(file.entry.Chunks)
file.entry.Chunks = append(file.entry.Chunks, chunks...)
}
func (file *File) setEntry(entry *filer_pb.Entry) {