aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-11-18 11:51:38 -0800
committerChris Lu <chris.lu@gmail.com>2018-11-18 11:51:38 -0800
commit4fcfc9410fd407165d7bb1c047bcd21e5b2b7dde (patch)
treefabdbc2da727e125ec354f5f6f8de2f7589e5bb0 /weed/filer2
parent9655dc9ca95312d578d60e71d839a6b9971a7bea (diff)
downloadseaweedfs-4fcfc9410fd407165d7bb1c047bcd21e5b2b7dde.tar.xz
seaweedfs-4fcfc9410fd407165d7bb1c047bcd21e5b2b7dde.zip
cleanup
Diffstat (limited to 'weed/filer2')
-rw-r--r--weed/filer2/filechunks.go24
-rw-r--r--weed/filer2/filechunks_test.go3
-rw-r--r--weed/filer2/filer.go5
3 files changed, 29 insertions, 3 deletions
diff --git a/weed/filer2/filechunks.go b/weed/filer2/filechunks.go
index 7fd4af5df..79aa50ec8 100644
--- a/weed/filer2/filechunks.go
+++ b/weed/filer2/filechunks.go
@@ -4,6 +4,7 @@ import (
"fmt"
"hash/fnv"
"sort"
+ "sync"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
@@ -46,6 +47,8 @@ func CompactFileChunks(chunks []*filer_pb.FileChunk) (compacted, garbage []*file
}
}
+ cleanupIntervals(visibles)
+
return
}
@@ -89,6 +92,8 @@ func ViewFromChunks(chunks []*filer_pb.FileChunk, offset int64, size int) (views
}
}
+ cleanupIntervals(visibles)
+
return views
}
@@ -102,6 +107,12 @@ func logPrintf(name string, visibles []*visibleInterval) {
*/
}
+var bufPool = sync.Pool{
+ New: func() interface{} {
+ return new(visibleInterval)
+ },
+}
+
func mergeIntoVisibles(visibles []*visibleInterval, chunk *filer_pb.FileChunk) (newVisibles []*visibleInterval) {
for _, v := range visibles {
if v.start < chunk.Offset && chunk.Offset < v.stop {
@@ -153,6 +164,12 @@ func nonOverlappingVisibleIntervals(chunks []*filer_pb.FileChunk) (visibles []*v
return
}
+func cleanupIntervals(visibles []*visibleInterval) {
+ for _, v := range visibles {
+ bufPool.Put(v)
+ }
+}
+
// find non-overlapping visible intervals
// visible interval map to one file chunk
@@ -164,7 +181,12 @@ type visibleInterval struct {
}
func newVisibleInterval(start, stop int64, fileId string, modifiedTime int64) *visibleInterval {
- return &visibleInterval{start: start, stop: stop, fileId: fileId, modifiedTime: modifiedTime}
+ b := bufPool.Get().(*visibleInterval)
+ b.start = start
+ b.stop = stop
+ b.fileId = fileId
+ b.modifiedTime = modifiedTime
+ return b
}
func min(x, y int64) int64 {
diff --git a/weed/filer2/filechunks_test.go b/weed/filer2/filechunks_test.go
index 90aa3df36..1b124981f 100644
--- a/weed/filer2/filechunks_test.go
+++ b/weed/filer2/filechunks_test.go
@@ -161,6 +161,9 @@ func TestIntervalMerging(t *testing.T) {
if len(intervals) != len(testcase.Expected) {
t.Fatalf("failed to compact test case %d, len %d expected %d", i, len(intervals), len(testcase.Expected))
}
+
+ cleanupIntervals(intervals)
+
}
}
diff --git a/weed/filer2/filer.go b/weed/filer2/filer.go
index 1c9f2cde4..f6f013933 100644
--- a/weed/filer2/filer.go
+++ b/weed/filer2/filer.go
@@ -3,6 +3,7 @@ package filer2
import (
"context"
"fmt"
+ "math"
"os"
"path/filepath"
"strings"
@@ -13,7 +14,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/wdclient"
"github.com/karlseguin/ccache"
- "math"
+ "github.com/chrislusf/seaweedfs/weed/storage"
)
type Filer struct {
@@ -240,7 +241,7 @@ func (f *Filer) DeleteFileByFileId(fileId string) {
if err != nil {
glog.V(0).Infof("can not find file %s: %v", fileId, err)
}
- if _, err := operation.DeleteFilesAtOneVolumeServer(volumeServer, []string{fileId}); err != nil {
+ if _, err := operation.DeleteFilesAtOneVolumeServer(volumeServer, []string{fileId}); err != nil && err != storage.NotFound{
glog.V(0).Infof("deleting file %s: %v", fileId, err)
}
}