2018-05-08 16:59:43 +08:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-05-28 02:52:26 +08:00
|
|
|
"fmt"
|
2018-05-27 14:59:56 +08:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2018-11-23 16:24:51 +08:00
|
|
|
"strconv"
|
2018-05-28 02:52:26 +08:00
|
|
|
"time"
|
2018-05-27 14:59:56 +08:00
|
|
|
|
2023-07-17 22:52:14 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2018-05-08 16:59:43 +08:00
|
|
|
)
|
|
|
|
|
2018-05-10 14:18:02 +08:00
|
|
|
func (fs *FilerServer) LookupDirectoryEntry(ctx context.Context, req *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) {
|
2018-05-08 16:59:43 +08:00
|
|
|
|
2020-04-26 20:21:54 +08:00
|
|
|
glog.V(4).Infof("LookupDirectoryEntry %s", filepath.Join(req.Directory, req.Name))
|
|
|
|
|
2020-04-06 04:11:43 +08:00
|
|
|
entry, err := fs.filer.FindEntry(ctx, util.JoinPath(req.Directory, req.Name))
|
2020-03-08 09:01:39 +08:00
|
|
|
if err == filer_pb.ErrNotFound {
|
2020-04-26 20:21:54 +08:00
|
|
|
return &filer_pb.LookupDirectoryEntryResponse{}, err
|
2020-01-25 10:07:34 +08:00
|
|
|
}
|
2018-05-08 16:59:43 +08:00
|
|
|
if err != nil {
|
2020-01-25 09:26:03 +08:00
|
|
|
glog.V(3).Infof("LookupDirectoryEntry %s: %+v, ", filepath.Join(req.Directory, req.Name), err)
|
2019-09-02 12:40:26 +08:00
|
|
|
return nil, err
|
2018-05-08 16:59:43 +08:00
|
|
|
}
|
|
|
|
|
2018-05-10 14:18:02 +08:00
|
|
|
return &filer_pb.LookupDirectoryEntryResponse{
|
2021-07-19 17:47:27 +08:00
|
|
|
Entry: entry.ToProtoEntry(),
|
2018-05-08 16:59:43 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-16 15:56:24 +08:00
|
|
|
func (fs *FilerServer) ListEntries(req *filer_pb.ListEntriesRequest, stream filer_pb.SeaweedFiler_ListEntriesServer) (err error) {
|
2018-05-08 16:59:43 +08:00
|
|
|
|
2020-04-26 20:21:54 +08:00
|
|
|
glog.V(4).Infof("ListEntries %v", req)
|
|
|
|
|
2018-07-22 16:14:36 +08:00
|
|
|
limit := int(req.Limit)
|
|
|
|
if limit == 0 {
|
|
|
|
limit = fs.option.DirListingLimit
|
2018-05-08 16:59:43 +08:00
|
|
|
}
|
|
|
|
|
2020-09-01 15:21:19 +08:00
|
|
|
paginationLimit := filer.PaginationSize
|
2019-11-22 17:39:50 +08:00
|
|
|
if limit < paginationLimit {
|
|
|
|
paginationLimit = limit
|
|
|
|
}
|
|
|
|
|
2018-07-22 16:14:36 +08:00
|
|
|
lastFileName := req.StartFromFileName
|
|
|
|
includeLastFile := req.InclusiveStartFrom
|
2021-01-16 15:56:24 +08:00
|
|
|
var listErr error
|
2018-07-22 16:14:36 +08:00
|
|
|
for limit > 0 {
|
2021-01-16 15:56:24 +08:00
|
|
|
var hasEntries bool
|
2021-04-25 02:49:03 +08:00
|
|
|
lastFileName, listErr = fs.filer.StreamListDirectoryEntries(stream.Context(), util.FullPath(req.Directory), lastFileName, includeLastFile, int64(paginationLimit), req.Prefix, "", "", func(entry *filer.Entry) bool {
|
2021-01-16 15:56:24 +08:00
|
|
|
hasEntries = true
|
|
|
|
if err = stream.Send(&filer_pb.ListEntriesResponse{
|
2021-07-19 17:47:27 +08:00
|
|
|
Entry: entry.ToProtoEntry(),
|
2019-12-13 16:22:37 +08:00
|
|
|
}); err != nil {
|
2021-01-16 15:56:24 +08:00
|
|
|
return false
|
2019-12-13 16:22:37 +08:00
|
|
|
}
|
2020-02-25 14:28:45 +08:00
|
|
|
|
2018-07-22 16:14:36 +08:00
|
|
|
limit--
|
2019-11-22 17:39:50 +08:00
|
|
|
if limit == 0 {
|
2021-01-16 15:56:24 +08:00
|
|
|
return false
|
2019-11-22 17:39:50 +08:00
|
|
|
}
|
2021-01-16 15:56:24 +08:00
|
|
|
return true
|
|
|
|
})
|
2018-05-14 17:02:17 +08:00
|
|
|
|
2021-01-16 15:56:24 +08:00
|
|
|
if listErr != nil {
|
|
|
|
return listErr
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-12-17 15:20:08 +08:00
|
|
|
}
|
2021-01-16 15:56:24 +08:00
|
|
|
if !hasEntries {
|
|
|
|
return nil
|
2018-12-17 15:20:08 +08:00
|
|
|
}
|
|
|
|
|
2021-01-16 15:56:24 +08:00
|
|
|
includeLastFile = false
|
2018-12-17 15:20:08 +08:00
|
|
|
|
2018-05-08 16:59:43 +08:00
|
|
|
}
|
|
|
|
|
2019-12-13 16:22:37 +08:00
|
|
|
return nil
|
2018-05-08 16:59:43 +08:00
|
|
|
}
|
|
|
|
|
2018-05-24 16:22:37 +08:00
|
|
|
func (fs *FilerServer) LookupVolume(ctx context.Context, req *filer_pb.LookupVolumeRequest) (*filer_pb.LookupVolumeResponse, error) {
|
2018-05-08 16:59:43 +08:00
|
|
|
|
2018-05-24 16:22:37 +08:00
|
|
|
resp := &filer_pb.LookupVolumeResponse{
|
|
|
|
LocationsMap: make(map[string]*filer_pb.Locations),
|
2018-05-08 16:59:43 +08:00
|
|
|
}
|
|
|
|
|
2018-07-29 05:22:46 +08:00
|
|
|
for _, vidString := range req.VolumeIds {
|
|
|
|
vid, err := strconv.Atoi(vidString)
|
|
|
|
if err != nil {
|
2018-07-29 17:25:03 +08:00
|
|
|
glog.V(1).Infof("Unknown volume id %d", vid)
|
2018-07-29 05:22:46 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
2018-05-24 16:22:37 +08:00
|
|
|
var locs []*filer_pb.Location
|
2019-07-28 18:58:13 +08:00
|
|
|
locations, found := fs.filer.MasterClient.GetLocations(uint32(vid))
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, loc := range locations {
|
2018-05-24 16:22:37 +08:00
|
|
|
locs = append(locs, &filer_pb.Location{
|
2022-08-05 08:35:00 +08:00
|
|
|
Url: loc.Url,
|
|
|
|
PublicUrl: loc.PublicUrl,
|
|
|
|
GrpcPort: uint32(loc.GrpcPort),
|
|
|
|
DataCenter: loc.DataCenter,
|
2018-05-24 16:22:37 +08:00
|
|
|
})
|
|
|
|
}
|
2018-07-29 05:22:46 +08:00
|
|
|
resp.LocationsMap[vidString] = &filer_pb.Locations{
|
2018-05-24 16:22:37 +08:00
|
|
|
Locations: locs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
2018-05-08 16:59:43 +08:00
|
|
|
}
|
|
|
|
|
2020-10-08 13:49:04 +08:00
|
|
|
func (fs *FilerServer) lookupFileId(fileId string) (targetUrls []string, err error) {
|
2020-07-20 08:59:43 +08:00
|
|
|
fid, err := needle.ParseFileIdFromString(fileId)
|
|
|
|
if err != nil {
|
2020-10-08 13:49:04 +08:00
|
|
|
return nil, err
|
2020-07-20 08:59:43 +08:00
|
|
|
}
|
|
|
|
locations, found := fs.filer.MasterClient.GetLocations(uint32(fid.VolumeId))
|
|
|
|
if !found || len(locations) == 0 {
|
2020-10-08 13:49:04 +08:00
|
|
|
return nil, fmt.Errorf("not found volume %d in %s", fid.VolumeId, fileId)
|
|
|
|
}
|
|
|
|
for _, loc := range locations {
|
|
|
|
targetUrls = append(targetUrls, fmt.Sprintf("http://%s/%s", loc.Url, fileId))
|
2020-07-20 08:59:43 +08:00
|
|
|
}
|
2020-10-08 13:49:04 +08:00
|
|
|
return
|
2020-07-20 08:59:43 +08:00
|
|
|
}
|
|
|
|
|
2018-05-16 15:08:44 +08:00
|
|
|
func (fs *FilerServer) CreateEntry(ctx context.Context, req *filer_pb.CreateEntryRequest) (resp *filer_pb.CreateEntryResponse, err error) {
|
2018-09-23 13:11:37 +08:00
|
|
|
|
2020-10-25 00:42:54 +08:00
|
|
|
glog.V(4).Infof("CreateEntry %v/%v", req.Directory, req.Entry.Name)
|
2020-04-26 20:21:54 +08:00
|
|
|
|
2020-01-26 01:17:19 +08:00
|
|
|
resp = &filer_pb.CreateEntryResponse{}
|
|
|
|
|
2020-11-16 08:58:48 +08:00
|
|
|
chunks, garbage, err2 := fs.cleanupChunks(util.Join(req.Directory, req.Entry.Name), nil, req.Entry)
|
2020-07-20 08:59:43 +08:00
|
|
|
if err2 != nil {
|
|
|
|
return &filer_pb.CreateEntryResponse{}, fmt.Errorf("CreateEntry cleanupChunks %s %s: %v", req.Directory, req.Entry.Name, err2)
|
|
|
|
}
|
2018-09-23 13:11:37 +08:00
|
|
|
|
2022-06-06 15:15:37 +08:00
|
|
|
so, err := fs.detectStorageOption(string(util.NewFullPath(req.Directory, req.Entry.Name)), "", "", 0, "", "", "", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-19 17:47:27 +08:00
|
|
|
newEntry := filer.FromPbEntry(req.Directory, req.Entry)
|
|
|
|
newEntry.Chunks = chunks
|
2022-06-06 15:15:37 +08:00
|
|
|
newEntry.TtlSec = so.TtlSeconds
|
2021-07-19 17:47:27 +08:00
|
|
|
|
2023-10-13 05:29:55 +08:00
|
|
|
createErr := fs.filer.CreateEntry(ctx, newEntry, req.OExcl, req.IsFromOtherCluster, req.Signatures, req.SkipCheckParentDirectory, so.MaxFileNameLength)
|
2018-05-16 15:08:44 +08:00
|
|
|
|
2020-01-26 01:17:19 +08:00
|
|
|
if createErr == nil {
|
2023-07-17 22:52:14 +08:00
|
|
|
fs.filer.DeleteChunksNotRecursive(garbage)
|
2020-01-25 09:55:39 +08:00
|
|
|
} else {
|
2020-01-26 01:17:19 +08:00
|
|
|
glog.V(3).Infof("CreateEntry %s: %v", filepath.Join(req.Directory, req.Entry.Name), createErr)
|
|
|
|
resp.Error = createErr.Error()
|
2018-05-16 15:08:44 +08:00
|
|
|
}
|
|
|
|
|
2020-01-26 01:17:19 +08:00
|
|
|
return
|
2018-05-16 15:08:44 +08:00
|
|
|
}
|
|
|
|
|
2018-05-22 18:26:38 +08:00
|
|
|
func (fs *FilerServer) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntryRequest) (*filer_pb.UpdateEntryResponse, error) {
|
2018-05-21 15:00:28 +08:00
|
|
|
|
2020-04-26 20:21:54 +08:00
|
|
|
glog.V(4).Infof("UpdateEntry %v", req)
|
|
|
|
|
2020-04-06 04:11:43 +08:00
|
|
|
fullpath := util.Join(req.Directory, req.Entry.Name)
|
2020-03-23 15:01:34 +08:00
|
|
|
entry, err := fs.filer.FindEntry(ctx, util.FullPath(fullpath))
|
2018-05-21 15:00:28 +08:00
|
|
|
if err != nil {
|
2018-05-26 18:49:46 +08:00
|
|
|
return &filer_pb.UpdateEntryResponse{}, fmt.Errorf("not found %s: %v", fullpath, err)
|
2018-05-21 15:00:28 +08:00
|
|
|
}
|
|
|
|
|
2020-11-16 08:58:48 +08:00
|
|
|
chunks, garbage, err2 := fs.cleanupChunks(fullpath, entry, req.Entry)
|
2020-07-20 08:59:43 +08:00
|
|
|
if err2 != nil {
|
|
|
|
return &filer_pb.UpdateEntryResponse{}, fmt.Errorf("UpdateEntry cleanupChunks %s: %v", fullpath, err2)
|
|
|
|
}
|
2018-05-21 15:00:28 +08:00
|
|
|
|
2021-07-19 17:47:27 +08:00
|
|
|
newEntry := filer.FromPbEntry(req.Directory, req.Entry)
|
|
|
|
newEntry.Chunks = chunks
|
2018-05-23 18:08:46 +08:00
|
|
|
|
2020-09-01 15:21:19 +08:00
|
|
|
if filer.EqualEntry(entry, newEntry) {
|
2018-08-13 16:20:49 +08:00
|
|
|
return &filer_pb.UpdateEntryResponse{}, err
|
|
|
|
}
|
|
|
|
|
2019-03-16 06:55:34 +08:00
|
|
|
if err = fs.filer.UpdateEntry(ctx, entry, newEntry); err == nil {
|
2023-07-17 22:52:14 +08:00
|
|
|
fs.filer.DeleteChunksNotRecursive(garbage)
|
2020-09-24 18:06:44 +08:00
|
|
|
|
|
|
|
fs.filer.NotifyUpdateEvent(ctx, entry, newEntry, true, req.IsFromOtherCluster, req.Signatures)
|
|
|
|
|
2020-01-25 09:55:39 +08:00
|
|
|
} else {
|
|
|
|
glog.V(3).Infof("UpdateEntry %s: %v", filepath.Join(req.Directory, req.Entry.Name), err)
|
2018-05-21 15:00:28 +08:00
|
|
|
}
|
|
|
|
|
2018-05-22 18:26:38 +08:00
|
|
|
return &filer_pb.UpdateEntryResponse{}, err
|
2018-05-16 15:08:44 +08:00
|
|
|
}
|
|
|
|
|
2020-11-16 08:58:48 +08:00
|
|
|
func (fs *FilerServer) cleanupChunks(fullpath string, existingEntry *filer.Entry, newEntry *filer_pb.Entry) (chunks, garbage []*filer_pb.FileChunk, err error) {
|
2020-07-20 08:59:43 +08:00
|
|
|
|
|
|
|
// remove old chunks if not included in the new ones
|
|
|
|
if existingEntry != nil {
|
2022-11-15 22:33:36 +08:00
|
|
|
garbage, err = filer.MinusChunks(fs.lookupFileId, existingEntry.GetChunks(), newEntry.GetChunks())
|
2020-07-20 08:59:43 +08:00
|
|
|
if err != nil {
|
2022-11-15 22:33:36 +08:00
|
|
|
return newEntry.GetChunks(), nil, fmt.Errorf("MinusChunks: %v", err)
|
2020-07-20 08:59:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// files with manifest chunks are usually large and append only, skip calculating covered chunks
|
2022-11-15 22:33:36 +08:00
|
|
|
manifestChunks, nonManifestChunks := filer.SeparateManifestChunks(newEntry.GetChunks())
|
2020-08-24 08:15:12 +08:00
|
|
|
|
2020-09-01 15:21:19 +08:00
|
|
|
chunks, coveredChunks := filer.CompactFileChunks(fs.lookupFileId, nonManifestChunks)
|
2020-08-24 08:15:12 +08:00
|
|
|
garbage = append(garbage, coveredChunks...)
|
2020-07-20 08:59:43 +08:00
|
|
|
|
2020-09-24 18:06:44 +08:00
|
|
|
if newEntry.Attributes != nil {
|
2021-06-04 16:03:41 +08:00
|
|
|
so, _ := fs.detectStorageOption(fullpath,
|
2022-06-06 15:39:35 +08:00
|
|
|
"",
|
|
|
|
"",
|
2020-11-16 08:58:48 +08:00
|
|
|
newEntry.Attributes.TtlSec,
|
2022-06-06 15:39:35 +08:00
|
|
|
"",
|
2020-11-16 08:58:48 +08:00
|
|
|
"",
|
|
|
|
"",
|
2021-12-22 21:57:26 +08:00
|
|
|
"",
|
2021-06-04 16:03:41 +08:00
|
|
|
) // ignore readonly error for capacity needed to manifestize
|
2020-11-16 06:41:56 +08:00
|
|
|
chunks, err = filer.MaybeManifestize(fs.saveAsChunk(so), chunks)
|
2020-09-24 18:06:44 +08:00
|
|
|
if err != nil {
|
|
|
|
// not good, but should be ok
|
|
|
|
glog.V(0).Infof("MaybeManifestize: %v", err)
|
|
|
|
}
|
2020-07-20 08:59:43 +08:00
|
|
|
}
|
2020-08-24 08:15:12 +08:00
|
|
|
|
|
|
|
chunks = append(chunks, manifestChunks...)
|
|
|
|
|
2020-07-20 08:59:43 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-17 17:28:09 +08:00
|
|
|
func (fs *FilerServer) AppendToEntry(ctx context.Context, req *filer_pb.AppendToEntryRequest) (*filer_pb.AppendToEntryResponse, error) {
|
|
|
|
|
2020-04-26 20:21:54 +08:00
|
|
|
glog.V(4).Infof("AppendToEntry %v", req)
|
2020-04-17 17:28:09 +08:00
|
|
|
fullpath := util.NewFullPath(req.Directory, req.EntryName)
|
2023-06-26 13:07:23 +08:00
|
|
|
|
2023-09-17 06:05:38 +08:00
|
|
|
lockClient := cluster.NewLockClient(fs.grpcDialOption, fs.option.Host)
|
|
|
|
lock := lockClient.NewLock(string(fullpath), string(fs.option.Host))
|
|
|
|
defer lock.StopLock()
|
2023-06-26 13:07:23 +08:00
|
|
|
|
2020-04-17 17:28:09 +08:00
|
|
|
var offset int64 = 0
|
2020-11-16 08:58:48 +08:00
|
|
|
entry, err := fs.filer.FindEntry(ctx, fullpath)
|
2020-04-17 17:28:09 +08:00
|
|
|
if err == filer_pb.ErrNotFound {
|
2020-09-01 15:21:19 +08:00
|
|
|
entry = &filer.Entry{
|
2020-04-17 17:28:09 +08:00
|
|
|
FullPath: fullpath,
|
2020-09-01 15:21:19 +08:00
|
|
|
Attr: filer.Attr{
|
2020-04-17 17:28:09 +08:00
|
|
|
Crtime: time.Now(),
|
|
|
|
Mtime: time.Now(),
|
|
|
|
Mode: os.FileMode(0644),
|
|
|
|
Uid: OS_UID,
|
|
|
|
Gid: OS_GID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
2022-11-15 22:33:36 +08:00
|
|
|
offset = int64(filer.TotalSize(entry.GetChunks()))
|
2020-04-17 17:28:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, chunk := range req.Chunks {
|
|
|
|
chunk.Offset = offset
|
|
|
|
offset += int64(chunk.Size)
|
|
|
|
}
|
|
|
|
|
2022-11-15 22:33:36 +08:00
|
|
|
entry.Chunks = append(entry.GetChunks(), req.Chunks...)
|
2022-06-06 15:39:35 +08:00
|
|
|
so, err := fs.detectStorageOption(string(fullpath), "", "", entry.TtlSec, "", "", "", "")
|
2021-06-04 16:03:41 +08:00
|
|
|
if err != nil {
|
|
|
|
glog.Warningf("detectStorageOption: %v", err)
|
|
|
|
return &filer_pb.AppendToEntryResponse{}, err
|
|
|
|
}
|
2022-11-15 22:33:36 +08:00
|
|
|
entry.Chunks, err = filer.MaybeManifestize(fs.saveAsChunk(so), entry.GetChunks())
|
2020-07-20 08:59:43 +08:00
|
|
|
if err != nil {
|
|
|
|
// not good, but should be ok
|
|
|
|
glog.V(0).Infof("MaybeManifestize: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-10-13 05:29:55 +08:00
|
|
|
err = fs.filer.CreateEntry(context.Background(), entry, false, false, nil, false, fs.filer.MaxFilenameLength)
|
2020-04-17 17:28:09 +08:00
|
|
|
|
|
|
|
return &filer_pb.AppendToEntryResponse{}, err
|
|
|
|
}
|
|
|
|
|
2018-05-10 14:18:02 +08:00
|
|
|
func (fs *FilerServer) DeleteEntry(ctx context.Context, req *filer_pb.DeleteEntryRequest) (resp *filer_pb.DeleteEntryResponse, err error) {
|
2020-04-26 20:21:54 +08:00
|
|
|
|
|
|
|
glog.V(4).Infof("DeleteEntry %v", req)
|
|
|
|
|
2020-09-10 02:21:23 +08:00
|
|
|
err = fs.filer.DeleteEntryMetaAndData(ctx, util.JoinPath(req.Directory, req.Name), req.IsRecursive, req.IgnoreRecursiveError, req.IsDeleteData, req.IsFromOtherCluster, req.Signatures)
|
2020-02-26 06:38:36 +08:00
|
|
|
resp = &filer_pb.DeleteEntryResponse{}
|
2020-12-28 16:18:37 +08:00
|
|
|
if err != nil && err != filer_pb.ErrNotFound {
|
2020-02-26 06:38:36 +08:00
|
|
|
resp.Error = err.Error()
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2018-05-16 15:08:44 +08:00
|
|
|
func (fs *FilerServer) AssignVolume(ctx context.Context, req *filer_pb.AssignVolumeRequest) (resp *filer_pb.AssignVolumeResponse, err error) {
|
|
|
|
|
2023-02-26 01:48:59 +08:00
|
|
|
if req.DiskType == "" {
|
|
|
|
req.DiskType = fs.option.DiskType
|
|
|
|
}
|
|
|
|
|
2021-12-22 21:57:26 +08:00
|
|
|
so, err := fs.detectStorageOption(req.Path, req.Collection, req.Replication, req.TtlSec, req.DiskType, req.DataCenter, req.Rack, req.DataNode)
|
2021-06-04 16:03:41 +08:00
|
|
|
if err != nil {
|
|
|
|
glog.V(3).Infof("AssignVolume: %v", err)
|
|
|
|
return &filer_pb.AssignVolumeResponse{Error: fmt.Sprintf("assign volume: %v", err)}, nil
|
|
|
|
}
|
2018-07-10 14:18:20 +08:00
|
|
|
|
2020-11-16 08:58:48 +08:00
|
|
|
assignRequest, altRequest := so.ToAssignRequests(int(req.Count))
|
2018-07-15 04:36:28 +08:00
|
|
|
|
2021-02-18 12:55:55 +08:00
|
|
|
assignResult, err := operation.Assign(fs.filer.GetMaster, fs.grpcDialOption, assignRequest, altRequest)
|
2018-05-16 15:08:44 +08:00
|
|
|
if err != nil {
|
2020-01-25 10:07:34 +08:00
|
|
|
glog.V(3).Infof("AssignVolume: %v", err)
|
2020-02-26 09:15:09 +08:00
|
|
|
return &filer_pb.AssignVolumeResponse{Error: fmt.Sprintf("assign volume: %v", err)}, nil
|
2018-05-16 15:08:44 +08:00
|
|
|
}
|
|
|
|
if assignResult.Error != "" {
|
2020-01-25 10:07:34 +08:00
|
|
|
glog.V(3).Infof("AssignVolume error: %v", assignResult.Error)
|
2020-02-26 09:15:09 +08:00
|
|
|
return &filer_pb.AssignVolumeResponse{Error: fmt.Sprintf("assign volume result: %v", assignResult.Error)}, nil
|
2018-05-16 15:08:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return &filer_pb.AssignVolumeResponse{
|
2021-09-13 13:47:52 +08:00
|
|
|
FileId: assignResult.Fid,
|
|
|
|
Count: int32(assignResult.Count),
|
|
|
|
Location: &filer_pb.Location{
|
|
|
|
Url: assignResult.Url,
|
|
|
|
PublicUrl: assignResult.PublicUrl,
|
|
|
|
GrpcPort: uint32(assignResult.GrpcPort),
|
|
|
|
},
|
2020-02-25 14:28:45 +08:00
|
|
|
Auth: string(assignResult.Auth),
|
2020-11-16 08:58:48 +08:00
|
|
|
Collection: so.Collection,
|
|
|
|
Replication: so.Replication,
|
2020-02-26 09:15:09 +08:00
|
|
|
}, nil
|
2018-05-16 15:08:44 +08:00
|
|
|
}
|
2018-07-20 15:10:01 +08:00
|
|
|
|
2020-10-16 01:52:17 +08:00
|
|
|
func (fs *FilerServer) CollectionList(ctx context.Context, req *filer_pb.CollectionListRequest) (resp *filer_pb.CollectionListResponse, err error) {
|
|
|
|
|
|
|
|
glog.V(4).Infof("CollectionList %v", req)
|
|
|
|
resp = &filer_pb.CollectionListResponse{}
|
|
|
|
|
2021-12-26 16:15:03 +08:00
|
|
|
err = fs.filer.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
|
2020-10-16 01:52:17 +08:00
|
|
|
masterResp, err := client.CollectionList(context.Background(), &master_pb.CollectionListRequest{
|
|
|
|
IncludeNormalVolumes: req.IncludeNormalVolumes,
|
|
|
|
IncludeEcVolumes: req.IncludeEcVolumes,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, c := range masterResp.Collections {
|
|
|
|
resp.Collections = append(resp.Collections, &filer_pb.Collection{Name: c.Name})
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-20 15:10:01 +08:00
|
|
|
func (fs *FilerServer) DeleteCollection(ctx context.Context, req *filer_pb.DeleteCollectionRequest) (resp *filer_pb.DeleteCollectionResponse, err error) {
|
|
|
|
|
2020-04-26 20:21:54 +08:00
|
|
|
glog.V(4).Infof("DeleteCollection %v", req)
|
|
|
|
|
2021-12-26 16:15:03 +08:00
|
|
|
err = fs.filer.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
|
2020-02-26 13:50:12 +08:00
|
|
|
_, err := client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
|
2019-03-19 20:19:37 +08:00
|
|
|
Name: req.GetCollection(),
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
})
|
2018-07-20 15:10:01 +08:00
|
|
|
|
|
|
|
return &filer_pb.DeleteCollectionResponse{}, err
|
|
|
|
}
|