mirror of
https://github.com/chrislusf/seaweedfs
synced 2024-07-06 09:07:08 +02:00
add dir list limit option
This commit is contained in:
parent
2ad45ca04f
commit
702ff48cda
|
@ -30,6 +30,7 @@ type FilerOptions struct {
|
||||||
disableDirListing *bool
|
disableDirListing *bool
|
||||||
maxMB *int
|
maxMB *int
|
||||||
secretKey *string
|
secretKey *string
|
||||||
|
dirListingLimit *int
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -45,6 +46,7 @@ func init() {
|
||||||
f.disableDirListing = cmdFiler.Flag.Bool("disableDirListing", false, "turn off directory listing")
|
f.disableDirListing = cmdFiler.Flag.Bool("disableDirListing", false, "turn off directory listing")
|
||||||
f.maxMB = cmdFiler.Flag.Int("maxMB", 32, "split files larger than the limit")
|
f.maxMB = cmdFiler.Flag.Int("maxMB", 32, "split files larger than the limit")
|
||||||
f.secretKey = cmdFiler.Flag.String("secure.secret", "", "secret to encrypt Json Web Token(JWT)")
|
f.secretKey = cmdFiler.Flag.String("secure.secret", "", "secret to encrypt Json Web Token(JWT)")
|
||||||
|
f.dirListingLimit = cmdFiler.Flag.Int("dirListLimit", 1000, "limit sub dir listing size")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdFiler = &Command{
|
var cmdFiler = &Command{
|
||||||
|
@ -86,12 +88,16 @@ func (fo *FilerOptions) start() {
|
||||||
|
|
||||||
masters := *f.masters
|
masters := *f.masters
|
||||||
|
|
||||||
fs, nfs_err := weed_server.NewFilerServer(defaultMux, publicVolumeMux,
|
fs, nfs_err := weed_server.NewFilerServer(defaultMux, publicVolumeMux, &weed_server.FilerOption{
|
||||||
strings.Split(masters, ","), *fo.collection,
|
Masters: strings.Split(masters, ","),
|
||||||
*fo.defaultReplicaPlacement, *fo.redirectOnRead, *fo.disableDirListing,
|
Collection: *fo.collection,
|
||||||
*fo.maxMB,
|
DefaultReplication: *fo.defaultReplicaPlacement,
|
||||||
*fo.secretKey,
|
RedirectOnRead: *fo.redirectOnRead,
|
||||||
)
|
DisableDirListing: *fo.disableDirListing,
|
||||||
|
MaxMB: *fo.maxMB,
|
||||||
|
SecretKey: *fo.secretKey,
|
||||||
|
DirListingLimit: *fo.dirListingLimit,
|
||||||
|
})
|
||||||
if nfs_err != nil {
|
if nfs_err != nil {
|
||||||
glog.Fatalf("Filer startup error: %v", nfs_err)
|
glog.Fatalf("Filer startup error: %v", nfs_err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (fs *FilerServer) LookupDirectoryEntry(ctx context.Context, req *filer_pb.L
|
||||||
|
|
||||||
func (fs *FilerServer) ListEntries(ctx context.Context, req *filer_pb.ListEntriesRequest) (*filer_pb.ListEntriesResponse, error) {
|
func (fs *FilerServer) ListEntries(ctx context.Context, req *filer_pb.ListEntriesRequest) (*filer_pb.ListEntriesResponse, error) {
|
||||||
|
|
||||||
entries, err := fs.filer.ListDirectoryEntries(filer2.FullPath(req.Directory), "", false, 1000)
|
entries, err := fs.filer.ListDirectoryEntries(filer2.FullPath(req.Directory), "", false, fs.option.DirListingLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,36 +13,33 @@ import (
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FilerServer struct {
|
type FilerOption struct {
|
||||||
masters []string
|
Masters []string
|
||||||
collection string
|
Collection string
|
||||||
defaultReplication string
|
DefaultReplication string
|
||||||
redirectOnRead bool
|
RedirectOnRead bool
|
||||||
disableDirListing bool
|
DisableDirListing bool
|
||||||
secret security.Secret
|
MaxMB int
|
||||||
filer *filer2.Filer
|
SecretKey string
|
||||||
maxMB int
|
DirListingLimit int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, masters []string, collection string,
|
type FilerServer struct {
|
||||||
replication string, redirectOnRead bool, disableDirListing bool,
|
option *FilerOption
|
||||||
maxMB int,
|
secret security.Secret
|
||||||
secret string,
|
filer *filer2.Filer
|
||||||
) (fs *FilerServer, err error) {
|
}
|
||||||
|
|
||||||
|
func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption) (fs *FilerServer, err error) {
|
||||||
fs = &FilerServer{
|
fs = &FilerServer{
|
||||||
masters: masters,
|
option: option,
|
||||||
collection: collection,
|
|
||||||
defaultReplication: replication,
|
|
||||||
redirectOnRead: redirectOnRead,
|
|
||||||
disableDirListing: disableDirListing,
|
|
||||||
maxMB: maxMB,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(masters) == 0 {
|
if len(option.Masters) == 0 {
|
||||||
glog.Fatal("master list is required!")
|
glog.Fatal("master list is required!")
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.filer = filer2.NewFiler(masters)
|
fs.filer = filer2.NewFiler(option.Masters)
|
||||||
|
|
||||||
go fs.filer.KeepConnectedToMaster()
|
go fs.filer.KeepConnectedToMaster()
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.IsDirectory() {
|
if entry.IsDirectory() {
|
||||||
if fs.disableDirListing {
|
if fs.option.DisableDirListing {
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (fs *FilerServer) handleSingleChunk(w http.ResponseWriter, r *http.Request,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if fs.redirectOnRead {
|
if fs.option.RedirectOnRead {
|
||||||
http.Redirect(w, r, urlString, http.StatusFound)
|
http.Redirect(w, r, urlString, http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,11 +65,11 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
replication := query.Get("replication")
|
replication := query.Get("replication")
|
||||||
if replication == "" {
|
if replication == "" {
|
||||||
replication = fs.defaultReplication
|
replication = fs.option.DefaultReplication
|
||||||
}
|
}
|
||||||
collection := query.Get("collection")
|
collection := query.Get("collection")
|
||||||
if collection == "" {
|
if collection == "" {
|
||||||
collection = fs.collection
|
collection = fs.option.Collection
|
||||||
}
|
}
|
||||||
|
|
||||||
if autoChunked := fs.autoChunk(w, r, replication, collection); autoChunked {
|
if autoChunked := fs.autoChunk(w, r, replication, collection); autoChunked {
|
||||||
|
|
|
@ -27,8 +27,8 @@ func (fs *FilerServer) autoChunk(w http.ResponseWriter, r *http.Request, replica
|
||||||
|
|
||||||
parsedMaxMB, _ := strconv.ParseInt(query.Get("maxMB"), 10, 32)
|
parsedMaxMB, _ := strconv.ParseInt(query.Get("maxMB"), 10, 32)
|
||||||
maxMB := int32(parsedMaxMB)
|
maxMB := int32(parsedMaxMB)
|
||||||
if maxMB <= 0 && fs.maxMB > 0 {
|
if maxMB <= 0 && fs.option.MaxMB > 0 {
|
||||||
maxMB = int32(fs.maxMB)
|
maxMB = int32(fs.option.MaxMB)
|
||||||
}
|
}
|
||||||
if maxMB <= 0 {
|
if maxMB <= 0 {
|
||||||
glog.V(4).Infoln("AutoChunking not enabled")
|
glog.V(4).Infoln("AutoChunking not enabled")
|
||||||
|
|
Loading…
Reference in a new issue