2018-05-08 08:59:43 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-05-27 18:52:26 +00:00
|
|
|
"fmt"
|
2018-05-27 06:59:56 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2018-11-23 08:24:51 +00:00
|
|
|
"strconv"
|
2018-05-27 18:52:26 +00:00
|
|
|
"time"
|
2018-05-27 06:59:56 +00:00
|
|
|
|
2020-09-01 07:21:19 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
2018-05-14 06:56:16 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2018-05-27 18:52:26 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/operation"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2018-11-23 08:24:51 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2020-07-20 00:59:43 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
2020-03-23 07:01:34 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2018-05-08 08:59:43 +00:00
|
|
|
)
|
|
|
|
|
2018-05-10 06:18:02 +00:00
|
|
|
func (fs *FilerServer) LookupDirectoryEntry(ctx context.Context, req *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) {
|
2018-05-08 08:59:43 +00:00
|
|
|
|
2020-04-26 12:21:54 +00:00
|
|
|
glog.V(4).Infof("LookupDirectoryEntry %s", filepath.Join(req.Directory, req.Name))
|
|
|
|
|
2020-04-05 20:11:43 +00:00
|
|
|
entry, err := fs.filer.FindEntry(ctx, util.JoinPath(req.Directory, req.Name))
|
2020-03-08 01:01:39 +00:00
|
|
|
if err == filer_pb.ErrNotFound {
|
2020-04-26 12:21:54 +00:00
|
|
|
return &filer_pb.LookupDirectoryEntryResponse{}, err
|
2020-01-25 02:07:34 +00:00
|
|
|
}
|
2018-05-08 08:59:43 +00:00
|
|
|
if err != nil {
|
2020-01-25 01:26:03 +00:00
|
|
|
glog.V(3).Infof("LookupDirectoryEntry %s: %+v, ", filepath.Join(req.Directory, req.Name), err)
|
2019-09-02 04:40:26 +00:00
|
|
|
return nil, err
|
2018-05-08 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 06:18:02 +00:00
|
|
|
return &filer_pb.LookupDirectoryEntryResponse{
|
|
|
|
Entry: &filer_pb.Entry{
|
2020-10-08 06:30:54 +00:00
|
|
|
Name: req.Name,
|
|
|
|
IsDirectory: entry.IsDirectory(),
|
|
|
|
Attributes: filer.EntryAttributeToPb(entry),
|
|
|
|
Chunks: entry.Chunks,
|
|
|
|
Extended: entry.Extended,
|
|
|
|
HardLinkId: entry.HardLinkId,
|
2020-09-24 10:06:44 +00:00
|
|
|
HardLinkCounter: entry.HardLinkCounter,
|
2020-11-30 12:34:04 +00:00
|
|
|
Content: entry.Content,
|
2018-05-08 08:59:43 +00:00
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-12-13 08:22:37 +00:00
|
|
|
func (fs *FilerServer) ListEntries(req *filer_pb.ListEntriesRequest, stream filer_pb.SeaweedFiler_ListEntriesServer) error {
|
2018-05-08 08:59:43 +00:00
|
|
|
|
2020-04-26 12:21:54 +00:00
|
|
|
glog.V(4).Infof("ListEntries %v", req)
|
|
|
|
|
2018-07-22 08:14:36 +00:00
|
|
|
limit := int(req.Limit)
|
|
|
|
if limit == 0 {
|
|
|
|
limit = fs.option.DirListingLimit
|
2018-05-08 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 07:21:19 +00:00
|
|
|
paginationLimit := filer.PaginationSize
|
2019-11-22 09:39:50 +00:00
|
|
|
if limit < paginationLimit {
|
|
|
|
paginationLimit = limit
|
|
|
|
}
|
|
|
|
|
2018-07-22 08:14:36 +00:00
|
|
|
lastFileName := req.StartFromFileName
|
|
|
|
includeLastFile := req.InclusiveStartFrom
|
|
|
|
for limit > 0 {
|
2020-08-05 17:19:16 +00:00
|
|
|
entries, err := fs.filer.ListDirectoryEntries(stream.Context(), util.FullPath(req.Directory), lastFileName, includeLastFile, paginationLimit, req.Prefix)
|
2020-02-25 06:28:45 +00:00
|
|
|
|
2018-07-22 08:14:36 +00:00
|
|
|
if err != nil {
|
2019-12-13 08:22:37 +00:00
|
|
|
return err
|
2018-07-22 08:14:36 +00:00
|
|
|
}
|
|
|
|
if len(entries) == 0 {
|
2019-12-13 08:22:37 +00:00
|
|
|
return nil
|
2018-07-22 08:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
includeLastFile = false
|
|
|
|
|
|
|
|
for _, entry := range entries {
|
|
|
|
|
|
|
|
lastFileName = entry.Name()
|
|
|
|
|
2019-12-13 08:22:37 +00:00
|
|
|
if err := stream.Send(&filer_pb.ListEntriesResponse{
|
|
|
|
Entry: &filer_pb.Entry{
|
2020-10-08 06:30:54 +00:00
|
|
|
Name: entry.Name(),
|
|
|
|
IsDirectory: entry.IsDirectory(),
|
|
|
|
Chunks: entry.Chunks,
|
|
|
|
Attributes: filer.EntryAttributeToPb(entry),
|
|
|
|
Extended: entry.Extended,
|
|
|
|
HardLinkId: entry.HardLinkId,
|
2020-09-24 10:06:44 +00:00
|
|
|
HardLinkCounter: entry.HardLinkCounter,
|
2020-11-30 12:34:04 +00:00
|
|
|
Content: entry.Content,
|
2019-12-13 08:22:37 +00:00
|
|
|
},
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-25 06:28:45 +00:00
|
|
|
|
2018-07-22 08:14:36 +00:00
|
|
|
limit--
|
2019-11-22 09:39:50 +00:00
|
|
|
if limit == 0 {
|
2019-12-13 08:22:37 +00:00
|
|
|
return nil
|
2019-11-22 09:39:50 +00:00
|
|
|
}
|
2018-07-22 08:14:36 +00:00
|
|
|
}
|
2018-05-14 09:02:17 +00:00
|
|
|
|
2020-03-10 06:28:01 +00:00
|
|
|
if len(entries) < paginationLimit {
|
2018-12-17 07:20:08 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2018-05-08 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 08:22:37 +00:00
|
|
|
return nil
|
2018-05-08 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 08:22:37 +00:00
|
|
|
func (fs *FilerServer) LookupVolume(ctx context.Context, req *filer_pb.LookupVolumeRequest) (*filer_pb.LookupVolumeResponse, error) {
|
2018-05-08 08:59:43 +00:00
|
|
|
|
2018-05-24 08:22:37 +00:00
|
|
|
resp := &filer_pb.LookupVolumeResponse{
|
|
|
|
LocationsMap: make(map[string]*filer_pb.Locations),
|
2018-05-08 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-28 21:22:46 +00:00
|
|
|
for _, vidString := range req.VolumeIds {
|
|
|
|
vid, err := strconv.Atoi(vidString)
|
|
|
|
if err != nil {
|
2018-07-29 09:25:03 +00:00
|
|
|
glog.V(1).Infof("Unknown volume id %d", vid)
|
2018-07-28 21:22:46 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2018-05-24 08:22:37 +00:00
|
|
|
var locs []*filer_pb.Location
|
2019-07-28 10:58:13 +00:00
|
|
|
locations, found := fs.filer.MasterClient.GetLocations(uint32(vid))
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, loc := range locations {
|
2018-05-24 08:22:37 +00:00
|
|
|
locs = append(locs, &filer_pb.Location{
|
|
|
|
Url: loc.Url,
|
|
|
|
PublicUrl: loc.PublicUrl,
|
|
|
|
})
|
|
|
|
}
|
2018-07-28 21:22:46 +00:00
|
|
|
resp.LocationsMap[vidString] = &filer_pb.Locations{
|
2018-05-24 08:22:37 +00:00
|
|
|
Locations: locs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
2018-05-08 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 05:49:04 +00:00
|
|
|
func (fs *FilerServer) lookupFileId(fileId string) (targetUrls []string, err error) {
|
2020-07-20 00:59:43 +00:00
|
|
|
fid, err := needle.ParseFileIdFromString(fileId)
|
|
|
|
if err != nil {
|
2020-10-08 05:49:04 +00:00
|
|
|
return nil, err
|
2020-07-20 00:59:43 +00:00
|
|
|
}
|
|
|
|
locations, found := fs.filer.MasterClient.GetLocations(uint32(fid.VolumeId))
|
|
|
|
if !found || len(locations) == 0 {
|
2020-10-08 05:49:04 +00: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 00:59:43 +00:00
|
|
|
}
|
2020-10-08 05:49:04 +00:00
|
|
|
return
|
2020-07-20 00:59:43 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 07:08:44 +00:00
|
|
|
func (fs *FilerServer) CreateEntry(ctx context.Context, req *filer_pb.CreateEntryRequest) (resp *filer_pb.CreateEntryResponse, err error) {
|
2018-09-23 05:11:37 +00:00
|
|
|
|
2020-10-24 16:42:54 +00:00
|
|
|
glog.V(4).Infof("CreateEntry %v/%v", req.Directory, req.Entry.Name)
|
2020-04-26 12:21:54 +00:00
|
|
|
|
2020-01-25 17:17:19 +00:00
|
|
|
resp = &filer_pb.CreateEntryResponse{}
|
|
|
|
|
2020-11-16 00:58:48 +00:00
|
|
|
chunks, garbage, err2 := fs.cleanupChunks(util.Join(req.Directory, req.Entry.Name), nil, req.Entry)
|
2020-07-20 00:59:43 +00:00
|
|
|
if err2 != nil {
|
|
|
|
return &filer_pb.CreateEntryResponse{}, fmt.Errorf("CreateEntry cleanupChunks %s %s: %v", req.Directory, req.Entry.Name, err2)
|
|
|
|
}
|
2018-09-23 05:11:37 +00:00
|
|
|
|
2020-09-01 07:21:19 +00:00
|
|
|
createErr := fs.filer.CreateEntry(ctx, &filer.Entry{
|
2020-10-08 06:30:54 +00:00
|
|
|
FullPath: util.JoinPath(req.Directory, req.Entry.Name),
|
|
|
|
Attr: filer.PbToEntryAttribute(req.Entry.Attributes),
|
|
|
|
Chunks: chunks,
|
|
|
|
Extended: req.Entry.Extended,
|
|
|
|
HardLinkId: filer.HardLinkId(req.Entry.HardLinkId),
|
2020-09-24 10:06:44 +00:00
|
|
|
HardLinkCounter: req.Entry.HardLinkCounter,
|
2020-08-29 06:48:48 +00:00
|
|
|
}, req.OExcl, req.IsFromOtherCluster, req.Signatures)
|
2018-05-16 07:08:44 +00:00
|
|
|
|
2020-01-25 17:17:19 +00:00
|
|
|
if createErr == nil {
|
2020-07-20 00:59:43 +00:00
|
|
|
fs.filer.DeleteChunks(garbage)
|
2020-01-25 01:55:39 +00:00
|
|
|
} else {
|
2020-01-25 17:17:19 +00:00
|
|
|
glog.V(3).Infof("CreateEntry %s: %v", filepath.Join(req.Directory, req.Entry.Name), createErr)
|
|
|
|
resp.Error = createErr.Error()
|
2018-05-16 07:08:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-25 17:17:19 +00:00
|
|
|
return
|
2018-05-16 07:08:44 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 10:26:38 +00:00
|
|
|
func (fs *FilerServer) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntryRequest) (*filer_pb.UpdateEntryResponse, error) {
|
2018-05-21 07:00:28 +00:00
|
|
|
|
2020-04-26 12:21:54 +00:00
|
|
|
glog.V(4).Infof("UpdateEntry %v", req)
|
|
|
|
|
2020-04-05 20:11:43 +00:00
|
|
|
fullpath := util.Join(req.Directory, req.Entry.Name)
|
2020-03-23 07:01:34 +00:00
|
|
|
entry, err := fs.filer.FindEntry(ctx, util.FullPath(fullpath))
|
2018-05-21 07:00:28 +00:00
|
|
|
if err != nil {
|
2018-05-26 10:49:46 +00:00
|
|
|
return &filer_pb.UpdateEntryResponse{}, fmt.Errorf("not found %s: %v", fullpath, err)
|
2018-05-21 07:00:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 00:58:48 +00:00
|
|
|
chunks, garbage, err2 := fs.cleanupChunks(fullpath, entry, req.Entry)
|
2020-07-20 00:59:43 +00:00
|
|
|
if err2 != nil {
|
|
|
|
return &filer_pb.UpdateEntryResponse{}, fmt.Errorf("UpdateEntry cleanupChunks %s: %v", fullpath, err2)
|
|
|
|
}
|
2018-05-21 07:00:28 +00:00
|
|
|
|
2020-09-01 07:21:19 +00:00
|
|
|
newEntry := &filer.Entry{
|
2020-10-08 06:30:54 +00:00
|
|
|
FullPath: util.JoinPath(req.Directory, req.Entry.Name),
|
|
|
|
Attr: entry.Attr,
|
|
|
|
Extended: req.Entry.Extended,
|
|
|
|
Chunks: chunks,
|
|
|
|
HardLinkId: filer.HardLinkId(req.Entry.HardLinkId),
|
2020-09-24 10:06:44 +00:00
|
|
|
HardLinkCounter: req.Entry.HardLinkCounter,
|
2018-05-23 10:08:46 +00:00
|
|
|
}
|
2018-05-16 07:08:44 +00:00
|
|
|
|
2019-12-18 05:39:48 +00:00
|
|
|
glog.V(3).Infof("updating %s: %+v, chunks %d: %v => %+v, chunks %d: %v, extended: %v => %v",
|
2018-05-23 10:08:46 +00:00
|
|
|
fullpath, entry.Attr, len(entry.Chunks), entry.Chunks,
|
2019-12-18 05:39:48 +00:00
|
|
|
req.Entry.Attributes, len(req.Entry.Chunks), req.Entry.Chunks,
|
|
|
|
entry.Extended, req.Entry.Extended)
|
2018-05-23 10:08:46 +00:00
|
|
|
|
|
|
|
if req.Entry.Attributes != nil {
|
|
|
|
if req.Entry.Attributes.Mtime != 0 {
|
|
|
|
newEntry.Attr.Mtime = time.Unix(req.Entry.Attributes.Mtime, 0)
|
|
|
|
}
|
|
|
|
if req.Entry.Attributes.FileMode != 0 {
|
|
|
|
newEntry.Attr.Mode = os.FileMode(req.Entry.Attributes.FileMode)
|
|
|
|
}
|
|
|
|
newEntry.Attr.Uid = req.Entry.Attributes.Uid
|
|
|
|
newEntry.Attr.Gid = req.Entry.Attributes.Gid
|
2018-05-31 03:24:57 +00:00
|
|
|
newEntry.Attr.Mime = req.Entry.Attributes.Mime
|
2018-12-04 08:46:00 +00:00
|
|
|
newEntry.Attr.UserName = req.Entry.Attributes.UserName
|
|
|
|
newEntry.Attr.GroupNames = req.Entry.Attributes.GroupName
|
2018-05-23 10:08:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-01 07:21:19 +00:00
|
|
|
if filer.EqualEntry(entry, newEntry) {
|
2018-08-13 08:20:49 +00:00
|
|
|
return &filer_pb.UpdateEntryResponse{}, err
|
|
|
|
}
|
|
|
|
|
2019-03-15 22:55:34 +00:00
|
|
|
if err = fs.filer.UpdateEntry(ctx, entry, newEntry); err == nil {
|
2020-07-20 00:59:43 +00:00
|
|
|
fs.filer.DeleteChunks(garbage)
|
2020-09-24 10:06:44 +00:00
|
|
|
|
|
|
|
fs.filer.NotifyUpdateEvent(ctx, entry, newEntry, true, req.IsFromOtherCluster, req.Signatures)
|
|
|
|
|
2020-01-25 01:55:39 +00:00
|
|
|
} else {
|
|
|
|
glog.V(3).Infof("UpdateEntry %s: %v", filepath.Join(req.Directory, req.Entry.Name), err)
|
2018-05-21 07:00:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 10:26:38 +00:00
|
|
|
return &filer_pb.UpdateEntryResponse{}, err
|
2018-05-16 07:08:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 00:58:48 +00:00
|
|
|
func (fs *FilerServer) cleanupChunks(fullpath string, existingEntry *filer.Entry, newEntry *filer_pb.Entry) (chunks, garbage []*filer_pb.FileChunk, err error) {
|
2020-07-20 00:59:43 +00:00
|
|
|
|
|
|
|
// remove old chunks if not included in the new ones
|
|
|
|
if existingEntry != nil {
|
2020-09-01 07:21:19 +00:00
|
|
|
garbage, err = filer.MinusChunks(fs.lookupFileId, existingEntry.Chunks, newEntry.Chunks)
|
2020-07-20 00:59:43 +00:00
|
|
|
if err != nil {
|
2020-08-24 00:15:12 +00:00
|
|
|
return newEntry.Chunks, nil, fmt.Errorf("MinusChunks: %v", err)
|
2020-07-20 00:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// files with manifest chunks are usually large and append only, skip calculating covered chunks
|
2020-09-01 07:21:19 +00:00
|
|
|
manifestChunks, nonManifestChunks := filer.SeparateManifestChunks(newEntry.Chunks)
|
2020-08-24 00:15:12 +00:00
|
|
|
|
2020-09-01 07:21:19 +00:00
|
|
|
chunks, coveredChunks := filer.CompactFileChunks(fs.lookupFileId, nonManifestChunks)
|
2020-08-24 00:15:12 +00:00
|
|
|
garbage = append(garbage, coveredChunks...)
|
2020-07-20 00:59:43 +00:00
|
|
|
|
2020-09-24 10:06:44 +00:00
|
|
|
if newEntry.Attributes != nil {
|
2020-11-16 00:58:48 +00:00
|
|
|
so := fs.detectStorageOption(fullpath,
|
|
|
|
newEntry.Attributes.Collection,
|
|
|
|
newEntry.Attributes.Replication,
|
|
|
|
newEntry.Attributes.TtlSec,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
)
|
2020-11-15 22:41:56 +00:00
|
|
|
chunks, err = filer.MaybeManifestize(fs.saveAsChunk(so), chunks)
|
2020-09-24 10:06:44 +00:00
|
|
|
if err != nil {
|
|
|
|
// not good, but should be ok
|
|
|
|
glog.V(0).Infof("MaybeManifestize: %v", err)
|
|
|
|
}
|
2020-07-20 00:59:43 +00:00
|
|
|
}
|
2020-08-24 00:15:12 +00:00
|
|
|
|
|
|
|
chunks = append(chunks, manifestChunks...)
|
|
|
|
|
2020-07-20 00:59:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-17 09:28:09 +00:00
|
|
|
func (fs *FilerServer) AppendToEntry(ctx context.Context, req *filer_pb.AppendToEntryRequest) (*filer_pb.AppendToEntryResponse, error) {
|
|
|
|
|
2020-04-26 12:21:54 +00:00
|
|
|
glog.V(4).Infof("AppendToEntry %v", req)
|
|
|
|
|
2020-04-17 09:28:09 +00:00
|
|
|
fullpath := util.NewFullPath(req.Directory, req.EntryName)
|
|
|
|
var offset int64 = 0
|
2020-11-16 00:58:48 +00:00
|
|
|
entry, err := fs.filer.FindEntry(ctx, fullpath)
|
2020-04-17 09:28:09 +00:00
|
|
|
if err == filer_pb.ErrNotFound {
|
2020-09-01 07:21:19 +00:00
|
|
|
entry = &filer.Entry{
|
2020-04-17 09:28:09 +00:00
|
|
|
FullPath: fullpath,
|
2020-09-01 07:21:19 +00:00
|
|
|
Attr: filer.Attr{
|
2020-04-17 09:28:09 +00:00
|
|
|
Crtime: time.Now(),
|
|
|
|
Mtime: time.Now(),
|
|
|
|
Mode: os.FileMode(0644),
|
|
|
|
Uid: OS_UID,
|
|
|
|
Gid: OS_GID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
2020-09-01 07:21:19 +00:00
|
|
|
offset = int64(filer.TotalSize(entry.Chunks))
|
2020-04-17 09:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, chunk := range req.Chunks {
|
|
|
|
chunk.Offset = offset
|
|
|
|
offset += int64(chunk.Size)
|
|
|
|
}
|
|
|
|
|
|
|
|
entry.Chunks = append(entry.Chunks, req.Chunks...)
|
2020-11-16 00:58:48 +00:00
|
|
|
so := fs.detectStorageOption(string(fullpath), entry.Collection, entry.Replication, entry.TtlSec, "", "")
|
2020-11-15 22:41:56 +00:00
|
|
|
entry.Chunks, err = filer.MaybeManifestize(fs.saveAsChunk(so), entry.Chunks)
|
2020-07-20 00:59:43 +00:00
|
|
|
if err != nil {
|
|
|
|
// not good, but should be ok
|
|
|
|
glog.V(0).Infof("MaybeManifestize: %v", err)
|
|
|
|
}
|
|
|
|
|
2020-08-29 06:48:48 +00:00
|
|
|
err = fs.filer.CreateEntry(context.Background(), entry, false, false, nil)
|
2020-04-17 09:28:09 +00:00
|
|
|
|
|
|
|
return &filer_pb.AppendToEntryResponse{}, err
|
|
|
|
}
|
|
|
|
|
2018-05-10 06:18:02 +00:00
|
|
|
func (fs *FilerServer) DeleteEntry(ctx context.Context, req *filer_pb.DeleteEntryRequest) (resp *filer_pb.DeleteEntryResponse, err error) {
|
2020-04-26 12:21:54 +00:00
|
|
|
|
|
|
|
glog.V(4).Infof("DeleteEntry %v", req)
|
|
|
|
|
2020-09-09 18:21:23 +00:00
|
|
|
err = fs.filer.DeleteEntryMetaAndData(ctx, util.JoinPath(req.Directory, req.Name), req.IsRecursive, req.IgnoreRecursiveError, req.IsDeleteData, req.IsFromOtherCluster, req.Signatures)
|
2020-02-25 22:38:36 +00:00
|
|
|
resp = &filer_pb.DeleteEntryResponse{}
|
|
|
|
if err != nil {
|
|
|
|
resp.Error = err.Error()
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2018-05-16 07:08:44 +00:00
|
|
|
func (fs *FilerServer) AssignVolume(ctx context.Context, req *filer_pb.AssignVolumeRequest) (resp *filer_pb.AssignVolumeResponse, err error) {
|
|
|
|
|
2020-11-16 00:58:48 +00:00
|
|
|
so := fs.detectStorageOption(req.Path, req.Collection, req.Replication, req.TtlSec, req.DataCenter, req.Rack)
|
2018-07-10 06:18:20 +00:00
|
|
|
|
2020-11-16 00:58:48 +00:00
|
|
|
assignRequest, altRequest := so.ToAssignRequests(int(req.Count))
|
2018-07-14 20:36:28 +00:00
|
|
|
|
2019-02-18 20:11:52 +00:00
|
|
|
assignResult, err := operation.Assign(fs.filer.GetMaster(), fs.grpcDialOption, assignRequest, altRequest)
|
2018-05-16 07:08:44 +00:00
|
|
|
if err != nil {
|
2020-01-25 02:07:34 +00:00
|
|
|
glog.V(3).Infof("AssignVolume: %v", err)
|
2020-02-26 01:15:09 +00:00
|
|
|
return &filer_pb.AssignVolumeResponse{Error: fmt.Sprintf("assign volume: %v", err)}, nil
|
2018-05-16 07:08:44 +00:00
|
|
|
}
|
|
|
|
if assignResult.Error != "" {
|
2020-01-25 02:07:34 +00:00
|
|
|
glog.V(3).Infof("AssignVolume error: %v", assignResult.Error)
|
2020-02-26 01:15:09 +00:00
|
|
|
return &filer_pb.AssignVolumeResponse{Error: fmt.Sprintf("assign volume result: %v", assignResult.Error)}, nil
|
2018-05-16 07:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &filer_pb.AssignVolumeResponse{
|
2020-02-25 06:28:45 +00:00
|
|
|
FileId: assignResult.Fid,
|
|
|
|
Count: int32(assignResult.Count),
|
|
|
|
Url: assignResult.Url,
|
|
|
|
PublicUrl: assignResult.PublicUrl,
|
|
|
|
Auth: string(assignResult.Auth),
|
2020-11-16 00:58:48 +00:00
|
|
|
Collection: so.Collection,
|
|
|
|
Replication: so.Replication,
|
2020-02-26 01:15:09 +00:00
|
|
|
}, nil
|
2018-05-16 07:08:44 +00:00
|
|
|
}
|
2018-07-20 07:10:01 +00:00
|
|
|
|
2020-10-15 17:52:17 +00: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{}
|
|
|
|
|
|
|
|
err = fs.filer.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
|
|
|
|
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 07:10:01 +00:00
|
|
|
func (fs *FilerServer) DeleteCollection(ctx context.Context, req *filer_pb.DeleteCollectionRequest) (resp *filer_pb.DeleteCollectionResponse, err error) {
|
|
|
|
|
2020-04-26 12:21:54 +00:00
|
|
|
glog.V(4).Infof("DeleteCollection %v", req)
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
err = fs.filer.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {
|
|
|
|
_, err := client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
|
2019-03-19 12:19:37 +00:00
|
|
|
Name: req.GetCollection(),
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
})
|
2018-07-20 07:10:01 +00:00
|
|
|
|
|
|
|
return &filer_pb.DeleteCollectionResponse{}, err
|
|
|
|
}
|
2018-11-23 08:24:51 +00:00
|
|
|
|
|
|
|
func (fs *FilerServer) Statistics(ctx context.Context, req *filer_pb.StatisticsRequest) (resp *filer_pb.StatisticsResponse, err error) {
|
|
|
|
|
2020-03-27 05:46:49 +00:00
|
|
|
var output *master_pb.StatisticsResponse
|
|
|
|
|
|
|
|
err = fs.filer.MasterClient.WithClient(func(masterClient master_pb.SeaweedClient) error {
|
|
|
|
grpcResponse, grpcErr := masterClient.Statistics(context.Background(), &master_pb.StatisticsRequest{
|
|
|
|
Replication: req.Replication,
|
|
|
|
Collection: req.Collection,
|
|
|
|
Ttl: req.Ttl,
|
|
|
|
})
|
|
|
|
if grpcErr != nil {
|
|
|
|
return grpcErr
|
|
|
|
}
|
|
|
|
|
|
|
|
output = grpcResponse
|
|
|
|
return nil
|
|
|
|
})
|
2018-11-23 08:24:51 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &filer_pb.StatisticsResponse{
|
|
|
|
TotalSize: output.TotalSize,
|
|
|
|
UsedSize: output.UsedSize,
|
|
|
|
FileCount: output.FileCount,
|
|
|
|
}, nil
|
|
|
|
}
|
2019-06-23 08:57:35 +00:00
|
|
|
|
|
|
|
func (fs *FilerServer) GetFilerConfiguration(ctx context.Context, req *filer_pb.GetFilerConfigurationRequest) (resp *filer_pb.GetFilerConfigurationResponse, err error) {
|
|
|
|
|
2020-04-26 12:21:54 +00:00
|
|
|
t := &filer_pb.GetFilerConfigurationResponse{
|
2020-09-17 13:46:51 +00:00
|
|
|
Masters: fs.option.Masters,
|
|
|
|
Collection: fs.option.Collection,
|
|
|
|
Replication: fs.option.DefaultReplication,
|
|
|
|
MaxMb: uint32(fs.option.MaxMB),
|
|
|
|
DirBuckets: fs.filer.DirBucketsPath,
|
|
|
|
Cipher: fs.filer.Cipher,
|
|
|
|
Signature: fs.filer.Signature,
|
|
|
|
MetricsAddress: fs.metricsAddress,
|
|
|
|
MetricsIntervalSec: int32(fs.metricsIntervalSec),
|
2020-04-26 12:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glog.V(4).Infof("GetFilerConfiguration: %v", t)
|
|
|
|
|
|
|
|
return t, nil
|
2019-06-23 08:57:35 +00:00
|
|
|
}
|
2020-05-05 09:05:28 +00:00
|
|
|
|
|
|
|
func (fs *FilerServer) KeepConnected(stream filer_pb.SeaweedFiler_KeepConnectedServer) error {
|
|
|
|
|
|
|
|
req, err := stream.Recv()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
clientName := fmt.Sprintf("%s:%d", req.Name, req.GrpcPort)
|
2020-05-08 09:47:22 +00:00
|
|
|
m := make(map[string]bool)
|
|
|
|
for _, tp := range req.Resources {
|
|
|
|
m[tp] = true
|
|
|
|
}
|
2020-05-05 09:05:28 +00:00
|
|
|
fs.brokersLock.Lock()
|
2020-05-08 09:47:22 +00:00
|
|
|
fs.brokers[clientName] = m
|
2020-05-05 09:05:28 +00:00
|
|
|
glog.V(0).Infof("+ broker %v", clientName)
|
|
|
|
fs.brokersLock.Unlock()
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
fs.brokersLock.Lock()
|
|
|
|
delete(fs.brokers, clientName)
|
|
|
|
glog.V(0).Infof("- broker %v: %v", clientName, err)
|
|
|
|
fs.brokersLock.Unlock()
|
|
|
|
}()
|
|
|
|
|
|
|
|
for {
|
|
|
|
if err := stream.Send(&filer_pb.KeepConnectedResponse{}); err != nil {
|
|
|
|
glog.V(0).Infof("send broker %v: %+v", clientName, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// println("replied")
|
|
|
|
|
|
|
|
if _, err := stream.Recv(); err != nil {
|
|
|
|
glog.V(0).Infof("recv broker %v: %v", clientName, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// println("received")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-05-08 09:47:22 +00:00
|
|
|
|
|
|
|
func (fs *FilerServer) LocateBroker(ctx context.Context, req *filer_pb.LocateBrokerRequest) (resp *filer_pb.LocateBrokerResponse, err error) {
|
|
|
|
|
|
|
|
resp = &filer_pb.LocateBrokerResponse{}
|
|
|
|
|
|
|
|
fs.brokersLock.Lock()
|
|
|
|
defer fs.brokersLock.Unlock()
|
|
|
|
|
|
|
|
var localBrokers []*filer_pb.LocateBrokerResponse_Resource
|
|
|
|
|
|
|
|
for b, m := range fs.brokers {
|
|
|
|
if _, found := m[req.Resource]; found {
|
|
|
|
resp.Found = true
|
|
|
|
resp.Resources = []*filer_pb.LocateBrokerResponse_Resource{
|
|
|
|
{
|
|
|
|
GrpcAddresses: b,
|
|
|
|
ResourceCount: int32(len(m)),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
localBrokers = append(localBrokers, &filer_pb.LocateBrokerResponse_Resource{
|
|
|
|
GrpcAddresses: b,
|
|
|
|
ResourceCount: int32(len(m)),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.Resources = localBrokers
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|