mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
fix: reject ignored or invalid host limiter configuration
This commit is contained in:
1 parent
fc0d75c07c
commit
76445f968e
3 files changed
+34
-2
No files matched your search
@@ -46,6 +46,13 @@ type chunkFlags struct {
|
||||
|
||||
func validateChunkFlags(f flags) error {
|
||||
c := f.chunk
|
||||
if c.hostLimit.Directory != "" {
|
||||
if err := c.hostLimit.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if c.hostLimit != (hostlimit.Config{}) && c.hostLimit != hostlimit.DefaultConfig("") {
|
||||
return errors.New("--host-limit-* settings require --host-limit-dir")
|
||||
}
|
||||
if f.durableImpl != "walstore-chunk" {
|
||||
if c.filer != "" || c.collection != "" || c.replication != "" || c.path != defaultChunkPath ||
|
||||
c.captureInterval != defaultChunkCaptureInterval || c.dirtyThreshold != defaultChunkDirtyThreshold ||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHostCutLimitFlags(t *testing.T) {
|
||||
base := append(phase150RequiredBlockvolumeArgs(), "--durable-root="+t.TempDir(), "--durable-impl=walstore-chunk", "--chunk-filer=x:1")
|
||||
dir := t.TempDir()
|
||||
args := append(append([]string{}, base...), "--host-limit-dir="+dir, "--host-limit-normal-slots=2", "--host-limit-urgent-slots=1")
|
||||
f, e := parseFlags(args)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if f.chunk.hostLimit.Directory != dir || f.chunk.hostLimit.NormalSlots != 2 || f.chunk.hostLimit.UrgentSlots != 1 {
|
||||
t.Fatal("lost host limits")
|
||||
}
|
||||
for _, extra := range [][]string{{"--host-limit-normal-slots=2"}, {"--host-limit-dir=" + dir, "--host-limit-normal-slots=0"}, {"--host-limit-dir=" + dir, "--host-limit-max-hold=-1s"}, {"--host-limit-dir=" + filepath.Join("relative", "pool")}} {
|
||||
a := append(append([]string{}, base...), extra...)
|
||||
if _, e = parseFlags(a); e == nil {
|
||||
t.Fatalf("accepted invalid limits: %v", extra)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ type Config struct {
|
||||
func DefaultConfig(dir string) Config {
|
||||
return Config{Directory: dir, NormalSlots: 3, UrgentSlots: 1, FillSlots: 2, IdleSlots: 1, PayloadBytes: 64 << 20, COWBytes: 1 << 30, BytesPerSecond: 64 << 20, FallbackVolumes: 200, MaxHold: 5 * time.Minute}
|
||||
}
|
||||
func (c Config) validate() error {
|
||||
func (c Config) Validate() error {
|
||||
if !filepath.IsAbs(c.Directory) || c.NormalSlots < 1 || c.UrgentSlots < 1 || c.FillSlots < 0 || c.IdleSlots < 0 || c.NormalSlots+c.UrgentSlots+c.FillSlots+c.IdleSlots > 256 || c.PayloadBytes <= 0 || c.COWBytes <= 0 || c.BytesPerSecond <= 0 || c.FallbackVolumes < 1 || c.FallbackVolumes > 65536 || c.MaxHold <= 0 {
|
||||
return errors.New("hostlimit: invalid configuration")
|
||||
}
|
||||
@@ -84,7 +84,7 @@ type Limiter struct {
|
||||
}
|
||||
|
||||
func New(c Config) (*Limiter, error) {
|
||||
if err := c.validate(); err != nil {
|
||||
if err := c.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l := &Limiter{cfg: c, live: map[uint64]*lease{}, wake: make(chan struct{}, 1), done: make(chan struct{})}
|
||||
|
||||
Reference in new issue
Block a user