mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-29 07:37:05 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d4c44a85c | ||
|
|
88ba08cb9e | ||
|
|
784c5bb73a | ||
|
|
7a4b234ea1 | ||
|
|
000ee725fc | ||
|
|
a41ba79119 | ||
|
|
d14b614407 | ||
|
|
a32abda1a3 | ||
|
|
c731d9be6d | ||
|
|
174bf1e8b2 | ||
|
|
02191f6156 | ||
|
|
d942aa808a | ||
|
|
596e920f1f | ||
|
|
e72469ea21 | ||
|
|
a98a6263e2 | ||
|
|
b13c2be332 | ||
|
|
efa881f557 | ||
|
|
27850c3a8b | ||
|
|
7e95dcc99e | ||
|
|
868913aa04 | ||
|
|
de7626bd22 | ||
|
|
94302935b2 | ||
|
|
b2d92a2992 | ||
|
|
24c020104a | ||
|
|
c789b496d8 | ||
|
|
5808caa2f5 | ||
|
|
cd6d35aa52 | ||
|
|
72920efc20 | ||
|
|
a6a5d80401 | ||
|
|
300b39b5af | ||
|
|
921231268b | ||
|
|
4f714cef22 | ||
|
|
c94823f52c | ||
|
|
0bd7ced7c2 | ||
|
|
9cc73f4a9a | ||
|
|
af37b374cb | ||
|
|
766396d249 | ||
|
|
c0c9a8bad5 | ||
|
|
715a38da1e | ||
|
|
20dcb44077 | ||
|
|
beaa2bd71a | ||
|
|
78b9db34d5 | ||
|
|
2a52e70a41 | ||
|
|
b4c276263f | ||
|
|
c5a3ff1c35 | ||
|
|
189c890715 |
No files matched your search
+29
-24
@@ -1,19 +1,21 @@
|
||||
sudo: false
|
||||
language: go
|
||||
go:
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- 1.12.x
|
||||
- tip
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- 1.12.x
|
||||
# - tip
|
||||
|
||||
before_install:
|
||||
- export PATH=/home/travis/gopath/bin:$PATH
|
||||
- export PATH=/home/travis/gopath/bin:$PATH
|
||||
|
||||
install:
|
||||
- go get ./weed/...
|
||||
- export CGO_ENABLED="0"
|
||||
- go env
|
||||
- go get -u ./weed/...
|
||||
|
||||
script:
|
||||
- go test ./weed/...
|
||||
- go test ./weed/...
|
||||
|
||||
before_deploy:
|
||||
- make release
|
||||
@@ -23,23 +25,26 @@ deploy:
|
||||
api_key:
|
||||
secure: ERL986+ncQ8lwAJUYDrQ8s2/FxF/cyNIwJIFCqspnWxQgGNNyokET9HapmlPSxjpFRF0q6L2WCg9OY3mSVRq4oI6hg1igOQ12KlLyN71XSJ3c8w0Ay5ho48TQ9l3f3Iu97mntBCe9l0R9pnT8wj1VI8YJxloXwUMG2yeTjA9aBI=
|
||||
file:
|
||||
- build/linux_arm.tar.gz
|
||||
- build/linux_arm64.tar.gz
|
||||
- build/linux_386.tar.gz
|
||||
- build/linux_amd64.tar.gz
|
||||
- build/darwin_amd64.tar.gz
|
||||
- build/windows_386.zip
|
||||
- build/windows_amd64.zip
|
||||
- build/freebsd_arm.tar.gz
|
||||
- build/freebsd_amd64.tar.gz
|
||||
- build/freebsd_386.tar.gz
|
||||
- build/netbsd_arm.tar.gz
|
||||
- build/netbsd_amd64.tar.gz
|
||||
- build/netbsd_386.tar.gz
|
||||
- build/openbsd_arm.tar.gz
|
||||
- build/openbsd_amd64.tar.gz
|
||||
- build/openbsd_386.tar.gz
|
||||
- build/linux_arm.tar.gz
|
||||
- build/linux_arm64.tar.gz
|
||||
- build/linux_386.tar.gz
|
||||
- build/linux_amd64.tar.gz
|
||||
- build/linux_amd64_large_disk.tar.gz
|
||||
- build/darwin_amd64.tar.gz
|
||||
- build/darwin_amd64_large_disk.tar.gz
|
||||
- build/windows_386.zip
|
||||
- build/windows_amd64.zip
|
||||
- build/windows_amd64_large_disk.zip
|
||||
- build/freebsd_arm.tar.gz
|
||||
- build/freebsd_amd64.tar.gz
|
||||
- build/freebsd_386.tar.gz
|
||||
- build/netbsd_arm.tar.gz
|
||||
- build/netbsd_amd64.tar.gz
|
||||
- build/netbsd_386.tar.gz
|
||||
- build/openbsd_arm.tar.gz
|
||||
- build/openbsd_amd64.tar.gz
|
||||
- build/openbsd_386.tar.gz
|
||||
on:
|
||||
tags: true
|
||||
repo: chrislusf/seaweedfs
|
||||
go: tip
|
||||
go: 1.12.x
|
||||
@@ -12,6 +12,9 @@ build = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -ldflags "-extldflags -stat
|
||||
tar = cd build && tar -cvzf $(1)_$(2).tar.gz $(appname)$(3) && rm $(appname)$(3)
|
||||
zip = cd build && zip $(1)_$(2).zip $(appname)$(3) && rm $(appname)$(3)
|
||||
|
||||
build_large = CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build -tags 5BytesOffset -ldflags "-extldflags -static" -o build/$(appname)$(3) $(SOURCE_DIR)
|
||||
tar_large = cd build && tar -cvzf $(1)_$(2)_large_disk.tar.gz $(appname)$(3) && rm $(appname)$(3)
|
||||
zip_large = cd build && zip $(1)_$(2)_large_disk.zip $(appname)$(3) && rm $(appname)$(3)
|
||||
|
||||
all: build
|
||||
|
||||
@@ -32,9 +35,21 @@ linux: deps
|
||||
mkdir -p linux
|
||||
GOOS=linux GOARCH=amd64 go build $(GO_FLAGS) -o linux/$(BINARY) $(SOURCE_DIR)
|
||||
|
||||
release: deps windows_build darwin_build linux_build bsd_build
|
||||
release: deps windows_build darwin_build linux_build bsd_build 5_byte_linux_build 5_byte_darwin_build 5_byte_windows_build
|
||||
|
||||
##### LINUX BUILDS #####
|
||||
5_byte_linux_build:
|
||||
$(call build_large,linux,amd64,)
|
||||
$(call tar_large,linux,amd64)
|
||||
|
||||
5_byte_darwin_build:
|
||||
$(call build_large,darwin,amd64,)
|
||||
$(call tar_large,darwin,amd64)
|
||||
|
||||
5_byte_windows_build:
|
||||
$(call build_large,windows,amd64,.exe)
|
||||
$(call zip_large,windows,amd64,.exe)
|
||||
|
||||
linux_build: build/linux_arm.tar.gz build/linux_arm64.tar.gz build/linux_386.tar.gz build/linux_amd64.tar.gz
|
||||
|
||||
build/linux_386.tar.gz: $(sources)
|
||||
|
||||
@@ -107,7 +107,7 @@ func (scanner *VolumeFileScanner4Export) VisitNeedle(n *storage.Needle, offset i
|
||||
nv, ok := needleMap.Get(n.Id)
|
||||
glog.V(3).Infof("key %d offset %d size %d disk_size %d gzip %v ok %v nv %+v",
|
||||
n.Id, offset, n.Size, n.DiskSize(scanner.version), n.IsGzipped(), ok, nv)
|
||||
if ok && nv.Size > 0 && nv.Size != types.TombstoneFileSize && int64(nv.Offset)*types.NeedlePaddingSize == offset {
|
||||
if ok && nv.Size > 0 && nv.Size != types.TombstoneFileSize && nv.Offset.ToAcutalOffset() == offset {
|
||||
if newerThanUnix >= 0 && n.HasLastModifiedDate() && n.LastModified < uint64(newerThanUnix) {
|
||||
glog.V(3).Infof("Skipping this file, as it's old enough: LastModified %d vs %d",
|
||||
n.LastModified, newerThanUnix)
|
||||
|
||||
+157
-90
@@ -1,30 +1,31 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/operation"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/security"
|
||||
"github.com/chrislusf/seaweedfs/weed/server"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"github.com/chrislusf/seaweedfs/weed/wdclient"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
"github.com/chrislusf/seaweedfs/weed/operation"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
copy CopyOptions
|
||||
copy CopyOptions
|
||||
waitGroup sync.WaitGroup
|
||||
)
|
||||
|
||||
type CopyOptions struct {
|
||||
@@ -37,6 +38,7 @@ type CopyOptions struct {
|
||||
maxMB *int
|
||||
grpcDialOption grpc.DialOption
|
||||
masterClient *wdclient.MasterClient
|
||||
concurrency *int
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -47,8 +49,9 @@ func init() {
|
||||
copy.replication = cmdCopy.Flag.String("replication", "", "replication type")
|
||||
copy.collection = cmdCopy.Flag.String("collection", "", "optional collection name")
|
||||
copy.ttl = cmdCopy.Flag.String("ttl", "", "time to live, e.g.: 1m, 1h, 1d, 1M, 1y")
|
||||
copy.maxMB = cmdCopy.Flag.Int("maxMB", 0, "split files larger than the limit")
|
||||
copy.maxMB = cmdCopy.Flag.Int("maxMB", 32, "split files larger than the limit")
|
||||
copy.filerGrpcPort = cmdCopy.Flag.Int("filer.port.grpc", 0, "filer grpc server listen port, default to filer port + 10000")
|
||||
copy.concurrency = cmdCopy.Flag.Int("c", 8, "concurrent file copy goroutines")
|
||||
}
|
||||
|
||||
var cmdCopy = &Command{
|
||||
@@ -111,61 +114,135 @@ func runCopy(cmd *Command, args []string) bool {
|
||||
go copy.masterClient.KeepConnectedToMaster()
|
||||
copy.masterClient.WaitUntilConnected()
|
||||
|
||||
for _, fileOrDir := range fileOrDirs {
|
||||
if !doEachCopy(context.Background(), fileOrDir, filerUrl.Host, filerGrpcAddress, copy.grpcDialOption, urlPath) {
|
||||
return false
|
||||
}
|
||||
if *cmdCopy.IsDebug {
|
||||
util.SetupProfiling("filer.copy.cpu.pprof", "filer.copy.mem.pprof")
|
||||
}
|
||||
|
||||
fileCopyTaskChan := make(chan FileCopyTask, *copy.concurrency)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
go func() {
|
||||
defer close(fileCopyTaskChan)
|
||||
for _, fileOrDir := range fileOrDirs {
|
||||
if err := genFileCopyTask(fileOrDir, urlPath, fileCopyTaskChan); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gen file list error: %v\n", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
for i := 0; i < *copy.concurrency; i++ {
|
||||
waitGroup.Add(1)
|
||||
go func() {
|
||||
defer waitGroup.Done()
|
||||
worker := FileCopyWorker{
|
||||
options: ©,
|
||||
filerHost: filerUrl.Host,
|
||||
filerGrpcAddress: filerGrpcAddress,
|
||||
}
|
||||
if err := worker.copyFiles(ctx, fileCopyTaskChan); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "copy file error: %v\n", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
waitGroup.Wait()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func doEachCopy(ctx context.Context, fileOrDir string, filerAddress, filerGrpcAddress string, grpcDialOption grpc.DialOption, path string) bool {
|
||||
f, err := os.Open(fileOrDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to open file %s: %v\n", fileOrDir, err)
|
||||
return false
|
||||
}
|
||||
defer f.Close()
|
||||
func genFileCopyTask(fileOrDir string, destPath string, fileCopyTaskChan chan FileCopyTask) error {
|
||||
|
||||
fi, err := f.Stat()
|
||||
fi, err := os.Stat(fileOrDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to get stat for file %s: %v\n", fileOrDir, err)
|
||||
return false
|
||||
fmt.Fprintf(os.Stderr, "Failed to get stat for file %s: %v\n", fileOrDir, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
mode := fi.Mode()
|
||||
if mode.IsDir() {
|
||||
files, _ := ioutil.ReadDir(fileOrDir)
|
||||
for _, subFileOrDir := range files {
|
||||
if !doEachCopy(ctx, fileOrDir+"/"+subFileOrDir.Name(), filerAddress, filerGrpcAddress, grpcDialOption, path+fi.Name()+"/") {
|
||||
return false
|
||||
if err = genFileCopyTask(fileOrDir+"/"+subFileOrDir.Name(), destPath+fi.Name()+"/", fileCopyTaskChan); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
uid, gid := util.GetFileUidGid(fi)
|
||||
|
||||
fileCopyTaskChan <- FileCopyTask{
|
||||
sourceLocation: fileOrDir,
|
||||
destinationUrlPath: destPath,
|
||||
fileSize: fi.Size(),
|
||||
fileMode: fi.Mode(),
|
||||
uid: uid,
|
||||
gid: gid,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type FileCopyWorker struct {
|
||||
options *CopyOptions
|
||||
filerHost string
|
||||
filerGrpcAddress string
|
||||
}
|
||||
|
||||
func (worker *FileCopyWorker) copyFiles(ctx context.Context, fileCopyTaskChan chan FileCopyTask) error {
|
||||
for task := range fileCopyTaskChan {
|
||||
if err := worker.doEachCopy(ctx, task); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type FileCopyTask struct {
|
||||
sourceLocation string
|
||||
destinationUrlPath string
|
||||
fileSize int64
|
||||
fileMode os.FileMode
|
||||
uid uint32
|
||||
gid uint32
|
||||
}
|
||||
|
||||
func (worker *FileCopyWorker) doEachCopy(ctx context.Context, task FileCopyTask) error {
|
||||
|
||||
f, err := os.Open(task.sourceLocation)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to open file %s: %v\n", task.sourceLocation, err)
|
||||
if _, ok := err.(*os.PathError); ok {
|
||||
fmt.Printf("skipping %s\n", task.sourceLocation)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// this is a regular file
|
||||
if *copy.include != "" {
|
||||
if ok, _ := filepath.Match(*copy.include, filepath.Base(fileOrDir)); !ok {
|
||||
return true
|
||||
if *worker.options.include != "" {
|
||||
if ok, _ := filepath.Match(*worker.options.include, filepath.Base(task.sourceLocation)); !ok {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// find the chunk count
|
||||
chunkSize := int64(*copy.maxMB * 1024 * 1024)
|
||||
chunkSize := int64(*worker.options.maxMB * 1024 * 1024)
|
||||
chunkCount := 1
|
||||
if chunkSize > 0 && fi.Size() > chunkSize {
|
||||
chunkCount = int(fi.Size()/chunkSize) + 1
|
||||
if chunkSize > 0 && task.fileSize > chunkSize {
|
||||
chunkCount = int(task.fileSize/chunkSize) + 1
|
||||
}
|
||||
|
||||
if chunkCount == 1 {
|
||||
return uploadFileAsOne(ctx, filerAddress, filerGrpcAddress, grpcDialOption, path, f, fi)
|
||||
return worker.uploadFileAsOne(ctx, task, f)
|
||||
}
|
||||
|
||||
return uploadFileInChunks(ctx, filerAddress, filerGrpcAddress, grpcDialOption, path, f, fi, chunkCount, chunkSize)
|
||||
return worker.uploadFileInChunks(ctx, task, f, chunkCount, chunkSize)
|
||||
}
|
||||
|
||||
func uploadFileAsOne(ctx context.Context, filerAddress, filerGrpcAddress string, grpcDialOption grpc.DialOption, urlFolder string, f *os.File, fi os.FileInfo) bool {
|
||||
func (worker *FileCopyWorker) uploadFileAsOne(ctx context.Context, task FileCopyTask, f *os.File) error {
|
||||
|
||||
// upload the file content
|
||||
fileName := filepath.Base(f.Name())
|
||||
@@ -173,29 +250,27 @@ func uploadFileAsOne(ctx context.Context, filerAddress, filerGrpcAddress string,
|
||||
|
||||
var chunks []*filer_pb.FileChunk
|
||||
|
||||
if fi.Size() > 0 {
|
||||
if task.fileSize > 0 {
|
||||
|
||||
// assign a volume
|
||||
assignResult, err := operation.Assign(copy.masterClient.GetMaster(), grpcDialOption, &operation.VolumeAssignRequest{
|
||||
assignResult, err := operation.Assign(worker.options.masterClient.GetMaster(), worker.options.grpcDialOption, &operation.VolumeAssignRequest{
|
||||
Count: 1,
|
||||
Replication: *copy.replication,
|
||||
Collection: *copy.collection,
|
||||
Ttl: *copy.ttl,
|
||||
Replication: *worker.options.replication,
|
||||
Collection: *worker.options.collection,
|
||||
Ttl: *worker.options.ttl,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to assign from %s: %v\n", *copy.master, err)
|
||||
fmt.Printf("Failed to assign from %s: %v\n", *worker.options.master, err)
|
||||
}
|
||||
|
||||
targetUrl := "http://" + assignResult.Url + "/" + assignResult.Fid
|
||||
|
||||
uploadResult, err := operation.Upload(targetUrl, fileName, f, false, mimeType, nil, assignResult.Auth)
|
||||
if err != nil {
|
||||
fmt.Printf("upload data %v to %s: %v\n", fileName, targetUrl, err)
|
||||
return false
|
||||
return fmt.Errorf("upload data %v to %s: %v\n", fileName, targetUrl, err)
|
||||
}
|
||||
if uploadResult.Error != "" {
|
||||
fmt.Printf("upload %v to %s result: %v\n", fileName, targetUrl, uploadResult.Error)
|
||||
return false
|
||||
return fmt.Errorf("upload %v to %s result: %v\n", fileName, targetUrl, uploadResult.Error)
|
||||
}
|
||||
fmt.Printf("uploaded %s to %s\n", fileName, targetUrl)
|
||||
|
||||
@@ -207,25 +282,25 @@ func uploadFileAsOne(ctx context.Context, filerAddress, filerGrpcAddress string,
|
||||
ETag: uploadResult.ETag,
|
||||
})
|
||||
|
||||
fmt.Printf("copied %s => http://%s%s%s\n", fileName, filerAddress, urlFolder, fileName)
|
||||
fmt.Printf("copied %s => http://%s%s%s\n", fileName, worker.filerHost, task.destinationUrlPath, fileName)
|
||||
}
|
||||
|
||||
if err := withFilerClient(ctx, filerGrpcAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
||||
if err := withFilerClient(ctx, worker.filerGrpcAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
||||
request := &filer_pb.CreateEntryRequest{
|
||||
Directory: urlFolder,
|
||||
Directory: task.destinationUrlPath,
|
||||
Entry: &filer_pb.Entry{
|
||||
Name: fileName,
|
||||
Attributes: &filer_pb.FuseAttributes{
|
||||
Crtime: time.Now().Unix(),
|
||||
Mtime: time.Now().Unix(),
|
||||
Gid: uint32(os.Getgid()),
|
||||
Uid: uint32(os.Getuid()),
|
||||
FileSize: uint64(fi.Size()),
|
||||
FileMode: uint32(fi.Mode()),
|
||||
Gid: task.gid,
|
||||
Uid: task.uid,
|
||||
FileSize: uint64(task.fileSize),
|
||||
FileMode: uint32(task.fileMode),
|
||||
Mime: mimeType,
|
||||
Replication: *copy.replication,
|
||||
Collection: *copy.collection,
|
||||
TtlSec: int32(util.ParseInt(*copy.ttl, 0)),
|
||||
Replication: *worker.options.replication,
|
||||
Collection: *worker.options.collection,
|
||||
TtlSec: int32(util.ParseInt(*worker.options.ttl, 0)),
|
||||
},
|
||||
Chunks: chunks,
|
||||
},
|
||||
@@ -236,14 +311,13 @@ func uploadFileAsOne(ctx context.Context, filerAddress, filerGrpcAddress string,
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
fmt.Printf("upload data %v to http://%s%s%s: %v\n", fileName, filerAddress, urlFolder, fileName, err)
|
||||
return false
|
||||
return fmt.Errorf("upload data %v to http://%s%s%s: %v\n", fileName, worker.filerHost, task.destinationUrlPath, fileName, err)
|
||||
}
|
||||
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func uploadFileInChunks(ctx context.Context, filerAddress, filerGrpcAddress string, grpcDialOption grpc.DialOption, urlFolder string, f *os.File, fi os.FileInfo, chunkCount int, chunkSize int64) bool {
|
||||
func (worker *FileCopyWorker) uploadFileInChunks(ctx context.Context, task FileCopyTask, f *os.File, chunkCount int, chunkSize int64) error {
|
||||
|
||||
fileName := filepath.Base(f.Name())
|
||||
mimeType := detectMimeType(f)
|
||||
@@ -253,14 +327,14 @@ func uploadFileInChunks(ctx context.Context, filerAddress, filerGrpcAddress stri
|
||||
for i := int64(0); i < int64(chunkCount); i++ {
|
||||
|
||||
// assign a volume
|
||||
assignResult, err := operation.Assign(copy.masterClient.GetMaster(), grpcDialOption, &operation.VolumeAssignRequest{
|
||||
assignResult, err := operation.Assign(worker.options.masterClient.GetMaster(), worker.options.grpcDialOption, &operation.VolumeAssignRequest{
|
||||
Count: 1,
|
||||
Replication: *copy.replication,
|
||||
Collection: *copy.collection,
|
||||
Ttl: *copy.ttl,
|
||||
Replication: *worker.options.replication,
|
||||
Collection: *worker.options.collection,
|
||||
Ttl: *worker.options.ttl,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to assign from %s: %v\n", *copy.master, err)
|
||||
fmt.Printf("Failed to assign from %s: %v\n", *worker.options.master, err)
|
||||
}
|
||||
|
||||
targetUrl := "http://" + assignResult.Url + "/" + assignResult.Fid
|
||||
@@ -270,12 +344,10 @@ func uploadFileInChunks(ctx context.Context, filerAddress, filerGrpcAddress stri
|
||||
io.LimitReader(f, chunkSize),
|
||||
false, "application/octet-stream", nil, assignResult.Auth)
|
||||
if err != nil {
|
||||
fmt.Printf("upload data %v to %s: %v\n", fileName, targetUrl, err)
|
||||
return false
|
||||
return fmt.Errorf("upload data %v to %s: %v\n", fileName, targetUrl, err)
|
||||
}
|
||||
if uploadResult.Error != "" {
|
||||
fmt.Printf("upload %v to %s result: %v\n", fileName, targetUrl, uploadResult.Error)
|
||||
return false
|
||||
return fmt.Errorf("upload %v to %s result: %v\n", fileName, targetUrl, uploadResult.Error)
|
||||
}
|
||||
chunks = append(chunks, &filer_pb.FileChunk{
|
||||
FileId: assignResult.Fid,
|
||||
@@ -287,22 +359,22 @@ func uploadFileInChunks(ctx context.Context, filerAddress, filerGrpcAddress stri
|
||||
fmt.Printf("uploaded %s-%d to %s [%d,%d)\n", fileName, i+1, targetUrl, i*chunkSize, i*chunkSize+int64(uploadResult.Size))
|
||||
}
|
||||
|
||||
if err := withFilerClient(ctx, filerGrpcAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
||||
if err := withFilerClient(ctx, worker.filerGrpcAddress, worker.options.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
||||
request := &filer_pb.CreateEntryRequest{
|
||||
Directory: urlFolder,
|
||||
Directory: task.destinationUrlPath,
|
||||
Entry: &filer_pb.Entry{
|
||||
Name: fileName,
|
||||
Attributes: &filer_pb.FuseAttributes{
|
||||
Crtime: time.Now().Unix(),
|
||||
Mtime: time.Now().Unix(),
|
||||
Gid: uint32(os.Getgid()),
|
||||
Uid: uint32(os.Getuid()),
|
||||
FileSize: uint64(fi.Size()),
|
||||
FileMode: uint32(fi.Mode()),
|
||||
Gid: task.gid,
|
||||
Uid: task.uid,
|
||||
FileSize: uint64(task.fileSize),
|
||||
FileMode: uint32(task.fileMode),
|
||||
Mime: mimeType,
|
||||
Replication: *copy.replication,
|
||||
Collection: *copy.collection,
|
||||
TtlSec: int32(util.ParseInt(*copy.ttl, 0)),
|
||||
Replication: *worker.options.replication,
|
||||
Collection: *worker.options.collection,
|
||||
TtlSec: int32(util.ParseInt(*worker.options.ttl, 0)),
|
||||
},
|
||||
Chunks: chunks,
|
||||
},
|
||||
@@ -313,13 +385,12 @@ func uploadFileInChunks(ctx context.Context, filerAddress, filerGrpcAddress stri
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
fmt.Printf("upload data %v to http://%s%s%s: %v\n", fileName, filerAddress, urlFolder, fileName, err)
|
||||
return false
|
||||
return fmt.Errorf("upload data %v to http://%s%s%s: %v\n", fileName, worker.filerHost, task.destinationUrlPath, fileName, err)
|
||||
}
|
||||
|
||||
fmt.Printf("copied %s => http://%s%s%s\n", fileName, filerAddress, urlFolder, fileName)
|
||||
fmt.Printf("copied %s => http://%s%s%s\n", fileName, worker.filerHost, task.destinationUrlPath, fileName)
|
||||
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func detectMimeType(f *os.File) string {
|
||||
@@ -340,13 +411,9 @@ func detectMimeType(f *os.File) string {
|
||||
|
||||
func withFilerClient(ctx context.Context, filerAddress string, grpcDialOption grpc.DialOption, fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||
|
||||
grpcConnection, err := util.GrpcDial(ctx, filerAddress, grpcDialOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to dial %s: %v", filerAddress, err)
|
||||
}
|
||||
defer grpcConnection.Close()
|
||||
return util.WithCachedGrpcClient(ctx, func(clientConn *grpc.ClientConn) error {
|
||||
client := filer_pb.NewSeaweedFilerClient(clientConn)
|
||||
return fn(client)
|
||||
}, filerAddress, grpcDialOption)
|
||||
|
||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||
|
||||
return fn(client)
|
||||
}
|
||||
+2
-2
@@ -45,11 +45,11 @@ func (scanner *VolumeFileScanner4Fix) ReadNeedleBody() bool {
|
||||
func (scanner *VolumeFileScanner4Fix) VisitNeedle(n *storage.Needle, offset int64) error {
|
||||
glog.V(2).Infof("key %d offset %d size %d disk_size %d gzip %v", n.Id, offset, n.Size, n.DiskSize(scanner.version), n.IsGzipped())
|
||||
if n.Size > 0 && n.Size != types.TombstoneFileSize {
|
||||
pe := scanner.nm.Put(n.Id, types.Offset(offset/types.NeedlePaddingSize), n.Size)
|
||||
pe := scanner.nm.Put(n.Id, types.ToOffset(offset), n.Size)
|
||||
glog.V(2).Infof("saved %d with error %v", n.Size, pe)
|
||||
} else {
|
||||
glog.V(2).Infof("skipping deleted file ...")
|
||||
return scanner.nm.Delete(n.Id, types.Offset(offset/types.NeedlePaddingSize))
|
||||
return scanner.nm.Delete(n.Id, types.ToOffset(offset))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func runMaster(cmd *Command, args []string) bool {
|
||||
if *masterWhiteListOption != "" {
|
||||
masterWhiteList = strings.Split(*masterWhiteListOption, ",")
|
||||
}
|
||||
if *volumeSizeLimitMB > 30*1000 {
|
||||
if *volumeSizeLimitMB > util.VolumeSizeLimitGB*1000 {
|
||||
glog.Fatalf("volumeSizeLimitMB should be smaller than 30000")
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ dir = "." # directory to store level db files
|
||||
|
||||
[mysql]
|
||||
# CREATE TABLE IF NOT EXISTS filemeta (
|
||||
# dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
|
||||
# name VARCHAR(1000) COMMENT 'directory or file name',
|
||||
# directory VARCHAR(4096) COMMENT 'full path to parent directory',
|
||||
# dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
|
||||
# name VARCHAR(65535) COMMENT 'directory or file name',
|
||||
# directory VARCHAR(65535) COMMENT 'full path to parent directory',
|
||||
# meta BLOB,
|
||||
# PRIMARY KEY (dirhash, name)
|
||||
# ) DEFAULT CHARSET=utf8;
|
||||
@@ -90,8 +90,8 @@ connection_max_open = 100
|
||||
[postgres]
|
||||
# CREATE TABLE IF NOT EXISTS filemeta (
|
||||
# dirhash BIGINT,
|
||||
# name VARCHAR(1000),
|
||||
# directory VARCHAR(4096),
|
||||
# name VARCHAR(65535),
|
||||
# directory VARCHAR(65535),
|
||||
# meta bytea,
|
||||
# PRIMARY KEY (dirhash, name)
|
||||
# );
|
||||
@@ -190,6 +190,7 @@ enabled = false
|
||||
# The exchange must have already been created by some other means, like
|
||||
# the RabbitMQ management plugin.
|
||||
topic_url = "rabbit://myexchange"
|
||||
sub_url = "rabbit://myqueue"
|
||||
`
|
||||
|
||||
REPLICATION_TOML_EXAMPLE = `
|
||||
|
||||
@@ -140,7 +140,7 @@ func runServer(cmd *Command, args []string) bool {
|
||||
|
||||
folders := strings.Split(*volumeDataFolders, ",")
|
||||
|
||||
if *masterVolumeSizeLimitMB > 30*1000 {
|
||||
if *masterVolumeSizeLimitMB > util.VolumeSizeLimitGB*1000 {
|
||||
glog.Fatalf("masterVolumeSizeLimitMB should be less than 30000")
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ func runShell(command *Command, args []string) bool {
|
||||
weed_server.LoadConfiguration("security", false)
|
||||
shellOptions.GrpcDialOption = security.LoadClientTLS(viper.Sub("grpc"), "client")
|
||||
|
||||
shellOptions.FilerHost = "localhost"
|
||||
shellOptions.FilerPort = 8888
|
||||
shellOptions.Directory = "/"
|
||||
|
||||
shell.RunShell(shellOptions)
|
||||
|
||||
return true
|
||||
|
||||
@@ -37,7 +37,7 @@ func init() {
|
||||
upload.collection = cmdUpload.Flag.String("collection", "", "optional collection name")
|
||||
upload.dataCenter = cmdUpload.Flag.String("dataCenter", "", "optional data center name")
|
||||
upload.ttl = cmdUpload.Flag.String("ttl", "", "time to live, e.g.: 1m, 1h, 1d, 1M, 1y")
|
||||
upload.maxMB = cmdUpload.Flag.Int("maxMB", 0, "split files larger than the limit")
|
||||
upload.maxMB = cmdUpload.Flag.Int("maxMB", 32, "split files larger than the limit")
|
||||
}
|
||||
|
||||
var cmdUpload = &Command{
|
||||
|
||||
@@ -26,7 +26,10 @@ type TxOrDB interface {
|
||||
}
|
||||
|
||||
func (store *AbstractSqlStore) BeginTransaction(ctx context.Context) (context.Context, error) {
|
||||
tx, err := store.DB.BeginTx(ctx, nil)
|
||||
tx, err := store.DB.BeginTx(ctx, &sql.TxOptions{
|
||||
Isolation: sql.LevelReadCommitted,
|
||||
ReadOnly: false,
|
||||
})
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
+25
-16
@@ -217,29 +217,32 @@ func (f *Filer) DeleteEntryMetaAndData(ctx context.Context, p FullPath, isRecurs
|
||||
if err != nil {
|
||||
return fmt.Errorf("list folder %s: %v", p, err)
|
||||
}
|
||||
|
||||
if len(entries) == 0 {
|
||||
break
|
||||
} else {
|
||||
if isRecursive {
|
||||
for _, sub := range entries {
|
||||
lastFileName = sub.Name()
|
||||
f.DeleteEntryMetaAndData(ctx, sub.FullPath, isRecursive, shouldDeleteChunks)
|
||||
limit--
|
||||
if limit <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isRecursive {
|
||||
for _, sub := range entries {
|
||||
lastFileName = sub.Name()
|
||||
err = f.DeleteEntryMetaAndData(ctx, sub.FullPath, isRecursive, shouldDeleteChunks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if len(entries) > 0 {
|
||||
return fmt.Errorf("folder %s is not empty", p)
|
||||
limit--
|
||||
if limit <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
f.cacheDelDirectory(string(p))
|
||||
if len(entries) < 1024 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(entries) < 1024 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
f.cacheDelDirectory(string(p))
|
||||
|
||||
}
|
||||
|
||||
if shouldDeleteChunks {
|
||||
@@ -264,6 +267,11 @@ func (f *Filer) ListDirectoryEntries(ctx context.Context, p FullPath, startFileN
|
||||
}
|
||||
|
||||
func (f *Filer) cacheDelDirectory(dirpath string) {
|
||||
|
||||
if dirpath == "/" {
|
||||
return
|
||||
}
|
||||
|
||||
if f.directoryCache == nil {
|
||||
return
|
||||
}
|
||||
@@ -272,6 +280,7 @@ func (f *Filer) cacheDelDirectory(dirpath string) {
|
||||
}
|
||||
|
||||
func (f *Filer) cacheGetDirectory(dirpath string) *Entry {
|
||||
|
||||
if f.directoryCache == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ $PGHOME/bin/psql --username=postgres --password seaweedfs
|
||||
|
||||
CREATE TABLE IF NOT EXISTS filemeta (
|
||||
dirhash BIGINT,
|
||||
name VARCHAR(1000),
|
||||
directory VARCHAR(4096),
|
||||
name VARCHAR(65535),
|
||||
directory VARCHAR(65535),
|
||||
meta bytea,
|
||||
PRIMARY KEY (dirhash, name)
|
||||
);
|
||||
|
||||
+48
-35
@@ -16,40 +16,9 @@ import (
|
||||
*/
|
||||
func IsGzippable(ext, mtype string, data []byte) bool {
|
||||
|
||||
// text
|
||||
if strings.HasPrefix(mtype, "text/") {
|
||||
return true
|
||||
}
|
||||
|
||||
// images
|
||||
switch ext {
|
||||
case ".svg", ".bmp":
|
||||
return true
|
||||
}
|
||||
if strings.HasPrefix(mtype, "image/") {
|
||||
return false
|
||||
}
|
||||
|
||||
// by file name extension
|
||||
switch ext {
|
||||
case ".zip", ".rar", ".gz", ".bz2", ".xz":
|
||||
return false
|
||||
case ".pdf", ".txt", ".html", ".htm", ".css", ".js", ".json":
|
||||
return true
|
||||
case ".php", ".java", ".go", ".rb", ".c", ".cpp", ".h", ".hpp":
|
||||
return true
|
||||
case ".png", ".jpg", ".jpeg":
|
||||
return false
|
||||
}
|
||||
|
||||
// by mime type
|
||||
if strings.HasPrefix(mtype, "application/") {
|
||||
if strings.HasSuffix(mtype, "xml") {
|
||||
return true
|
||||
}
|
||||
if strings.HasSuffix(mtype, "script") {
|
||||
return true
|
||||
}
|
||||
shouldBeZipped, iAmSure := IsGzippableFileType(ext, mtype)
|
||||
if iAmSure {
|
||||
return shouldBeZipped
|
||||
}
|
||||
|
||||
isMostlyText := util.IsText(data)
|
||||
@@ -57,9 +26,53 @@ func IsGzippable(ext, mtype string, data []byte) bool {
|
||||
return isMostlyText
|
||||
}
|
||||
|
||||
/*
|
||||
* Default more not to gzip since gzip can be done on client side.
|
||||
*/
|
||||
func IsGzippableFileType(ext, mtype string) (shouldBeZipped, iAmSure bool) {
|
||||
|
||||
// text
|
||||
if strings.HasPrefix(mtype, "text/") {
|
||||
return true, true
|
||||
}
|
||||
|
||||
// images
|
||||
switch ext {
|
||||
case ".svg", ".bmp":
|
||||
return true, true
|
||||
}
|
||||
if strings.HasPrefix(mtype, "image/") {
|
||||
return false, true
|
||||
}
|
||||
|
||||
// by file name extension
|
||||
switch ext {
|
||||
case ".zip", ".rar", ".gz", ".bz2", ".xz":
|
||||
return false, true
|
||||
case ".pdf", ".txt", ".html", ".htm", ".css", ".js", ".json":
|
||||
return true, true
|
||||
case ".php", ".java", ".go", ".rb", ".c", ".cpp", ".h", ".hpp":
|
||||
return true, true
|
||||
case ".png", ".jpg", ".jpeg":
|
||||
return false, true
|
||||
}
|
||||
|
||||
// by mime type
|
||||
if strings.HasPrefix(mtype, "application/") {
|
||||
if strings.HasSuffix(mtype, "xml") {
|
||||
return true, true
|
||||
}
|
||||
if strings.HasSuffix(mtype, "script") {
|
||||
return true, true
|
||||
}
|
||||
}
|
||||
|
||||
return false, false
|
||||
}
|
||||
|
||||
func GzipData(input []byte) ([]byte, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
w, _ := gzip.NewWriterLevel(buf, flate.BestCompression)
|
||||
w, _ := gzip.NewWriterLevel(buf, flate.BestSpeed)
|
||||
if _, err := w.Write(input); err != nil {
|
||||
glog.V(2).Infoln("error compressing data:", err)
|
||||
return nil, err
|
||||
|
||||
@@ -2,6 +2,8 @@ package operation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/flate"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -39,10 +41,24 @@ var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
|
||||
|
||||
// Upload sends a POST request to a volume server to upload the content
|
||||
func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) {
|
||||
contentIsGzipped := isGzipped
|
||||
shouldGzipNow := false
|
||||
if !isGzipped {
|
||||
if shouldBeZipped, iAmSure := IsGzippableFileType(filepath.Base(filename), mtype); iAmSure && shouldBeZipped {
|
||||
shouldGzipNow = true
|
||||
contentIsGzipped = true
|
||||
}
|
||||
}
|
||||
return upload_content(uploadUrl, func(w io.Writer) (err error) {
|
||||
_, err = io.Copy(w, reader)
|
||||
if shouldGzipNow {
|
||||
gzWriter, _ := gzip.NewWriterLevel(w, flate.BestSpeed)
|
||||
_, err = io.Copy(gzWriter, reader)
|
||||
gzWriter.Close()
|
||||
} else {
|
||||
_, err = io.Copy(w, reader)
|
||||
}
|
||||
return
|
||||
}, filename, isGzipped, mtype, pairMap, jwt)
|
||||
}, filename, contentIsGzipped, mtype, pairMap, jwt)
|
||||
}
|
||||
func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error, filename string, isGzipped bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) {
|
||||
body_buf := bytes.NewBufferString("")
|
||||
|
||||
@@ -3,6 +3,7 @@ package filersink
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -105,15 +106,11 @@ func (fs *FilerSink) fetchAndWrite(ctx context.Context, sourceChunk *filer_pb.Fi
|
||||
|
||||
func (fs *FilerSink) withFilerClient(ctx context.Context, fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||
|
||||
grpcConnection, err := util.GrpcDial(ctx, fs.grpcAddress, fs.grpcDialOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to dial %s: %v", fs.grpcAddress, err)
|
||||
}
|
||||
defer grpcConnection.Close()
|
||||
return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {
|
||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||
return fn(client)
|
||||
}, fs.grpcAddress, fs.grpcDialOption)
|
||||
|
||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||
|
||||
return fn(client)
|
||||
}
|
||||
|
||||
func volumeId(fileId string) string {
|
||||
|
||||
@@ -91,15 +91,11 @@ func (fs *FilerSource) ReadPart(ctx context.Context, part string) (filename stri
|
||||
|
||||
func (fs *FilerSource) withFilerClient(ctx context.Context, grpcDialOption grpc.DialOption, fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||
|
||||
grpcConnection, err := util.GrpcDial(ctx, fs.grpcAddress, grpcDialOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to dial %s: %v", fs.grpcAddress, err)
|
||||
}
|
||||
defer grpcConnection.Close()
|
||||
return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {
|
||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||
return fn(client)
|
||||
}, fs.grpcAddress, fs.grpcDialOption)
|
||||
|
||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||
|
||||
return fn(client)
|
||||
}
|
||||
|
||||
func volumeId(fileId string) string {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package sub
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"gocloud.dev/pubsub"
|
||||
_ "gocloud.dev/pubsub/awssnssqs"
|
||||
_ "gocloud.dev/pubsub/azuresb"
|
||||
_ "gocloud.dev/pubsub/gcppubsub"
|
||||
_ "gocloud.dev/pubsub/natspubsub"
|
||||
_ "gocloud.dev/pubsub/rabbitpubsub"
|
||||
)
|
||||
|
||||
func init() {
|
||||
NotificationInputs = append(NotificationInputs, &GoCDKPubSubInput{})
|
||||
}
|
||||
|
||||
type GoCDKPubSubInput struct {
|
||||
sub *pubsub.Subscription
|
||||
}
|
||||
|
||||
func (k *GoCDKPubSubInput) GetName() string {
|
||||
return "gocdk_pub_sub"
|
||||
}
|
||||
|
||||
func (k *GoCDKPubSubInput) Initialize(config util.Configuration) error {
|
||||
subURL := config.GetString("sub_url")
|
||||
glog.V(0).Infof("notification.gocdk_pub_sub.sub_url: %v", subURL)
|
||||
sub, err := pubsub.OpenSubscription(context.Background(), subURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
k.sub = sub
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *GoCDKPubSubInput) ReceiveMessage() (key string, message *filer_pb.EventNotification, err error) {
|
||||
msg, err := k.sub.Receive(context.Background())
|
||||
key = msg.Metadata["key"]
|
||||
message = &filer_pb.EventNotification{}
|
||||
err = proto.Unmarshal(msg.Body, message)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return key, message, nil
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package s3api
|
||||
|
||||
const s3TimeFormat = "2006-01-02T15:04:05.999Z07:00"
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"google.golang.org/grpc"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
@@ -38,15 +39,11 @@ func encodeResponse(response interface{}) []byte {
|
||||
|
||||
func (s3a *S3ApiServer) withFilerClient(ctx context.Context, fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||
|
||||
grpcConnection, err := util.GrpcDial(ctx, s3a.option.FilerGrpcAddress, s3a.option.GrpcDialOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to dial %s: %v", s3a.option.FilerGrpcAddress, err)
|
||||
}
|
||||
defer grpcConnection.Close()
|
||||
return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {
|
||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||
return fn(client)
|
||||
}, s3a.option.FilerGrpcAddress, s3a.option.GrpcDialOption)
|
||||
|
||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||
|
||||
return fn(client)
|
||||
}
|
||||
|
||||
// If none of the http routes match respond with MethodNotAllowed
|
||||
|
||||
@@ -200,8 +200,8 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
|
||||
dataReader = newSignV4ChunkedReader(r)
|
||||
}
|
||||
|
||||
uploadUrl := fmt.Sprintf("http://%s%s/%s/%04d.part",
|
||||
s3a.option.Filer, s3a.genUploadsFolder(bucket), uploadID, partID-1)
|
||||
uploadUrl := fmt.Sprintf("http://%s%s/%s/%04d.part?collection=%s",
|
||||
s3a.option.Filer, s3a.genUploadsFolder(bucket), uploadID, partID-1, bucket)
|
||||
|
||||
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
|
||||
|
||||
|
||||
@@ -131,8 +131,8 @@ func (s3a *S3ApiServer) listFilerEntries(ctx context.Context, bucket, originalPr
|
||||
ETag: "\"" + filer2.ETag(entry.Chunks) + "\"",
|
||||
Size: int64(filer2.TotalSize(entry.Chunks)),
|
||||
Owner: CanonicalUser{
|
||||
ID: "bcaf161ca5fb16fd081034f",
|
||||
DisplayName: "webfile",
|
||||
ID: fmt.Sprintf("%x", entry.Attributes.Uid),
|
||||
DisplayName: entry.Attributes.UserName,
|
||||
},
|
||||
StorageClass: "STANDARD",
|
||||
})
|
||||
@@ -151,7 +151,7 @@ func (s3a *S3ApiServer) listFilerEntries(ctx context.Context, bucket, originalPr
|
||||
CommonPrefixes: commonPrefixes,
|
||||
}
|
||||
|
||||
glog.V(4).Infof("read directory: %v, found: %v", request, counter)
|
||||
glog.V(4).Infof("read directory: %v, found: %v, %+v", request, counter, response)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -10,7 +10,7 @@ func TestListObjectsHandler(t *testing.T) {
|
||||
// https://docs.aws.amazon.com/AmazonS3/latest/API/v2-RESTBucketGET.html
|
||||
|
||||
expected := `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>test_container</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>1.zip</Key><ETag>"4397da7a7649e8085de9916c240e8166"</ETag><Size>1234567</Size><Owner><ID>65a011niqo39cdf8ec533ec3d1ccaafsa932</ID></Owner><StorageClass>STANDARD</StorageClass><LastModified>2011-04-09T12:34:49</LastModified></Contents></ListBucketResult>`
|
||||
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>test_container</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>1.zip</Key><ETag>"4397da7a7649e8085de9916c240e8166"</ETag><Size>1234567</Size><Owner><ID>65a011niqo39cdf8ec533ec3d1ccaafsa932</ID></Owner><StorageClass>STANDARD</StorageClass><LastModified>2011-04-09T12:34:49Z</LastModified></Contents></ListBucketResult>`
|
||||
|
||||
response := ListBucketResult{
|
||||
Name: "test_container",
|
||||
|
||||
@@ -966,10 +966,10 @@ func (b xsdBase64Binary) MarshalText() ([]byte, error) {
|
||||
type xsdDateTime time.Time
|
||||
|
||||
func (t *xsdDateTime) UnmarshalText(text []byte) error {
|
||||
return _unmarshalTime(text, (*time.Time)(t), "2006-01-02T15:04:05.999999999")
|
||||
return _unmarshalTime(text, (*time.Time)(t), s3TimeFormat)
|
||||
}
|
||||
func (t xsdDateTime) MarshalText() ([]byte, error) {
|
||||
return []byte((time.Time)(t).Format("2006-01-02T15:04:05.999999999")), nil
|
||||
return []byte((time.Time)(t).Format(s3TimeFormat)), nil
|
||||
}
|
||||
func (t xsdDateTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
if (time.Time)(t).IsZero() {
|
||||
|
||||
@@ -24,7 +24,8 @@ func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.Atom
|
||||
return nil, fmt.Errorf("%s/%s not found: %v", req.OldDirectory, req.OldName, err)
|
||||
}
|
||||
|
||||
moveErr := fs.moveEntry(ctx, oldParent, oldEntry, filer2.FullPath(filepath.ToSlash(req.NewDirectory)), req.NewName)
|
||||
var events MoveEvents
|
||||
moveErr := fs.moveEntry(ctx, oldParent, oldEntry, filer2.FullPath(filepath.ToSlash(req.NewDirectory)), req.NewName, &events)
|
||||
if moveErr != nil {
|
||||
fs.filer.RollbackTransaction(ctx)
|
||||
return nil, fmt.Errorf("%s/%s move error: %v", req.OldDirectory, req.OldName, err)
|
||||
@@ -35,19 +36,26 @@ func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.Atom
|
||||
}
|
||||
}
|
||||
|
||||
for _, entry := range events.newEntries {
|
||||
fs.filer.NotifyUpdateEvent(nil, entry, false)
|
||||
}
|
||||
for _, entry := range events.oldEntries {
|
||||
fs.filer.NotifyUpdateEvent(entry, nil, false)
|
||||
}
|
||||
|
||||
return &filer_pb.AtomicRenameEntryResponse{}, nil
|
||||
}
|
||||
|
||||
func (fs *FilerServer) moveEntry(ctx context.Context, oldParent filer2.FullPath, entry *filer2.Entry, newParent filer2.FullPath, newName string) error {
|
||||
func (fs *FilerServer) moveEntry(ctx context.Context, oldParent filer2.FullPath, entry *filer2.Entry, newParent filer2.FullPath, newName string, events *MoveEvents) error {
|
||||
if entry.IsDirectory() {
|
||||
if err := fs.moveFolderSubEntries(ctx, oldParent, entry, newParent, newName); err != nil {
|
||||
if err := fs.moveFolderSubEntries(ctx, oldParent, entry, newParent, newName, events); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return fs.moveSelfEntry(ctx, oldParent, entry, newParent, newName)
|
||||
return fs.moveSelfEntry(ctx, oldParent, entry, newParent, newName, events)
|
||||
}
|
||||
|
||||
func (fs *FilerServer) moveFolderSubEntries(ctx context.Context, oldParent filer2.FullPath, entry *filer2.Entry, newParent filer2.FullPath, newName string) error {
|
||||
func (fs *FilerServer) moveFolderSubEntries(ctx context.Context, oldParent filer2.FullPath, entry *filer2.Entry, newParent filer2.FullPath, newName string, events *MoveEvents) error {
|
||||
|
||||
currentDirPath := oldParent.Child(entry.Name())
|
||||
newDirPath := newParent.Child(newName)
|
||||
@@ -68,7 +76,7 @@ func (fs *FilerServer) moveFolderSubEntries(ctx context.Context, oldParent filer
|
||||
for _, item := range entries {
|
||||
lastFileName = item.Name()
|
||||
println("processing", lastFileName)
|
||||
err := fs.moveEntry(ctx, currentDirPath, item, newDirPath, item.Name())
|
||||
err := fs.moveEntry(ctx, currentDirPath, item, newDirPath, item.Name(), events)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -80,18 +88,19 @@ func (fs *FilerServer) moveFolderSubEntries(ctx context.Context, oldParent filer
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *FilerServer) moveSelfEntry(ctx context.Context, oldParent filer2.FullPath, entry *filer2.Entry, newParent filer2.FullPath, newName string) error {
|
||||
func (fs *FilerServer) moveSelfEntry(ctx context.Context, oldParent filer2.FullPath, entry *filer2.Entry, newParent filer2.FullPath, newName string, events *MoveEvents) (error) {
|
||||
|
||||
oldPath, newPath := oldParent.Child(entry.Name()), newParent.Child(newName)
|
||||
|
||||
glog.V(1).Infof("moving entry %s => %s", oldPath, newPath)
|
||||
|
||||
// add to new directory
|
||||
createErr := fs.filer.CreateEntry(ctx, &filer2.Entry{
|
||||
newEntry := &filer2.Entry{
|
||||
FullPath: newPath,
|
||||
Attr: entry.Attr,
|
||||
Chunks: entry.Chunks,
|
||||
})
|
||||
}
|
||||
createErr := fs.filer.CreateEntry(ctx, newEntry)
|
||||
if createErr != nil {
|
||||
return createErr
|
||||
}
|
||||
@@ -101,6 +110,14 @@ func (fs *FilerServer) moveSelfEntry(ctx context.Context, oldParent filer2.FullP
|
||||
if deleteErr != nil {
|
||||
return deleteErr
|
||||
}
|
||||
|
||||
events.oldEntries = append(events.oldEntries, entry)
|
||||
events.newEntries = append(events.newEntries, newEntry)
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
type MoveEvents struct {
|
||||
oldEntries []*filer2.Entry
|
||||
newEntries []*filer2.Entry
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ
|
||||
rack := dc.GetOrCreateRack(rackName)
|
||||
dn = rack.GetOrCreateDataNode(heartbeat.Ip,
|
||||
int(heartbeat.Port), heartbeat.PublicUrl,
|
||||
int(heartbeat.MaxVolumeCount))
|
||||
int64(heartbeat.MaxVolumeCount))
|
||||
glog.V(0).Infof("added volume server %v:%d", heartbeat.GetIp(), heartbeat.GetPort())
|
||||
if err := stream.Send(&master_pb.HeartbeatResponse{
|
||||
VolumeSizeLimit: uint64(ms.volumeSizeLimitMB) * 1024 * 1024,
|
||||
|
||||
@@ -68,8 +68,8 @@ func (ms *MasterServer) volumeGrowHandler(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
if err == nil {
|
||||
if count, err = strconv.Atoi(r.FormValue("count")); err == nil {
|
||||
if ms.Topo.FreeSpace() < count*option.ReplicaPlacement.GetCopyCount() {
|
||||
err = errors.New("Only " + strconv.Itoa(ms.Topo.FreeSpace()) + " volumes left! Not enough for " + strconv.Itoa(count*option.ReplicaPlacement.GetCopyCount()))
|
||||
if ms.Topo.FreeSpace() < int64(count*option.ReplicaPlacement.GetCopyCount()) {
|
||||
err = fmt.Errorf("only %d volumes left, not enough for %d", ms.Topo.FreeSpace(), count*option.ReplicaPlacement.GetCopyCount())
|
||||
} else {
|
||||
count, err = ms.vg.GrowByCountAndType(ms.grpcDialOpiton, count, option, ms.Topo)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package weed_server
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
@@ -28,7 +27,7 @@ func (vs *VolumeServer) VolumeFollow(req *volume_server_pb.VolumeFollowRequest,
|
||||
return nil
|
||||
}
|
||||
|
||||
startOffset := int64(foundOffset) * int64(types.NeedlePaddingSize)
|
||||
startOffset := foundOffset.ToAcutalOffset()
|
||||
|
||||
buf := make([]byte, 1024*1024*2)
|
||||
return sendFileContent(v.DataFile(), buf, startOffset, stopOffset, stream)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
)
|
||||
|
||||
func init() {
|
||||
commands = append(commands, &commandFsCd{})
|
||||
}
|
||||
|
||||
type commandFsCd struct {
|
||||
}
|
||||
|
||||
func (c *commandFsCd) Name() string {
|
||||
return "fs.cd"
|
||||
}
|
||||
|
||||
func (c *commandFsCd) Help() string {
|
||||
return `change directory to http://<filer_server>:<port>/dir/
|
||||
|
||||
The full path can be too long to type. For example,
|
||||
fs.ls http://<filer_server>:<port>/some/path/to/file_name
|
||||
|
||||
can be simplified as
|
||||
|
||||
fs.cd http://<filer_server>:<port>/some/path
|
||||
fs.ls to/file_name
|
||||
`
|
||||
}
|
||||
|
||||
func (c *commandFsCd) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
|
||||
|
||||
input := findInputDirectory(args)
|
||||
|
||||
filerServer, filerPort, path, err := commandEnv.parseUrl(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if path == "/" {
|
||||
commandEnv.option.FilerHost = filerServer
|
||||
commandEnv.option.FilerPort = filerPort
|
||||
commandEnv.option.Directory = "/"
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
err = commandEnv.checkDirectory(ctx, filerServer, filerPort, path)
|
||||
|
||||
if err == nil {
|
||||
commandEnv.option.FilerHost = filerServer
|
||||
commandEnv.option.FilerPort = filerPort
|
||||
commandEnv.option.Directory = path
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -8,9 +8,6 @@ import (
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"google.golang.org/grpc"
|
||||
"io"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -35,21 +32,18 @@ func (c *commandFsDu) Help() string {
|
||||
|
||||
func (c *commandFsDu) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
|
||||
|
||||
filerServer, filerPort, path, err := parseFilerUrl(args[0])
|
||||
filerServer, filerPort, path, err := commandEnv.parseUrl(findInputDirectory(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir, name := filer2.FullPath(path).DirAndName()
|
||||
if strings.HasSuffix(path, "/") {
|
||||
if path == "/" {
|
||||
dir, name = "/", ""
|
||||
} else {
|
||||
dir, name = path[0:len(path)-1], ""
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
if commandEnv.isDirectory(ctx, filerServer, filerPort, path) {
|
||||
path = path + "/"
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
dir, name := filer2.FullPath(path).DirAndName()
|
||||
|
||||
return commandEnv.withFilerClient(ctx, filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
@@ -112,25 +106,6 @@ func paginateDirectory(ctx context.Context, writer io.Writer, client filer_pb.Se
|
||||
|
||||
}
|
||||
|
||||
func parseFilerUrl(entryPath string) (filerServer string, filerPort int64, path string, err error) {
|
||||
if strings.HasPrefix(entryPath, "http") {
|
||||
var u *url.URL
|
||||
u, err = url.Parse(entryPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
filerServer = u.Hostname()
|
||||
portString := u.Port()
|
||||
if portString != "" {
|
||||
filerPort, err = strconv.ParseInt(portString, 10, 32)
|
||||
}
|
||||
path = u.Path
|
||||
} else {
|
||||
err = fmt.Errorf("path should have full url http://<filer_server>:<port>/path/to/dirOrFile : %s", entryPath)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (env *commandEnv) withFilerClient(ctx context.Context, filerServer string, filerPort int64, fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||
|
||||
filerGrpcAddress := fmt.Sprintf("%s:%d", filerServer, filerPort+10000)
|
||||
|
||||
+18
-14
@@ -36,29 +36,33 @@ func (c *commandFsLs) Do(args []string, commandEnv *commandEnv, writer io.Writer
|
||||
|
||||
var isLongFormat, showHidden bool
|
||||
for _, arg := range args {
|
||||
switch arg {
|
||||
case "-a":
|
||||
showHidden = true
|
||||
case "-l":
|
||||
isLongFormat = true
|
||||
if !strings.HasPrefix(arg, "-") {
|
||||
break
|
||||
}
|
||||
for _, t := range arg {
|
||||
switch t {
|
||||
case 'a':
|
||||
showHidden = true
|
||||
case 'l':
|
||||
isLongFormat = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filerServer, filerPort, path, err := parseFilerUrl(args[len(args)-1])
|
||||
input := findInputDirectory(args)
|
||||
|
||||
filerServer, filerPort, path, err := commandEnv.parseUrl(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir, name := filer2.FullPath(path).DirAndName()
|
||||
if strings.HasSuffix(path, "/") {
|
||||
if path == "/" {
|
||||
dir, name = "/", ""
|
||||
} else {
|
||||
dir, name = path[0:len(path)-1], ""
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
if commandEnv.isDirectory(ctx, filerServer, filerPort, path) {
|
||||
path = path + "/"
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
dir, name := filer2.FullPath(path).DirAndName()
|
||||
|
||||
return commandEnv.withFilerClient(ctx, filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
func init() {
|
||||
commands = append(commands, &commandFsPwd{})
|
||||
}
|
||||
|
||||
type commandFsPwd struct {
|
||||
}
|
||||
|
||||
func (c *commandFsPwd) Name() string {
|
||||
return "fs.pwd"
|
||||
}
|
||||
|
||||
func (c *commandFsPwd) Help() string {
|
||||
return `print out current directory`
|
||||
}
|
||||
|
||||
func (c *commandFsPwd) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
|
||||
|
||||
fmt.Fprintf(writer, "http://%s:%d%s\n",
|
||||
commandEnv.option.FilerHost,
|
||||
commandEnv.option.FilerPort,
|
||||
commandEnv.option.Directory,
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -29,33 +29,33 @@ func (c *commandFsTree) Help() string {
|
||||
|
||||
func (c *commandFsTree) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
|
||||
|
||||
filerServer, filerPort, path, err := parseFilerUrl(args[len(args)-1])
|
||||
filerServer, filerPort, path, err := commandEnv.parseUrl(findInputDirectory(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir, name := filer2.FullPath(path).DirAndName()
|
||||
if strings.HasSuffix(path, "/") {
|
||||
if path == "/" {
|
||||
dir, name = "/", ""
|
||||
} else {
|
||||
dir, name = path[0:len(path)-1], ""
|
||||
}
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
return commandEnv.withFilerClient(ctx, filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
return treeTraverseDirectory(ctx, writer, client, dir, name, 1000, newPrefix(), 0)
|
||||
dirCount, fCount, terr := treeTraverseDirectory(ctx, writer, client, dir, name, newPrefix(), -1)
|
||||
|
||||
if terr == nil {
|
||||
fmt.Fprintf(writer, "%d directories, %d files\n", dirCount, fCount)
|
||||
}
|
||||
|
||||
return terr
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
func treeTraverseDirectory(ctx context.Context, writer io.Writer, client filer_pb.SeaweedFilerClient, dir, name string, paginateSize int, prefix *Prefix, level int) (err error) {
|
||||
func treeTraverseDirectory(ctx context.Context, writer io.Writer, client filer_pb.SeaweedFilerClient, dir, name string, prefix *Prefix, level int) (directoryCount, fileCount int64, err error) {
|
||||
|
||||
paginatedCount := -1
|
||||
startFromFileName := ""
|
||||
paginateSize := 1000
|
||||
|
||||
for paginatedCount == -1 || paginatedCount == paginateSize {
|
||||
resp, listErr := client.ListEntries(ctx, &filer_pb.ListEntriesRequest{
|
||||
@@ -76,17 +76,29 @@ func treeTraverseDirectory(ctx context.Context, writer io.Writer, client filer_p
|
||||
}
|
||||
|
||||
for i, entry := range resp.Entries {
|
||||
|
||||
if level < 0 && name != "" {
|
||||
if entry.Name != name {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 0.1% wrong prefix here, but fixing it would need to paginate to the next batch first
|
||||
isLast := paginatedCount < paginateSize && i == paginatedCount-1
|
||||
fmt.Fprintf(writer, "%s%s\n", prefix.getPrefix(level, isLast), entry.Name)
|
||||
|
||||
if entry.IsDirectory {
|
||||
directoryCount++
|
||||
subDir := fmt.Sprintf("%s/%s", dir, entry.Name)
|
||||
if dir == "/" {
|
||||
subDir = "/" + entry.Name
|
||||
}
|
||||
err = treeTraverseDirectory(ctx, writer, client, subDir, "", paginateSize, prefix, level+1)
|
||||
dirCount, fCount, terr := treeTraverseDirectory(ctx, writer, client, subDir, "", prefix, level+1)
|
||||
directoryCount += dirCount
|
||||
fileCount += fCount
|
||||
err = terr
|
||||
} else {
|
||||
fileCount++
|
||||
}
|
||||
startFromFileName = entry.Name
|
||||
|
||||
@@ -114,6 +126,9 @@ func (p *Prefix) removeMarker(marker int) {
|
||||
}
|
||||
func (p *Prefix) getPrefix(level int, isLastChild bool) string {
|
||||
var sb strings.Builder
|
||||
if level < 0 {
|
||||
return ""
|
||||
}
|
||||
for i := 0; i < level; i++ {
|
||||
if _, ok := p.markers[i]; ok {
|
||||
sb.WriteString("│")
|
||||
|
||||
@@ -42,30 +42,75 @@ func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo) {
|
||||
func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo) statistics {
|
||||
fmt.Fprintf(writer, "Topology volume:%d/%d active:%d free:%d\n", t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
||||
var s statistics
|
||||
for _, dc := range t.DataCenterInfos {
|
||||
writeDataCenterInfo(writer, dc)
|
||||
s = s.plus(writeDataCenterInfo(writer, dc))
|
||||
}
|
||||
fmt.Fprintf(writer, "%+v \n", s)
|
||||
return s
|
||||
}
|
||||
func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo) {
|
||||
func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo) statistics {
|
||||
fmt.Fprintf(writer, " DataCenter %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
||||
var s statistics
|
||||
for _, r := range t.RackInfos {
|
||||
writeRackInfo(writer, r)
|
||||
s = s.plus(writeRackInfo(writer, r))
|
||||
}
|
||||
fmt.Fprintf(writer, " DataCenter %s %+v \n", t.Id, s)
|
||||
return s
|
||||
}
|
||||
func writeRackInfo(writer io.Writer, t *master_pb.RackInfo) {
|
||||
func writeRackInfo(writer io.Writer, t *master_pb.RackInfo) statistics {
|
||||
fmt.Fprintf(writer, " Rack %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
||||
var s statistics
|
||||
for _, dn := range t.DataNodeInfos {
|
||||
writeDataNodeInfo(writer, dn)
|
||||
s = s.plus(writeDataNodeInfo(writer, dn))
|
||||
}
|
||||
fmt.Fprintf(writer, " Rack %s %+v \n", t.Id, s)
|
||||
return s
|
||||
}
|
||||
func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) {
|
||||
func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) statistics {
|
||||
fmt.Fprintf(writer, " DataNode %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
||||
var s statistics
|
||||
for _, vi := range t.VolumeInfos {
|
||||
writeVolumeInformationMessage(writer, vi)
|
||||
s = s.plus(writeVolumeInformationMessage(writer, vi))
|
||||
}
|
||||
fmt.Fprintf(writer, " DataNode %s %+v \n", t.Id, s)
|
||||
return s
|
||||
}
|
||||
func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) statistics {
|
||||
fmt.Fprintf(writer, " volume %+v \n", t)
|
||||
return newStatiscis(t)
|
||||
}
|
||||
|
||||
type statistics struct {
|
||||
Size uint64
|
||||
FileCount uint64
|
||||
DeletedFileCount uint64
|
||||
DeletedBytes uint64
|
||||
}
|
||||
|
||||
func newStatiscis(t *master_pb.VolumeInformationMessage) statistics {
|
||||
return statistics{
|
||||
Size: t.Size,
|
||||
FileCount: t.FileCount,
|
||||
DeletedFileCount: t.DeleteCount,
|
||||
DeletedBytes: t.DeletedByteCount,
|
||||
}
|
||||
}
|
||||
func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) {
|
||||
fmt.Fprintf(writer, " volume %+v \n", t)
|
||||
|
||||
func (s statistics) plus(t statistics) statistics {
|
||||
return statistics{
|
||||
Size: s.Size + t.Size,
|
||||
FileCount: s.FileCount + t.FileCount,
|
||||
DeletedFileCount: s.DeletedFileCount + t.DeletedFileCount,
|
||||
DeletedBytes: s.DeletedBytes + t.DeletedBytes,
|
||||
}
|
||||
}
|
||||
|
||||
func (s statistics) String() string {
|
||||
if s.DeletedFileCount > 0 {
|
||||
return fmt.Sprintf("total size:%d file_count:%d deleted_file:%d deleted_bytes:%d", s.Size, s.FileCount, s.DeletedFileCount, s.DeletedBytes)
|
||||
}
|
||||
return fmt.Sprintf("total size:%d file_count:%d", s.Size, s.FileCount)
|
||||
}
|
||||
@@ -1,14 +1,26 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/wdclient"
|
||||
"google.golang.org/grpc"
|
||||
"io"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ShellOptions struct {
|
||||
Masters *string
|
||||
GrpcDialOption grpc.DialOption
|
||||
// shell transient context
|
||||
FilerHost string
|
||||
FilerPort int64
|
||||
Directory string
|
||||
}
|
||||
|
||||
type commandEnv struct {
|
||||
@@ -26,3 +38,83 @@ type command interface {
|
||||
var (
|
||||
commands = []command{}
|
||||
)
|
||||
|
||||
func (ce *commandEnv) parseUrl(input string) (filerServer string, filerPort int64, path string, err error) {
|
||||
if strings.HasPrefix(input, "http") {
|
||||
return parseFilerUrl(input)
|
||||
}
|
||||
if !strings.HasPrefix(input, "/") {
|
||||
input = filepath.ToSlash(filepath.Join(ce.option.Directory, input))
|
||||
}
|
||||
return ce.option.FilerHost, ce.option.FilerPort, input, err
|
||||
}
|
||||
|
||||
func (ce *commandEnv) isDirectory(ctx context.Context, filerServer string, filerPort int64, path string) bool {
|
||||
|
||||
return ce.checkDirectory(ctx,filerServer,filerPort,path) == nil
|
||||
|
||||
}
|
||||
|
||||
func (ce *commandEnv) checkDirectory(ctx context.Context, filerServer string, filerPort int64, path string) error {
|
||||
|
||||
dir, name := filer2.FullPath(path).DirAndName()
|
||||
|
||||
return ce.withFilerClient(ctx, filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
resp, listErr := client.ListEntries(ctx, &filer_pb.ListEntriesRequest{
|
||||
Directory: dir,
|
||||
Prefix: name,
|
||||
StartFromFileName: name,
|
||||
InclusiveStartFrom: true,
|
||||
Limit: 1,
|
||||
})
|
||||
if listErr != nil {
|
||||
return listErr
|
||||
}
|
||||
|
||||
if len(resp.Entries) == 0 {
|
||||
return fmt.Errorf("entry not found")
|
||||
}
|
||||
|
||||
if resp.Entries[0].Name != name {
|
||||
return fmt.Errorf("not a valid directory, found %s", resp.Entries[0].Name)
|
||||
}
|
||||
|
||||
if !resp.Entries[0].IsDirectory {
|
||||
return fmt.Errorf("not a directory")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func parseFilerUrl(entryPath string) (filerServer string, filerPort int64, path string, err error) {
|
||||
if strings.HasPrefix(entryPath, "http") {
|
||||
var u *url.URL
|
||||
u, err = url.Parse(entryPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
filerServer = u.Hostname()
|
||||
portString := u.Port()
|
||||
if portString != "" {
|
||||
filerPort, err = strconv.ParseInt(portString, 10, 32)
|
||||
}
|
||||
path = u.Path
|
||||
} else {
|
||||
err = fmt.Errorf("path should have full url http://<filer_server>:<port>/path/to/dirOrFile : %s", entryPath)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func findInputDirectory(args []string) (input string) {
|
||||
input = "."
|
||||
if len(args) > 0 {
|
||||
input = args[len(args)-1]
|
||||
if strings.HasPrefix(input, "-") {
|
||||
input = "."
|
||||
}
|
||||
}
|
||||
return input
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func (cm *BtreeMap) Set(key NeedleId, offset Offset, size uint32) (oldOffset Off
|
||||
}
|
||||
|
||||
func (cm *BtreeMap) Delete(key NeedleId) (oldSize uint32) {
|
||||
found := cm.tree.Delete(NeedleValue{key, 0, 0})
|
||||
found := cm.tree.Delete(NeedleValue{key, Offset{}, 0})
|
||||
if found != nil {
|
||||
old := found.(NeedleValue)
|
||||
return old.Size
|
||||
@@ -34,7 +34,7 @@ func (cm *BtreeMap) Delete(key NeedleId) (oldSize uint32) {
|
||||
return
|
||||
}
|
||||
func (cm *BtreeMap) Get(key NeedleId) (*NeedleValue, bool) {
|
||||
found := cm.tree.Get(NeedleValue{key, 0, 0})
|
||||
found := cm.tree.Get(NeedleValue{key, Offset{}, 0})
|
||||
if found != nil {
|
||||
old := found.(NeedleValue)
|
||||
return &old, true
|
||||
|
||||
@@ -15,27 +15,36 @@ type SectionalNeedleId uint32
|
||||
const SectionalNeedleIdLimit = 1<<32 - 1
|
||||
|
||||
type SectionalNeedleValue struct {
|
||||
Key SectionalNeedleId
|
||||
Offset Offset `comment:"Volume offset"` //since aligned to 8 bytes, range is 4G*8=32G
|
||||
Size uint32 `comment:"Size of the data portion"`
|
||||
Key SectionalNeedleId
|
||||
OffsetLower OffsetLower `comment:"Volume offset"` //since aligned to 8 bytes, range is 4G*8=32G
|
||||
Size uint32 `comment:"Size of the data portion"`
|
||||
}
|
||||
|
||||
type SectionalNeedleValueExtra struct {
|
||||
OffsetHigher OffsetHigher
|
||||
}
|
||||
|
||||
type CompactSection struct {
|
||||
sync.RWMutex
|
||||
values []SectionalNeedleValue
|
||||
overflow Overflow
|
||||
start NeedleId
|
||||
end NeedleId
|
||||
counter int
|
||||
values []SectionalNeedleValue
|
||||
valuesExtra []SectionalNeedleValueExtra
|
||||
overflow Overflow
|
||||
overflowExtra OverflowExtra
|
||||
start NeedleId
|
||||
end NeedleId
|
||||
counter int
|
||||
}
|
||||
|
||||
type Overflow []SectionalNeedleValue
|
||||
type OverflowExtra []SectionalNeedleValueExtra
|
||||
|
||||
func NewCompactSection(start NeedleId) *CompactSection {
|
||||
return &CompactSection{
|
||||
values: make([]SectionalNeedleValue, batch),
|
||||
overflow: Overflow(make([]SectionalNeedleValue, 0)),
|
||||
start: start,
|
||||
values: make([]SectionalNeedleValue, batch),
|
||||
valuesExtra: make([]SectionalNeedleValueExtra, batch),
|
||||
overflow: Overflow(make([]SectionalNeedleValue, 0)),
|
||||
overflowExtra: OverflowExtra(make([]SectionalNeedleValueExtra, 0)),
|
||||
start: start,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,21 +56,21 @@ func (cs *CompactSection) Set(key NeedleId, offset Offset, size uint32) (oldOffs
|
||||
}
|
||||
skey := SectionalNeedleId(key - cs.start)
|
||||
if i := cs.binarySearchValues(skey); i >= 0 {
|
||||
oldOffset, oldSize = cs.values[i].Offset, cs.values[i].Size
|
||||
oldOffset.OffsetHigher, oldOffset.OffsetLower, oldSize = cs.valuesExtra[i].OffsetHigher, cs.values[i].OffsetLower, cs.values[i].Size
|
||||
//println("key", key, "old size", ret)
|
||||
cs.values[i].Offset, cs.values[i].Size = offset, size
|
||||
cs.valuesExtra[i].OffsetHigher, cs.values[i].OffsetLower, cs.values[i].Size = offset.OffsetHigher, offset.OffsetLower, size
|
||||
} else {
|
||||
needOverflow := cs.counter >= batch
|
||||
needOverflow = needOverflow || cs.counter > 0 && cs.values[cs.counter-1].Key > skey
|
||||
if needOverflow {
|
||||
//println("start", cs.start, "counter", cs.counter, "key", key)
|
||||
if oldValue, found := cs.overflow.findOverflowEntry(skey); found {
|
||||
oldOffset, oldSize = oldValue.Offset, oldValue.Size
|
||||
if oldValueExtra, oldValue, found := cs.findOverflowEntry(skey); found {
|
||||
oldOffset.OffsetHigher, oldOffset.OffsetLower, oldSize = oldValueExtra.OffsetHigher, oldValue.OffsetLower, oldValue.Size
|
||||
}
|
||||
cs.overflow = cs.overflow.setOverflowEntry(SectionalNeedleValue{Key: skey, Offset: offset, Size: size})
|
||||
cs.setOverflowEntry(skey, offset, size)
|
||||
} else {
|
||||
p := &cs.values[cs.counter]
|
||||
p.Key, p.Offset, p.Size = skey, offset, size
|
||||
p.Key, cs.valuesExtra[cs.counter].OffsetHigher, p.OffsetLower, p.Size = skey, offset.OffsetHigher, offset.OffsetLower, size
|
||||
//println("added index", cs.counter, "key", key, cs.values[cs.counter].Key)
|
||||
cs.counter++
|
||||
}
|
||||
@@ -70,6 +79,50 @@ func (cs *CompactSection) Set(key NeedleId, offset Offset, size uint32) (oldOffs
|
||||
return
|
||||
}
|
||||
|
||||
func (cs *CompactSection) setOverflowEntry(skey SectionalNeedleId, offset Offset, size uint32) {
|
||||
needleValue := SectionalNeedleValue{Key: skey, OffsetLower: offset.OffsetLower, Size: size}
|
||||
needleValueExtra := SectionalNeedleValueExtra{OffsetHigher: OffsetHigher{}}
|
||||
insertCandidate := sort.Search(len(cs.overflow), func(i int) bool {
|
||||
return cs.overflow[i].Key >= needleValue.Key
|
||||
})
|
||||
if insertCandidate != len(cs.overflow) && cs.overflow[insertCandidate].Key == needleValue.Key {
|
||||
cs.overflow[insertCandidate] = needleValue
|
||||
} else {
|
||||
cs.overflow = append(cs.overflow, needleValue)
|
||||
cs.overflowExtra = append(cs.overflowExtra, needleValueExtra)
|
||||
for i := len(cs.overflow) - 1; i > insertCandidate; i-- {
|
||||
cs.overflow[i] = cs.overflow[i-1]
|
||||
cs.overflowExtra[i] = cs.overflowExtra[i-1]
|
||||
}
|
||||
cs.overflow[insertCandidate] = needleValue
|
||||
}
|
||||
}
|
||||
|
||||
func (cs *CompactSection) findOverflowEntry(key SectionalNeedleId) (nve SectionalNeedleValueExtra, nv SectionalNeedleValue, found bool) {
|
||||
foundCandidate := sort.Search(len(cs.overflow), func(i int) bool {
|
||||
return cs.overflow[i].Key >= key
|
||||
})
|
||||
if foundCandidate != len(cs.overflow) && cs.overflow[foundCandidate].Key == key {
|
||||
return cs.overflowExtra[foundCandidate], cs.overflow[foundCandidate], true
|
||||
}
|
||||
return nve, nv, false
|
||||
}
|
||||
|
||||
func (cs *CompactSection) deleteOverflowEntry(key SectionalNeedleId) {
|
||||
length := len(cs.overflow)
|
||||
deleteCandidate := sort.Search(length, func(i int) bool {
|
||||
return cs.overflow[i].Key >= key
|
||||
})
|
||||
if deleteCandidate != length && cs.overflow[deleteCandidate].Key == key {
|
||||
for i := deleteCandidate; i < length-1; i++ {
|
||||
cs.overflow[i] = cs.overflow[i+1]
|
||||
cs.overflowExtra[i] = cs.overflowExtra[i+1]
|
||||
}
|
||||
cs.overflow = cs.overflow[0 : length-1]
|
||||
cs.overflowExtra = cs.overflowExtra[0 : length-1]
|
||||
}
|
||||
}
|
||||
|
||||
//return old entry size
|
||||
func (cs *CompactSection) Delete(key NeedleId) uint32 {
|
||||
skey := SectionalNeedleId(key - cs.start)
|
||||
@@ -81,8 +134,8 @@ func (cs *CompactSection) Delete(key NeedleId) uint32 {
|
||||
cs.values[i].Size = TombstoneFileSize
|
||||
}
|
||||
}
|
||||
if v, found := cs.overflow.findOverflowEntry(skey); found {
|
||||
cs.overflow = cs.overflow.deleteOverflowEntry(skey)
|
||||
if _, v, found := cs.findOverflowEntry(skey); found {
|
||||
cs.deleteOverflowEntry(skey)
|
||||
ret = v.Size
|
||||
}
|
||||
cs.Unlock()
|
||||
@@ -91,14 +144,14 @@ func (cs *CompactSection) Delete(key NeedleId) uint32 {
|
||||
func (cs *CompactSection) Get(key NeedleId) (*NeedleValue, bool) {
|
||||
cs.RLock()
|
||||
skey := SectionalNeedleId(key - cs.start)
|
||||
if v, ok := cs.overflow.findOverflowEntry(skey); ok {
|
||||
if ve, v, ok := cs.findOverflowEntry(skey); ok {
|
||||
cs.RUnlock()
|
||||
nv := v.toNeedleValue(cs)
|
||||
nv := toNeedleValue(ve, v, cs)
|
||||
return &nv, true
|
||||
}
|
||||
if i := cs.binarySearchValues(skey); i >= 0 {
|
||||
cs.RUnlock()
|
||||
nv := cs.values[i].toNeedleValue(cs)
|
||||
nv := toNeedleValue(cs.valuesExtra[i], cs.values[i], cs)
|
||||
return &nv, true
|
||||
}
|
||||
cs.RUnlock()
|
||||
@@ -194,8 +247,8 @@ func (cm *CompactMap) binarySearchCompactSection(key NeedleId) int {
|
||||
func (cm *CompactMap) Visit(visit func(NeedleValue) error) error {
|
||||
for _, cs := range cm.list {
|
||||
cs.RLock()
|
||||
for _, v := range cs.overflow {
|
||||
if err := visit(v.toNeedleValue(cs)); err != nil {
|
||||
for i, v := range cs.overflow {
|
||||
if err := visit(toNeedleValue(cs.overflowExtra[i], v, cs)); err != nil {
|
||||
cs.RUnlock()
|
||||
return err
|
||||
}
|
||||
@@ -204,8 +257,8 @@ func (cm *CompactMap) Visit(visit func(NeedleValue) error) error {
|
||||
if i >= cs.counter {
|
||||
break
|
||||
}
|
||||
if _, found := cs.overflow.findOverflowEntry(v.Key); !found {
|
||||
if err := visit(v.toNeedleValue(cs)); err != nil {
|
||||
if _, _, found := cs.findOverflowEntry(v.Key); !found {
|
||||
if err := visit(toNeedleValue(cs.valuesExtra[i], v, cs)); err != nil {
|
||||
cs.RUnlock()
|
||||
return err
|
||||
}
|
||||
@@ -216,50 +269,20 @@ func (cm *CompactMap) Visit(visit func(NeedleValue) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o Overflow) deleteOverflowEntry(key SectionalNeedleId) Overflow {
|
||||
length := len(o)
|
||||
deleteCandidate := sort.Search(length, func(i int) bool {
|
||||
return o[i].Key >= key
|
||||
})
|
||||
if deleteCandidate != length && o[deleteCandidate].Key == key {
|
||||
for i := deleteCandidate; i < length-1; i++ {
|
||||
o[i] = o[i+1]
|
||||
}
|
||||
o = o[0 : length-1]
|
||||
func toNeedleValue(snve SectionalNeedleValueExtra, snv SectionalNeedleValue, cs *CompactSection) NeedleValue {
|
||||
offset := Offset{
|
||||
OffsetHigher: snve.OffsetHigher,
|
||||
OffsetLower: snv.OffsetLower,
|
||||
}
|
||||
return o
|
||||
return NeedleValue{Key: NeedleId(snv.Key) + cs.start, Offset: offset, Size: snv.Size}
|
||||
}
|
||||
|
||||
func (o Overflow) setOverflowEntry(needleValue SectionalNeedleValue) Overflow {
|
||||
insertCandidate := sort.Search(len(o), func(i int) bool {
|
||||
return o[i].Key >= needleValue.Key
|
||||
})
|
||||
if insertCandidate != len(o) && o[insertCandidate].Key == needleValue.Key {
|
||||
o[insertCandidate] = needleValue
|
||||
} else {
|
||||
o = append(o, needleValue)
|
||||
for i := len(o) - 1; i > insertCandidate; i-- {
|
||||
o[i] = o[i-1]
|
||||
}
|
||||
o[insertCandidate] = needleValue
|
||||
func (nv NeedleValue) toSectionalNeedleValue(cs *CompactSection) (SectionalNeedleValue, SectionalNeedleValueExtra) {
|
||||
return SectionalNeedleValue{
|
||||
SectionalNeedleId(nv.Key - cs.start),
|
||||
nv.Offset.OffsetLower,
|
||||
nv.Size,
|
||||
}, SectionalNeedleValueExtra{
|
||||
nv.Offset.OffsetHigher,
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
func (o Overflow) findOverflowEntry(key SectionalNeedleId) (nv SectionalNeedleValue, found bool) {
|
||||
foundCandidate := sort.Search(len(o), func(i int) bool {
|
||||
return o[i].Key >= key
|
||||
})
|
||||
if foundCandidate != len(o) && o[foundCandidate].Key == key {
|
||||
return o[foundCandidate], true
|
||||
}
|
||||
return nv, false
|
||||
}
|
||||
|
||||
func (snv SectionalNeedleValue) toNeedleValue(cs *CompactSection) NeedleValue {
|
||||
return NeedleValue{NeedleId(snv.Key) + cs.start, snv.Offset, snv.Size}
|
||||
}
|
||||
|
||||
func (nv NeedleValue) toSectionalNeedleValue(cs *CompactSection) SectionalNeedleValue {
|
||||
return SectionalNeedleValue{SectionalNeedleId(nv.Key - cs.start), nv.Offset, nv.Size}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func loadNewNeedleMap(file *os.File) (*CompactMap, uint64) {
|
||||
offset := BytesToOffset(bytes[i+NeedleIdSize : i+NeedleIdSize+OffsetSize])
|
||||
size := util.BytesToUint32(bytes[i+NeedleIdSize+OffsetSize : i+NeedleIdSize+OffsetSize+SizeSize])
|
||||
|
||||
if offset > 0 {
|
||||
if !offset.IsZero() {
|
||||
m.Set(NeedleId(key), offset, size)
|
||||
} else {
|
||||
m.Delete(key)
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package needle
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOverflow2(t *testing.T) {
|
||||
m := NewCompactMap()
|
||||
m.Set(NeedleId(150088), 8, 3000073)
|
||||
m.Set(NeedleId(150073), 8, 3000073)
|
||||
m.Set(NeedleId(150089), 8, 3000073)
|
||||
m.Set(NeedleId(150076), 8, 3000073)
|
||||
m.Set(NeedleId(150124), 8, 3000073)
|
||||
m.Set(NeedleId(150137), 8, 3000073)
|
||||
m.Set(NeedleId(150147), 8, 3000073)
|
||||
m.Set(NeedleId(150145), 8, 3000073)
|
||||
m.Set(NeedleId(150158), 8, 3000073)
|
||||
m.Set(NeedleId(150162), 8, 3000073)
|
||||
m.Set(NeedleId(150088), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150073), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150089), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150076), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150124), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150137), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150147), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150145), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150158), ToOffset(8), 3000073)
|
||||
m.Set(NeedleId(150162), ToOffset(8), 3000073)
|
||||
|
||||
m.Visit(func(value NeedleValue) error {
|
||||
println("needle key:", value.Key)
|
||||
@@ -26,13 +27,13 @@ func TestOverflow2(t *testing.T) {
|
||||
|
||||
func TestIssue52(t *testing.T) {
|
||||
m := NewCompactMap()
|
||||
m.Set(NeedleId(10002), 10002, 10002)
|
||||
m.Set(NeedleId(10002), ToOffset(10002), 10002)
|
||||
if element, ok := m.Get(NeedleId(10002)); ok {
|
||||
println("key", 10002, "ok", ok, element.Key, element.Offset, element.Size)
|
||||
fmt.Printf("key %d ok %v %d, %v, %d\n", 10002, ok, element.Key, element.Offset, element.Size)
|
||||
}
|
||||
m.Set(NeedleId(10001), 10001, 10001)
|
||||
m.Set(NeedleId(10001), ToOffset(10001), 10001)
|
||||
if element, ok := m.Get(NeedleId(10002)); ok {
|
||||
println("key", 10002, "ok", ok, element.Key, element.Offset, element.Size)
|
||||
fmt.Printf("key %d ok %v %d, %v, %d\n", 10002, ok, element.Key, element.Offset, element.Size)
|
||||
} else {
|
||||
t.Fatal("key 10002 missing after setting 10001")
|
||||
}
|
||||
@@ -41,7 +42,7 @@ func TestIssue52(t *testing.T) {
|
||||
func TestCompactMap(t *testing.T) {
|
||||
m := NewCompactMap()
|
||||
for i := uint32(0); i < 100*batch; i += 2 {
|
||||
m.Set(NeedleId(i), Offset(i), i)
|
||||
m.Set(NeedleId(i), ToOffset(int64(i)), i)
|
||||
}
|
||||
|
||||
for i := uint32(0); i < 100*batch; i += 37 {
|
||||
@@ -49,7 +50,7 @@ func TestCompactMap(t *testing.T) {
|
||||
}
|
||||
|
||||
for i := uint32(0); i < 10*batch; i += 3 {
|
||||
m.Set(NeedleId(i), Offset(i+11), i+5)
|
||||
m.Set(NeedleId(i), ToOffset(int64(i+11)), i+5)
|
||||
}
|
||||
|
||||
// for i := uint32(0); i < 100; i++ {
|
||||
@@ -97,60 +98,60 @@ func TestCompactMap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOverflow(t *testing.T) {
|
||||
o := Overflow(make([]SectionalNeedleValue, 0))
|
||||
cs := NewCompactSection(1)
|
||||
|
||||
o = o.setOverflowEntry(SectionalNeedleValue{Key: 1, Offset: 12, Size: 12})
|
||||
o = o.setOverflowEntry(SectionalNeedleValue{Key: 2, Offset: 12, Size: 12})
|
||||
o = o.setOverflowEntry(SectionalNeedleValue{Key: 3, Offset: 12, Size: 12})
|
||||
o = o.setOverflowEntry(SectionalNeedleValue{Key: 4, Offset: 12, Size: 12})
|
||||
o = o.setOverflowEntry(SectionalNeedleValue{Key: 5, Offset: 12, Size: 12})
|
||||
cs.setOverflowEntry(1, ToOffset(12), 12)
|
||||
cs.setOverflowEntry(2, ToOffset(12), 12)
|
||||
cs.setOverflowEntry(3, ToOffset(12), 12)
|
||||
cs.setOverflowEntry(4, ToOffset(12), 12)
|
||||
cs.setOverflowEntry(5, ToOffset(12), 12)
|
||||
|
||||
if o[2].Key != 3 {
|
||||
t.Fatalf("expecting o[2] has key 3: %+v", o[2].Key)
|
||||
if cs.overflow[2].Key != 3 {
|
||||
t.Fatalf("expecting o[2] has key 3: %+v", cs.overflow[2].Key)
|
||||
}
|
||||
|
||||
o = o.setOverflowEntry(SectionalNeedleValue{Key: 3, Offset: 24, Size: 24})
|
||||
cs.setOverflowEntry(3, ToOffset(24), 24)
|
||||
|
||||
if o[2].Key != 3 {
|
||||
t.Fatalf("expecting o[2] has key 3: %+v", o[2].Key)
|
||||
if cs.overflow[2].Key != 3 {
|
||||
t.Fatalf("expecting o[2] has key 3: %+v", cs.overflow[2].Key)
|
||||
}
|
||||
|
||||
if o[2].Size != 24 {
|
||||
t.Fatalf("expecting o[2] has size 24: %+v", o[2].Size)
|
||||
if cs.overflow[2].Size != 24 {
|
||||
t.Fatalf("expecting o[2] has size 24: %+v", cs.overflow[2].Size)
|
||||
}
|
||||
|
||||
o = o.deleteOverflowEntry(4)
|
||||
cs.deleteOverflowEntry(4)
|
||||
|
||||
if len(o) != 4 {
|
||||
t.Fatalf("expecting 4 entries now: %+v", o)
|
||||
if len(cs.overflow) != 4 {
|
||||
t.Fatalf("expecting 4 entries now: %+v", cs.overflow)
|
||||
}
|
||||
|
||||
x, _ := o.findOverflowEntry(5)
|
||||
_, x, _ := cs.findOverflowEntry(5)
|
||||
if x.Key != 5 {
|
||||
t.Fatalf("expecting entry 5 now: %+v", x)
|
||||
}
|
||||
|
||||
for i, x := range o {
|
||||
for i, x := range cs.overflow {
|
||||
println("overflow[", i, "]:", x.Key)
|
||||
}
|
||||
println()
|
||||
|
||||
o = o.deleteOverflowEntry(1)
|
||||
cs.deleteOverflowEntry(1)
|
||||
|
||||
for i, x := range o {
|
||||
for i, x := range cs.overflow {
|
||||
println("overflow[", i, "]:", x.Key)
|
||||
}
|
||||
println()
|
||||
|
||||
o = o.setOverflowEntry(SectionalNeedleValue{Key: 4, Offset: 44, Size: 44})
|
||||
for i, x := range o {
|
||||
cs.setOverflowEntry(4, ToOffset(44), 44)
|
||||
for i, x := range cs.overflow {
|
||||
println("overflow[", i, "]:", x.Key)
|
||||
}
|
||||
println()
|
||||
|
||||
o = o.setOverflowEntry(SectionalNeedleValue{Key: 1, Offset: 11, Size: 11})
|
||||
cs.setOverflowEntry(1, ToOffset(11), 11)
|
||||
|
||||
for i, x := range o {
|
||||
for i, x := range cs.overflow {
|
||||
println("overflow[", i, "]:", x.Key)
|
||||
}
|
||||
println()
|
||||
|
||||
@@ -68,7 +68,7 @@ func generateBoltDbFile(dbFileName string, indexFile *os.File) error {
|
||||
}
|
||||
defer db.Close()
|
||||
return WalkIndexFile(indexFile, func(key NeedleId, offset Offset, size uint32) error {
|
||||
if offset > 0 && size != TombstoneFileSize {
|
||||
if !offset.IsZero() && size != TombstoneFileSize {
|
||||
boltDbWrite(db, key, offset, size)
|
||||
} else {
|
||||
boltDbDelete(db, key)
|
||||
|
||||
@@ -63,7 +63,7 @@ func generateLevelDbFile(dbFileName string, indexFile *os.File) error {
|
||||
}
|
||||
defer db.Close()
|
||||
return WalkIndexFile(indexFile, func(key NeedleId, offset Offset, size uint32) error {
|
||||
if offset > 0 && size != TombstoneFileSize {
|
||||
if !offset.IsZero() && size != TombstoneFileSize {
|
||||
levelDbWrite(db, key, offset, size)
|
||||
} else {
|
||||
levelDbDelete(db, key)
|
||||
|
||||
@@ -50,12 +50,12 @@ func doLoading(file *os.File, nm *NeedleMap) (*NeedleMap, error) {
|
||||
if key > nm.MaximumFileKey {
|
||||
nm.MaximumFileKey = key
|
||||
}
|
||||
if offset > 0 && size != TombstoneFileSize {
|
||||
if !offset.IsZero() && size != TombstoneFileSize {
|
||||
nm.FileCounter++
|
||||
nm.FileByteCounter = nm.FileByteCounter + uint64(size)
|
||||
oldOffset, oldSize := nm.m.Set(NeedleId(key), offset, size)
|
||||
// glog.V(3).Infoln("reading key", key, "offset", offset*NeedlePaddingSize, "size", size, "oldSize", oldSize)
|
||||
if oldOffset > 0 && oldSize != TombstoneFileSize {
|
||||
if !oldOffset.IsZero() && oldSize != TombstoneFileSize {
|
||||
nm.DeletionCounter++
|
||||
nm.DeletionByteCounter = nm.DeletionByteCounter + uint64(oldSize)
|
||||
}
|
||||
|
||||
@@ -88,10 +88,12 @@ func parseMultipart(r *http.Request) (
|
||||
}
|
||||
isGzipped = true
|
||||
} else if operation.IsGzippable(ext, mtype, data) {
|
||||
if data, e = operation.GzipData(data); e != nil {
|
||||
return
|
||||
if compressedData, err := operation.GzipData(data); err == nil {
|
||||
if len(data) > len(compressedData) {
|
||||
data = compressedData
|
||||
isGzipped = true
|
||||
}
|
||||
}
|
||||
isGzipped = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,25 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Offset uint32
|
||||
type Offset struct {
|
||||
OffsetHigher
|
||||
OffsetLower
|
||||
}
|
||||
|
||||
type OffsetLower struct {
|
||||
b3 byte
|
||||
b2 byte
|
||||
b1 byte
|
||||
b0 byte // the smaller byte
|
||||
}
|
||||
|
||||
type Cookie uint32
|
||||
|
||||
const (
|
||||
OffsetSize = 4
|
||||
SizeSize = 4 // uint32 size
|
||||
NeedleEntrySize = NeedleIdSize + OffsetSize + SizeSize
|
||||
NeedleEntrySize = CookieSize + NeedleIdSize + SizeSize
|
||||
TimestampSize = 8 // int64 size
|
||||
NeedlePaddingSize = 8
|
||||
MaxPossibleVolumeSize = 4 * 1024 * 1024 * 1024 * 8
|
||||
TombstoneFileSize = math.MaxUint32
|
||||
CookieSize = 4
|
||||
)
|
||||
@@ -39,15 +48,3 @@ func ParseCookie(cookieString string) (Cookie, error) {
|
||||
}
|
||||
return Cookie(cookie), nil
|
||||
}
|
||||
|
||||
func OffsetToBytes(bytes []byte, offset Offset) {
|
||||
util.Uint32toBytes(bytes, uint32(offset))
|
||||
}
|
||||
|
||||
func Uint32ToOffset(offset uint32) Offset {
|
||||
return Offset(offset)
|
||||
}
|
||||
|
||||
func BytesToOffset(bytes []byte) Offset {
|
||||
return Offset(util.BytesToUint32(bytes[0:4]))
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// +build !5BytesOffset
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type OffsetHigher struct {
|
||||
// b4 byte
|
||||
}
|
||||
|
||||
const (
|
||||
OffsetSize = 4
|
||||
MaxPossibleVolumeSize = 4 * 1024 * 1024 * 1024 * 8 // 32GB
|
||||
)
|
||||
|
||||
func OffsetToBytes(bytes []byte, offset Offset) {
|
||||
bytes[3] = offset.b0
|
||||
bytes[2] = offset.b1
|
||||
bytes[1] = offset.b2
|
||||
bytes[0] = offset.b3
|
||||
}
|
||||
|
||||
// only for testing, will be removed later.
|
||||
func Uint32ToOffset(offset uint32) Offset {
|
||||
return Offset{
|
||||
OffsetLower: OffsetLower{
|
||||
b0: byte(offset),
|
||||
b1: byte(offset >> 8),
|
||||
b2: byte(offset >> 16),
|
||||
b3: byte(offset >> 24),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func BytesToOffset(bytes []byte) Offset {
|
||||
return Offset{
|
||||
OffsetLower: OffsetLower{
|
||||
b0: bytes[3],
|
||||
b1: bytes[2],
|
||||
b2: bytes[1],
|
||||
b3: bytes[0],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (offset Offset) IsZero() bool {
|
||||
return offset.b0 == 0 && offset.b1 == 0 && offset.b2 == 0 && offset.b3 == 0
|
||||
}
|
||||
|
||||
func ToOffset(offset int64) Offset {
|
||||
smaller := uint32(offset / int64(NeedlePaddingSize))
|
||||
return Uint32ToOffset(smaller)
|
||||
}
|
||||
|
||||
func (offset Offset) ToAcutalOffset() (actualOffset int64) {
|
||||
return (int64(offset.b0) + int64(offset.b1)<<8 + int64(offset.b2)<<16 + int64(offset.b3)<<24) * int64(NeedlePaddingSize)
|
||||
}
|
||||
|
||||
func (offset Offset) String() string {
|
||||
return fmt.Sprintf("%d", int64(offset.b0)+int64(offset.b1)<<8+int64(offset.b2)<<16+int64(offset.b3)<<24)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// +build 5BytesOffset
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type OffsetHigher struct {
|
||||
b4 byte
|
||||
}
|
||||
|
||||
const (
|
||||
OffsetSize = 4 + 1
|
||||
MaxPossibleVolumeSize = 4 * 1024 * 1024 * 1024 * 8 * 256 /* 256 is from the extra byte */ // 8TB
|
||||
)
|
||||
|
||||
func OffsetToBytes(bytes []byte, offset Offset) {
|
||||
bytes[4] = offset.b4
|
||||
bytes[3] = offset.b0
|
||||
bytes[2] = offset.b1
|
||||
bytes[1] = offset.b2
|
||||
bytes[0] = offset.b3
|
||||
}
|
||||
|
||||
// only for testing, will be removed later.
|
||||
func Uint32ToOffset(offset uint32) Offset {
|
||||
return Offset{
|
||||
OffsetHigher: OffsetHigher{
|
||||
b4: byte(offset >> 32),
|
||||
},
|
||||
OffsetLower: OffsetLower{
|
||||
b0: byte(offset),
|
||||
b1: byte(offset >> 8),
|
||||
b2: byte(offset >> 16),
|
||||
b3: byte(offset >> 24),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func BytesToOffset(bytes []byte) Offset {
|
||||
return Offset{
|
||||
OffsetHigher: OffsetHigher{
|
||||
b4: bytes[4],
|
||||
},
|
||||
OffsetLower: OffsetLower{
|
||||
b0: bytes[3],
|
||||
b1: bytes[2],
|
||||
b2: bytes[1],
|
||||
b3: bytes[0],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (offset Offset) IsZero() bool {
|
||||
return offset.b0 == 0 && offset.b1 == 0 && offset.b2 == 0 && offset.b3 == 0 && offset.b4 == 0
|
||||
}
|
||||
|
||||
func ToOffset(offset int64) Offset {
|
||||
smaller := offset / int64(NeedlePaddingSize)
|
||||
return Offset{
|
||||
OffsetHigher: OffsetHigher{
|
||||
b4: byte(smaller >> 32),
|
||||
},
|
||||
OffsetLower: OffsetLower{
|
||||
b0: byte(smaller),
|
||||
b1: byte(smaller >> 8),
|
||||
b2: byte(smaller >> 16),
|
||||
b3: byte(smaller >> 24),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (offset Offset) ToAcutalOffset() (actualOffset int64) {
|
||||
return (int64(offset.b0) + int64(offset.b1)<<8 + int64(offset.b2)<<16 + int64(offset.b3)<<24 + int64(offset.b4)<<32) * int64(NeedlePaddingSize)
|
||||
}
|
||||
|
||||
func (offset Offset) String() string {
|
||||
return fmt.Sprintf("%d", int64(offset.b0)+int64(offset.b1)<<8+int64(offset.b2)<<16+int64(offset.b3)<<24+int64(offset.b4)<<32)
|
||||
}
|
||||
@@ -26,10 +26,10 @@ func CheckVolumeDataIntegrity(v *Volume, indexFile *os.File) error {
|
||||
return fmt.Errorf("readLastIndexEntry %s failed: %v", indexFile.Name(), e)
|
||||
}
|
||||
key, offset, size := IdxFileEntry(lastIdxEntry)
|
||||
if offset == 0 || size == TombstoneFileSize {
|
||||
if offset.IsZero() || size == TombstoneFileSize {
|
||||
return nil
|
||||
}
|
||||
if e = verifyNeedleIntegrity(v.dataFile, v.Version(), int64(offset)*NeedlePaddingSize, key, size); e != nil {
|
||||
if e = verifyNeedleIntegrity(v.dataFile, v.Version(), offset.ToAcutalOffset(), key, size); e != nil {
|
||||
return fmt.Errorf("verifyNeedleIntegrity %s failed: %v", indexFile.Name(), e)
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ func (v *Volume) findLastAppendAtNs() (uint64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if offset == 0 {
|
||||
if offset.IsZero() {
|
||||
return 0, nil
|
||||
}
|
||||
return v.readAppendAtNs(offset)
|
||||
@@ -119,26 +119,26 @@ func (v *Volume) findLastAppendAtNs() (uint64, error) {
|
||||
func (v *Volume) locateLastAppendEntry() (Offset, error) {
|
||||
indexFile, e := os.OpenFile(v.FileName()+".idx", os.O_RDONLY, 0644)
|
||||
if e != nil {
|
||||
return 0, fmt.Errorf("cannot read %s.idx: %v", v.FileName(), e)
|
||||
return Offset{}, fmt.Errorf("cannot read %s.idx: %v", v.FileName(), e)
|
||||
}
|
||||
defer indexFile.Close()
|
||||
|
||||
fi, err := indexFile.Stat()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("file %s stat error: %v", indexFile.Name(), err)
|
||||
return Offset{}, fmt.Errorf("file %s stat error: %v", indexFile.Name(), err)
|
||||
}
|
||||
fileSize := fi.Size()
|
||||
if fileSize%NeedleEntrySize != 0 {
|
||||
return 0, fmt.Errorf("unexpected file %s size: %d", indexFile.Name(), fileSize)
|
||||
return Offset{}, fmt.Errorf("unexpected file %s size: %d", indexFile.Name(), fileSize)
|
||||
}
|
||||
if fileSize == 0 {
|
||||
return 0, nil
|
||||
return Offset{}, nil
|
||||
}
|
||||
|
||||
bytes := make([]byte, NeedleEntrySize)
|
||||
n, e := indexFile.ReadAt(bytes, fileSize-NeedleEntrySize)
|
||||
if n != NeedleEntrySize {
|
||||
return 0, fmt.Errorf("file %s read error: %v", indexFile.Name(), e)
|
||||
return Offset{}, fmt.Errorf("file %s read error: %v", indexFile.Name(), e)
|
||||
}
|
||||
_, offset, _ := IdxFileEntry(bytes)
|
||||
|
||||
@@ -147,13 +147,13 @@ func (v *Volume) locateLastAppendEntry() (Offset, error) {
|
||||
|
||||
func (v *Volume) readAppendAtNs(offset Offset) (uint64, error) {
|
||||
|
||||
n, bodyLength, err := ReadNeedleHeader(v.dataFile, v.SuperBlock.version, int64(offset)*NeedlePaddingSize)
|
||||
n, bodyLength, err := ReadNeedleHeader(v.dataFile, v.SuperBlock.version, offset.ToAcutalOffset())
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ReadNeedleHeader: %v", err)
|
||||
}
|
||||
err = n.ReadNeedleBody(v.dataFile, v.SuperBlock.version, int64(offset)*NeedlePaddingSize+int64(NeedleEntrySize), bodyLength)
|
||||
err = n.ReadNeedleBody(v.dataFile, v.SuperBlock.version, offset.ToAcutalOffset()+int64(NeedleEntrySize), bodyLength)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ReadNeedleBody offset %d, bodyLength %d: %v", int64(offset)*NeedlePaddingSize, bodyLength, err)
|
||||
return 0, fmt.Errorf("ReadNeedleBody offset %d, bodyLength %d: %v", offset.ToAcutalOffset(), bodyLength, err)
|
||||
}
|
||||
return n.AppendAtNs, nil
|
||||
|
||||
@@ -189,7 +189,7 @@ func (v *Volume) BinarySearchByAppendAtNs(sinceNs uint64) (offset Offset, isLast
|
||||
m := (l + h) / 2
|
||||
|
||||
if m == entryCount {
|
||||
return 0, true, nil
|
||||
return Offset{}, true, nil
|
||||
}
|
||||
|
||||
// read the appendAtNs for entry m
|
||||
@@ -214,7 +214,7 @@ func (v *Volume) BinarySearchByAppendAtNs(sinceNs uint64) (offset Offset, isLast
|
||||
}
|
||||
|
||||
if l == entryCount {
|
||||
return 0, true, nil
|
||||
return Offset{}, true, nil
|
||||
}
|
||||
|
||||
offset, err = v.readAppendAtNsForIndexEntry(indexFile, bytes, l)
|
||||
@@ -226,7 +226,7 @@ func (v *Volume) BinarySearchByAppendAtNs(sinceNs uint64) (offset Offset, isLast
|
||||
// bytes is of size NeedleEntrySize
|
||||
func (v *Volume) readAppendAtNsForIndexEntry(indexFile *os.File, bytes []byte, m int64) (Offset, error) {
|
||||
if _, readErr := indexFile.ReadAt(bytes, m*NeedleEntrySize); readErr != nil && readErr != io.EOF {
|
||||
return 0, readErr
|
||||
return Offset{}, readErr
|
||||
}
|
||||
_, offset, _ := IdxFileEntry(bytes)
|
||||
return offset, nil
|
||||
@@ -247,7 +247,7 @@ func (scanner *VolumeFileScanner4GenIdx) ReadNeedleBody() bool {
|
||||
|
||||
func (scanner *VolumeFileScanner4GenIdx) VisitNeedle(n *Needle, offset int64) error {
|
||||
if n.Size > 0 && n.Size != TombstoneFileSize {
|
||||
return scanner.v.nm.Put(n.Id, Offset(offset/NeedlePaddingSize), n.Size)
|
||||
return scanner.v.nm.Put(n.Id, ToOffset(offset), n.Size)
|
||||
}
|
||||
return scanner.v.nm.Delete(n.Id, Offset(offset/NeedlePaddingSize))
|
||||
return scanner.v.nm.Delete(n.Id, ToOffset(offset))
|
||||
}
|
||||
@@ -21,9 +21,9 @@ func (v *Volume) isFileUnchanged(n *Needle) bool {
|
||||
return false
|
||||
}
|
||||
nv, ok := v.nm.Get(n.Id)
|
||||
if ok && nv.Offset > 0 {
|
||||
if ok && !nv.Offset.IsZero() {
|
||||
oldNeedle := new(Needle)
|
||||
err := oldNeedle.ReadData(v.dataFile, int64(nv.Offset)*NeedlePaddingSize, nv.Size, v.Version())
|
||||
err := oldNeedle.ReadData(v.dataFile, nv.Offset.ToAcutalOffset(), nv.Size, v.Version())
|
||||
if err != nil {
|
||||
glog.V(0).Infof("Failed to check updated file %v", err)
|
||||
return false
|
||||
@@ -96,8 +96,8 @@ func (v *Volume) writeNeedle(n *Needle) (offset uint64, size uint32, err error)
|
||||
}
|
||||
|
||||
nv, ok := v.nm.Get(n.Id)
|
||||
if !ok || uint64(nv.Offset)*NeedlePaddingSize < offset {
|
||||
if err = v.nm.Put(n.Id, Offset(offset/NeedlePaddingSize), n.Size); err != nil {
|
||||
if !ok || uint64(nv.Offset.ToAcutalOffset()) < offset {
|
||||
if err = v.nm.Put(n.Id, ToOffset(int64(offset)), n.Size); err != nil {
|
||||
glog.V(4).Infof("failed to save in needle map %d: %v", n.Id, err)
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (v *Volume) deleteNeedle(n *Needle) (uint32, error) {
|
||||
if err != nil {
|
||||
return size, err
|
||||
}
|
||||
if err = v.nm.Delete(n.Id, Offset(offset/NeedlePaddingSize)); err != nil {
|
||||
if err = v.nm.Delete(n.Id, ToOffset(int64(offset))); err != nil {
|
||||
return size, err
|
||||
}
|
||||
return size, err
|
||||
@@ -135,10 +135,10 @@ func (v *Volume) deleteNeedle(n *Needle) (uint32, error) {
|
||||
// read fills in Needle content by looking up n.Id from NeedleMapper
|
||||
func (v *Volume) readNeedle(n *Needle) (int, error) {
|
||||
nv, ok := v.nm.Get(n.Id)
|
||||
if !ok || nv.Offset == 0 {
|
||||
if !ok || nv.Offset.IsZero() {
|
||||
v.compactingWg.Wait()
|
||||
nv, ok = v.nm.Get(n.Id)
|
||||
if !ok || nv.Offset == 0 {
|
||||
if !ok || nv.Offset.IsZero() {
|
||||
return -1, ErrorNotFound
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (v *Volume) readNeedle(n *Needle) (int, error) {
|
||||
if nv.Size == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
err := n.ReadData(v.dataFile, int64(nv.Offset)*NeedlePaddingSize, nv.Size, v.Version())
|
||||
err := n.ReadData(v.dataFile, nv.Offset.ToAcutalOffset(), nv.Size, v.Version())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -201,13 +201,13 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI
|
||||
}
|
||||
|
||||
//updated needle
|
||||
if increIdxEntry.offset != 0 && increIdxEntry.size != 0 && increIdxEntry.size != TombstoneFileSize {
|
||||
if !increIdxEntry.offset.IsZero() && increIdxEntry.size != 0 && increIdxEntry.size != TombstoneFileSize {
|
||||
//even the needle cache in memory is hit, the need_bytes is correct
|
||||
glog.V(4).Infof("file %d offset %d size %d", key, int64(increIdxEntry.offset)*NeedlePaddingSize, increIdxEntry.size)
|
||||
glog.V(4).Infof("file %d offset %d size %d", key, increIdxEntry.offset.ToAcutalOffset(), increIdxEntry.size)
|
||||
var needleBytes []byte
|
||||
needleBytes, err = ReadNeedleBlob(oldDatFile, int64(increIdxEntry.offset)*NeedlePaddingSize, increIdxEntry.size, v.Version())
|
||||
needleBytes, err = ReadNeedleBlob(oldDatFile, increIdxEntry.offset.ToAcutalOffset(), increIdxEntry.size, v.Version())
|
||||
if err != nil {
|
||||
return fmt.Errorf("ReadNeedleBlob %s key %d offset %d size %d failed: %v", oldDatFile.Name(), key, int64(increIdxEntry.offset)*NeedlePaddingSize, increIdxEntry.size, err)
|
||||
return fmt.Errorf("ReadNeedleBlob %s key %d offset %d size %d failed: %v", oldDatFile.Name(), key, increIdxEntry.offset.ToAcutalOffset(), increIdxEntry.size, err)
|
||||
}
|
||||
dst.Write(needleBytes)
|
||||
util.Uint32toBytes(idxEntryBytes[8:12], uint32(offset/NeedlePaddingSize))
|
||||
@@ -261,8 +261,8 @@ func (scanner *VolumeFileScanner4Vacuum) VisitNeedle(n *Needle, offset int64) er
|
||||
}
|
||||
nv, ok := scanner.v.nm.Get(n.Id)
|
||||
glog.V(4).Infoln("needle expected offset ", offset, "ok", ok, "nv", nv)
|
||||
if ok && int64(nv.Offset)*NeedlePaddingSize == offset && nv.Size > 0 && nv.Size != TombstoneFileSize {
|
||||
if err := scanner.nm.Put(n.Id, Offset(scanner.newOffset/NeedlePaddingSize), n.Size); err != nil {
|
||||
if ok && nv.Offset.ToAcutalOffset() == offset && nv.Size > 0 && nv.Size != TombstoneFileSize {
|
||||
if err := scanner.nm.Put(n.Id, ToOffset(scanner.newOffset), n.Size); err != nil {
|
||||
return fmt.Errorf("cannot put needle: %s", err)
|
||||
}
|
||||
if _, _, _, err := n.Append(scanner.dst, scanner.v.Version()); err != nil {
|
||||
@@ -325,7 +325,7 @@ func (v *Volume) copyDataBasedOnIndexFile(dstName, idxName string) (err error) {
|
||||
newOffset := int64(v.SuperBlock.BlockSize())
|
||||
|
||||
WalkIndexFile(oldIndexFile, func(key NeedleId, offset Offset, size uint32) error {
|
||||
if offset == 0 || size == TombstoneFileSize {
|
||||
if offset.IsZero() || size == TombstoneFileSize {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ func (v *Volume) copyDataBasedOnIndexFile(dstName, idxName string) (err error) {
|
||||
}
|
||||
|
||||
n := new(Needle)
|
||||
err := n.ReadData(v.dataFile, int64(offset)*NeedlePaddingSize, size, v.Version())
|
||||
err := n.ReadData(v.dataFile, offset.ToAcutalOffset(), size, v.Version())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -346,7 +346,7 @@ func (v *Volume) copyDataBasedOnIndexFile(dstName, idxName string) (err error) {
|
||||
|
||||
glog.V(4).Infoln("needle expected offset ", offset, "ok", ok, "nv", nv)
|
||||
if nv.Offset == offset && nv.Size > 0 {
|
||||
if err = nm.Put(n.Id, Offset(newOffset/NeedlePaddingSize), n.Size); err != nil {
|
||||
if err = nm.Put(n.Id, ToOffset(newOffset), n.Size); err != nil {
|
||||
return fmt.Errorf("cannot put needle: %s", err)
|
||||
}
|
||||
if _, _, _, err = n.Append(dst, v.Version()); err != nil {
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/storage"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
)
|
||||
|
||||
var (
|
||||
indexFileName = flag.String("file", "", ".idx file to analyze")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
indexFile, err := os.OpenFile(*indexFileName, os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("Create Volume Index [ERROR] %s\n", err)
|
||||
}
|
||||
defer indexFile.Close()
|
||||
|
||||
storage.WalkIndexFile(indexFile, func(key types.NeedleId, offset types.Offset, size uint32) error {
|
||||
fmt.Printf("key %d, offset %d, size %d, nextOffset %d\n", key, offset*8, size, int64(offset)*types.NeedlePaddingSize+int64(size))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
+23
-22
@@ -5,6 +5,7 @@ import (
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage"
|
||||
@@ -14,16 +15,16 @@ type NodeId string
|
||||
type Node interface {
|
||||
Id() NodeId
|
||||
String() string
|
||||
FreeSpace() int
|
||||
ReserveOneVolume(r int) (*DataNode, error)
|
||||
UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int)
|
||||
UpAdjustVolumeCountDelta(volumeCountDelta int)
|
||||
UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int)
|
||||
FreeSpace() int64
|
||||
ReserveOneVolume(r int64) (*DataNode, error)
|
||||
UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int64)
|
||||
UpAdjustVolumeCountDelta(volumeCountDelta int64)
|
||||
UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int64)
|
||||
UpAdjustMaxVolumeId(vid storage.VolumeId)
|
||||
|
||||
GetVolumeCount() int
|
||||
GetActiveVolumeCount() int
|
||||
GetMaxVolumeCount() int
|
||||
GetVolumeCount() int64
|
||||
GetActiveVolumeCount() int64
|
||||
GetMaxVolumeCount() int64
|
||||
GetMaxVolumeId() storage.VolumeId
|
||||
SetParent(Node)
|
||||
LinkChildNode(node Node)
|
||||
@@ -40,9 +41,9 @@ type Node interface {
|
||||
}
|
||||
type NodeImpl struct {
|
||||
id NodeId
|
||||
volumeCount int
|
||||
activeVolumeCount int
|
||||
maxVolumeCount int
|
||||
volumeCount int64
|
||||
activeVolumeCount int64
|
||||
maxVolumeCount int64
|
||||
parent Node
|
||||
sync.RWMutex // lock children
|
||||
children map[NodeId]Node
|
||||
@@ -126,7 +127,7 @@ func (n *NodeImpl) String() string {
|
||||
func (n *NodeImpl) Id() NodeId {
|
||||
return n.id
|
||||
}
|
||||
func (n *NodeImpl) FreeSpace() int {
|
||||
func (n *NodeImpl) FreeSpace() int64 {
|
||||
return n.maxVolumeCount - n.volumeCount
|
||||
}
|
||||
func (n *NodeImpl) SetParent(node Node) {
|
||||
@@ -146,7 +147,7 @@ func (n *NodeImpl) Parent() Node {
|
||||
func (n *NodeImpl) GetValue() interface{} {
|
||||
return n.value
|
||||
}
|
||||
func (n *NodeImpl) ReserveOneVolume(r int) (assignedNode *DataNode, err error) {
|
||||
func (n *NodeImpl) ReserveOneVolume(r int64) (assignedNode *DataNode, err error) {
|
||||
n.RLock()
|
||||
defer n.RUnlock()
|
||||
for _, node := range n.children {
|
||||
@@ -171,20 +172,20 @@ func (n *NodeImpl) ReserveOneVolume(r int) (assignedNode *DataNode, err error) {
|
||||
return nil, errors.New("No free volume slot found!")
|
||||
}
|
||||
|
||||
func (n *NodeImpl) UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int) { //can be negative
|
||||
n.maxVolumeCount += maxVolumeCountDelta
|
||||
func (n *NodeImpl) UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int64) { //can be negative
|
||||
atomic.AddInt64(&n.maxVolumeCount, maxVolumeCountDelta)
|
||||
if n.parent != nil {
|
||||
n.parent.UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta)
|
||||
}
|
||||
}
|
||||
func (n *NodeImpl) UpAdjustVolumeCountDelta(volumeCountDelta int) { //can be negative
|
||||
n.volumeCount += volumeCountDelta
|
||||
func (n *NodeImpl) UpAdjustVolumeCountDelta(volumeCountDelta int64) { //can be negative
|
||||
atomic.AddInt64(&n.volumeCount, volumeCountDelta)
|
||||
if n.parent != nil {
|
||||
n.parent.UpAdjustVolumeCountDelta(volumeCountDelta)
|
||||
}
|
||||
}
|
||||
func (n *NodeImpl) UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int) { //can be negative
|
||||
n.activeVolumeCount += activeVolumeCountDelta
|
||||
func (n *NodeImpl) UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int64) { //can be negative
|
||||
atomic.AddInt64(&n.activeVolumeCount, activeVolumeCountDelta)
|
||||
if n.parent != nil {
|
||||
n.parent.UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta)
|
||||
}
|
||||
@@ -200,13 +201,13 @@ func (n *NodeImpl) UpAdjustMaxVolumeId(vid storage.VolumeId) { //can be negative
|
||||
func (n *NodeImpl) GetMaxVolumeId() storage.VolumeId {
|
||||
return n.maxVolumeId
|
||||
}
|
||||
func (n *NodeImpl) GetVolumeCount() int {
|
||||
func (n *NodeImpl) GetVolumeCount() int64 {
|
||||
return n.volumeCount
|
||||
}
|
||||
func (n *NodeImpl) GetActiveVolumeCount() int {
|
||||
func (n *NodeImpl) GetActiveVolumeCount() int64 {
|
||||
return n.activeVolumeCount
|
||||
}
|
||||
func (n *NodeImpl) GetMaxVolumeCount() int {
|
||||
func (n *NodeImpl) GetMaxVolumeCount() int64 {
|
||||
return n.maxVolumeCount
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ func (r *Rack) FindDataNode(ip string, port int) *DataNode {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVolumeCount int) *DataNode {
|
||||
func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVolumeCount int64) *DataNode {
|
||||
for _, c := range r.Children() {
|
||||
dn := c.(*DataNode)
|
||||
if dn.MatchLocation(ip, port) {
|
||||
|
||||
@@ -47,8 +47,8 @@ func TestHandlingVolumeServerHeartbeat(t *testing.T) {
|
||||
|
||||
topo.SyncDataNodeRegistration(volumeMessages, dn)
|
||||
|
||||
assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
|
||||
assert(t, "volumeCount", topo.volumeCount, volumeCount)
|
||||
assert(t, "activeVolumeCount1", int(topo.activeVolumeCount), volumeCount)
|
||||
assert(t, "volumeCount", int(topo.volumeCount), volumeCount)
|
||||
}
|
||||
|
||||
{
|
||||
@@ -71,13 +71,13 @@ func TestHandlingVolumeServerHeartbeat(t *testing.T) {
|
||||
}
|
||||
topo.SyncDataNodeRegistration(volumeMessages, dn)
|
||||
|
||||
assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
|
||||
assert(t, "volumeCount", topo.volumeCount, volumeCount)
|
||||
assert(t, "activeVolumeCount1", int(topo.activeVolumeCount), volumeCount)
|
||||
assert(t, "volumeCount", int(topo.volumeCount), volumeCount)
|
||||
}
|
||||
|
||||
topo.UnRegisterDataNode(dn)
|
||||
|
||||
assert(t, "activeVolumeCount2", topo.activeVolumeCount, 0)
|
||||
assert(t, "activeVolumeCount2", int(topo.activeVolumeCount), 0)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ func (vg *VolumeGrowth) findEmptySlotsForOneVolume(topo *Topology, option *Volum
|
||||
if len(node.Children()) < rp.DiffRackCount+1 {
|
||||
return fmt.Errorf("Only has %d racks, not enough for %d.", len(node.Children()), rp.DiffRackCount+1)
|
||||
}
|
||||
if node.FreeSpace() < rp.DiffRackCount+rp.SameRackCount+1 {
|
||||
if node.FreeSpace() < int64(rp.DiffRackCount+rp.SameRackCount+1) {
|
||||
return fmt.Errorf("Free:%d < Expected:%d", node.FreeSpace(), rp.DiffRackCount+rp.SameRackCount+1)
|
||||
}
|
||||
possibleRacksCount := 0
|
||||
@@ -134,7 +134,7 @@ func (vg *VolumeGrowth) findEmptySlotsForOneVolume(topo *Topology, option *Volum
|
||||
if option.Rack != "" && node.IsRack() && node.Id() != NodeId(option.Rack) {
|
||||
return fmt.Errorf("Not matching preferred rack:%s", option.Rack)
|
||||
}
|
||||
if node.FreeSpace() < rp.SameRackCount+1 {
|
||||
if node.FreeSpace() < int64(rp.SameRackCount+1) {
|
||||
return fmt.Errorf("Free:%d < Expected:%d", node.FreeSpace(), rp.SameRackCount+1)
|
||||
}
|
||||
if len(node.Children()) < rp.SameRackCount+1 {
|
||||
@@ -175,7 +175,7 @@ func (vg *VolumeGrowth) findEmptySlotsForOneVolume(topo *Topology, option *Volum
|
||||
servers = append(servers, server.(*DataNode))
|
||||
}
|
||||
for _, rack := range otherRacks {
|
||||
r := rand.Intn(rack.FreeSpace())
|
||||
r := rand.Int63n(rack.FreeSpace())
|
||||
if server, e := rack.ReserveOneVolume(r); e == nil {
|
||||
servers = append(servers, server)
|
||||
} else {
|
||||
@@ -183,7 +183,7 @@ func (vg *VolumeGrowth) findEmptySlotsForOneVolume(topo *Topology, option *Volum
|
||||
}
|
||||
}
|
||||
for _, datacenter := range otherDataCenters {
|
||||
r := rand.Intn(datacenter.FreeSpace())
|
||||
r := rand.Int63n(datacenter.FreeSpace())
|
||||
if server, e := datacenter.ReserveOneVolume(r); e == nil {
|
||||
servers = append(servers, server)
|
||||
} else {
|
||||
|
||||
@@ -101,7 +101,7 @@ func setup(topologyLayout string) *Topology {
|
||||
Version: storage.CurrentVersion}
|
||||
server.AddOrUpdateVolume(vi)
|
||||
}
|
||||
server.UpAdjustMaxVolumeCountDelta(int(serverMap["limit"].(float64)))
|
||||
server.UpAdjustMaxVolumeCountDelta(int64(serverMap["limit"].(float64)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package util
|
||||
|
||||
const (
|
||||
VERSION = "1.28"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
VERSION = fmt.Sprintf("%s %d.%d", sizeLimit, 1, 29)
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
// +build !5BytesOffset
|
||||
|
||||
package util
|
||||
|
||||
const (
|
||||
sizeLimit = "30GB"
|
||||
VolumeSizeLimitGB = 30
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
// +build 5BytesOffset
|
||||
|
||||
package util
|
||||
|
||||
const (
|
||||
sizeLimit = "8000GB"
|
||||
VolumeSizeLimitGB = 8000
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
// +build linux darwin freebsd netbsd openbsd plan9 solaris zos
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func GetFileUidGid(fi os.FileInfo) (uid, gid uint32) {
|
||||
return fi.Sys().(*syscall.Stat_t).Uid, fi.Sys().(*syscall.Stat_t).Gid
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// +build windows
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func GetFileUidGid(fi os.FileInfo) (uid, gid uint32) {
|
||||
return 0, 0
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package util
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -18,6 +19,10 @@ var (
|
||||
grpcClientsLock sync.Mutex
|
||||
)
|
||||
|
||||
func init(){
|
||||
http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = 100
|
||||
}
|
||||
|
||||
func NewGrpcServer(opts ...grpc.ServerOption) *grpc.Server {
|
||||
var options []grpc.ServerOption
|
||||
options = append(options, grpc.KeepaliveParams(keepalive.ServerParameters{
|
||||
|
||||
@@ -106,15 +106,11 @@ func withMasterClient(ctx context.Context, master string, grpcDialOption grpc.Di
|
||||
return fmt.Errorf("failed to parse master grpc %v", master)
|
||||
}
|
||||
|
||||
grpcConnection, err := util.GrpcDial(ctx, masterGrpcAddress, grpcDialOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to dial %s: %v", master, err)
|
||||
}
|
||||
defer grpcConnection.Close()
|
||||
return util.WithCachedGrpcClient(ctx, func(grpcConnection *grpc.ClientConn) error {
|
||||
client := master_pb.NewSeaweedClient(grpcConnection)
|
||||
return fn(ctx, client)
|
||||
}, masterGrpcAddress, grpcDialOption)
|
||||
|
||||
client := master_pb.NewSeaweedClient(grpcConnection)
|
||||
|
||||
return fn(ctx, client)
|
||||
}
|
||||
|
||||
func (mc *MasterClient) WithClient(ctx context.Context, fn func(client master_pb.SeaweedClient) error) error {
|
||||
|
||||
Reference in new issue
Block a user