aboutsummaryrefslogtreecommitdiff
path: root/weed/filer
diff options
context:
space:
mode:
authorguosj <515878133@qq.com>2022-04-19 09:25:32 +0800
committerguosj <515878133@qq.com>2022-04-19 09:25:32 +0800
commit82ee31965dd7a1ad2d348c7e9dadb254744bf9b0 (patch)
tree593eb933dffc877010c761b2c55ec6c73875e9a3 /weed/filer
parent5c9a3bb8cf68ed99acb53dd548c92b54744d7fd7 (diff)
parente6ebafc094dc0ce0e3b0a68d7735f52a544bc479 (diff)
downloadseaweedfs-82ee31965dd7a1ad2d348c7e9dadb254744bf9b0.tar.xz
seaweedfs-82ee31965dd7a1ad2d348c7e9dadb254744bf9b0.zip
Merge branch 'master' of https://github.com/chrislusf/seaweedfs into chrislusf-master
Diffstat (limited to 'weed/filer')
-rw-r--r--weed/filer/filechunks.go21
-rw-r--r--weed/filer/filechunks2_test.go10
-rw-r--r--weed/filer/filechunks_read.go17
-rw-r--r--weed/filer/filer.go2
-rw-r--r--weed/filer/meta_aggregator.go3
-rw-r--r--weed/filer/redis/universal_redis_store.go6
-rw-r--r--weed/filer/stream.go13
7 files changed, 34 insertions, 38 deletions
diff --git a/weed/filer/filechunks.go b/weed/filer/filechunks.go
index fd9694b38..208ef8095 100644
--- a/weed/filer/filechunks.go
+++ b/weed/filer/filechunks.go
@@ -4,8 +4,8 @@ import (
"bytes"
"fmt"
"github.com/chrislusf/seaweedfs/weed/wdclient"
+ "golang.org/x/exp/slices"
"math"
- "sort"
"sync"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
@@ -23,6 +23,9 @@ func TotalSize(chunks []*filer_pb.FileChunk) (size uint64) {
}
func FileSize(entry *filer_pb.Entry) (size uint64) {
+ if entry == nil || entry.Attributes == nil {
+ return 0
+ }
fileSize := entry.Attributes.FileSize
if entry.RemoteEntry != nil {
if entry.RemoteEntry.RemoteMtime > entry.Attributes.Mtime {
@@ -251,19 +254,17 @@ func NonOverlappingVisibleIntervals(lookupFileIdFn wdclient.LookupFileIdFunction
if true {
return visibles2, err
}
-
- sort.Slice(chunks, func(i, j int) bool {
- if chunks[i].Mtime == chunks[j].Mtime {
- filer_pb.EnsureFid(chunks[i])
- filer_pb.EnsureFid(chunks[j])
- if chunks[i].Fid == nil || chunks[j].Fid == nil {
+ slices.SortFunc(chunks, func(a, b *filer_pb.FileChunk) bool {
+ if a.Mtime == b.Mtime {
+ filer_pb.EnsureFid(a)
+ filer_pb.EnsureFid(b)
+ if a.Fid == nil || b.Fid == nil {
return true
}
- return chunks[i].Fid.FileKey < chunks[j].Fid.FileKey
+ return a.Fid.FileKey < b.Fid.FileKey
}
- return chunks[i].Mtime < chunks[j].Mtime // keep this to make tests run
+ return a.Mtime < b.Mtime
})
-
for _, chunk := range chunks {
// glog.V(0).Infof("merge [%d,%d)", chunk.Offset, chunk.Offset+int64(chunk.Size))
diff --git a/weed/filer/filechunks2_test.go b/weed/filer/filechunks2_test.go
index 9f9566d9b..39dec87c9 100644
--- a/weed/filer/filechunks2_test.go
+++ b/weed/filer/filechunks2_test.go
@@ -1,7 +1,7 @@
package filer
import (
- "sort"
+ "golang.org/x/exp/slices"
"testing"
"github.com/chrislusf/seaweedfs/weed/glog"
@@ -34,11 +34,11 @@ func TestCompactFileChunksRealCase(t *testing.T) {
}
func printChunks(name string, chunks []*filer_pb.FileChunk) {
- sort.Slice(chunks, func(i, j int) bool {
- if chunks[i].Offset == chunks[j].Offset {
- return chunks[i].Mtime < chunks[j].Mtime
+ slices.SortFunc(chunks, func(a, b *filer_pb.FileChunk) bool {
+ if a.Offset == b.Offset {
+ return a.Mtime < b.Mtime
}
- return chunks[i].Offset < chunks[j].Offset
+ return a.Offset < b.Offset
})
for _, chunk := range chunks {
glog.V(0).Infof("%s chunk %s [%10d,%10d)", name, chunk.GetFileIdString(), chunk.Offset, chunk.Offset+int64(chunk.Size))
diff --git a/weed/filer/filechunks_read.go b/weed/filer/filechunks_read.go
index 33ee6d138..1d0bd837a 100644
--- a/weed/filer/filechunks_read.go
+++ b/weed/filer/filechunks_read.go
@@ -2,7 +2,7 @@ package filer
import (
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
- "sort"
+ "golang.org/x/exp/slices"
)
func readResolvedChunks(chunks []*filer_pb.FileChunk) (visibles []VisibleInterval) {
@@ -22,17 +22,14 @@ func readResolvedChunks(chunks []*filer_pb.FileChunk) (visibles []VisibleInterva
isStart: false,
})
}
- sort.Slice(points, func(i, j int) bool {
- if points[i].x != points[j].x {
- return points[i].x < points[j].x
+ slices.SortFunc(points, func(a, b *Point) bool {
+ if a.x != b.x {
+ return a.x < b.x
}
- if points[i].ts != points[j].ts {
- return points[i].ts < points[j].ts
+ if a.ts != b.ts {
+ return a.ts < b.ts
}
- if !points[i].isStart {
- return true
- }
- return false
+ return !a.isStart
})
var prevX int64
diff --git a/weed/filer/filer.go b/weed/filer/filer.go
index 7b6f1342c..836a0e447 100644
--- a/weed/filer/filer.go
+++ b/weed/filer/filer.go
@@ -49,7 +49,7 @@ type Filer struct {
UniqueFileId uint32
}
-func NewFiler(masters []pb.ServerAddress, grpcDialOption grpc.DialOption,
+func NewFiler(masters map[string]pb.ServerAddress, grpcDialOption grpc.DialOption,
filerHost pb.ServerAddress, collection string, replication string, dataCenter string, notifyFn func()) *Filer {
f := &Filer{
MasterClient: wdclient.NewMasterClient(grpcDialOption, cluster.FilerType, filerHost, dataCenter, masters),
diff --git a/weed/filer/meta_aggregator.go b/weed/filer/meta_aggregator.go
index 1e8b89ad5..83c8a945d 100644
--- a/weed/filer/meta_aggregator.go
+++ b/weed/filer/meta_aggregator.go
@@ -76,9 +76,6 @@ func (ma *MetaAggregator) setActive(address pb.ServerAddress, isActive bool) (no
}
} else {
if _, found := ma.peerStatues[address]; found {
- ma.peerStatues[address] -= 1
- }
- if ma.peerStatues[address] <= 0 {
delete(ma.peerStatues, address)
}
}
diff --git a/weed/filer/redis/universal_redis_store.go b/weed/filer/redis/universal_redis_store.go
index 2cc7f49b1..0cdf58d7f 100644
--- a/weed/filer/redis/universal_redis_store.go
+++ b/weed/filer/redis/universal_redis_store.go
@@ -3,7 +3,7 @@ package redis
import (
"context"
"fmt"
- "sort"
+ "golang.org/x/exp/slices"
"strings"
"time"
@@ -157,8 +157,8 @@ func (store *UniversalRedisStore) ListDirectoryEntries(ctx context.Context, dirP
}
// sort
- sort.Slice(members, func(i, j int) bool {
- return strings.Compare(members[i], members[j]) < 0
+ slices.SortFunc(members, func(a, b string) bool {
+ return strings.Compare(a, b) < 0
})
// limit
diff --git a/weed/filer/stream.go b/weed/filer/stream.go
index 36278f0b1..7da9fd0a0 100644
--- a/weed/filer/stream.go
+++ b/weed/filer/stream.go
@@ -3,6 +3,7 @@ package filer
import (
"bytes"
"fmt"
+ "golang.org/x/exp/slices"
"io"
"math"
"sort"
@@ -39,11 +40,11 @@ func isSameChunks(a, b []*filer_pb.FileChunk) bool {
if len(a) != len(b) {
return false
}
- sort.Slice(a, func(i, j int) bool {
- return strings.Compare(a[i].ETag, a[j].ETag) < 0
+ slices.SortFunc(a, func(i, j *filer_pb.FileChunk) bool {
+ return strings.Compare(i.ETag, j.ETag) < 0
})
- sort.Slice(b, func(i, j int) bool {
- return strings.Compare(b[i].ETag, b[j].ETag) < 0
+ slices.SortFunc(b, func(i, j *filer_pb.FileChunk) bool {
+ return strings.Compare(i.ETag, j.ETag) < 0
})
for i := 0; i < len(a); i++ {
if a[i].ETag != b[i].ETag {
@@ -179,8 +180,8 @@ var _ = io.ReaderAt(&ChunkStreamReader{})
func doNewChunkStreamReader(lookupFileIdFn wdclient.LookupFileIdFunctionType, chunks []*filer_pb.FileChunk) *ChunkStreamReader {
chunkViews := ViewFromChunks(lookupFileIdFn, chunks, 0, math.MaxInt64)
- sort.Slice(chunkViews, func(i, j int) bool {
- return chunkViews[i].LogicOffset < chunkViews[j].LogicOffset
+ slices.SortFunc(chunkViews, func(a, b *ChunkView) bool {
+ return a.LogicOffset < b.LogicOffset
})
var totalSize int64