diff --git a/seaweed-block/cmd/blockvolume/chunk_remote.go b/seaweed-block/cmd/blockvolume/chunk_remote.go index e4a04a8f08..6721fc1a84 100644 --- a/seaweed-block/cmd/blockvolume/chunk_remote.go +++ b/seaweed-block/cmd/blockvolume/chunk_remote.go @@ -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 || diff --git a/seaweed-block/cmd/blockvolume/host_limit_test.go b/seaweed-block/cmd/blockvolume/host_limit_test.go new file mode 100644 index 0000000000..939050f42e --- /dev/null +++ b/seaweed-block/cmd/blockvolume/host_limit_test.go @@ -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) + } + } +} diff --git a/seaweed-block/core/hostlimit/limiter.go b/seaweed-block/core/hostlimit/limiter.go index 99ea3d938a..1313654f15 100644 --- a/seaweed-block/core/hostlimit/limiter.go +++ b/seaweed-block/core/hostlimit/limiter.go @@ -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{})}