mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-14 02:20:41 +02:00
* refactor(s3/lifecycle): drop Per-Run Time Limit knob; use scheduler's Execution Timeout "Per-Run Time Limit (minutes)" duplicated the admin scheduler's "Execution Timeout (s)" — both are wall-clock caps on the same Execute call, stacked via context.WithTimeout. Whichever was shorter won. Under defaults the scheduler's 90s timeout always clobbered the worker's 60-min cap, so the "Per-Run Time Limit" knob was effectively dead unless an operator also raised Execution Timeout, and operators had to keep two values in agreement. Remove the worker-side knob and declare a sane scheduler default on the handler descriptor: - WorkerConfigForm: nil (was: one section with one field) - Config.MaxRuntime removed; ParseConfig drops max_runtime_minutes - Handler no longer wraps ctx in context.WithTimeout(MaxRuntime); runCtx is just the ctx the scheduler passes - AdminRuntimeDefaults.ExecutionTimeoutSeconds = 3600 (1h) and JobTypeMaxRuntimeSeconds = 3600 — the scheduler's global 90s default would otherwise kill every real run Tests: - TestParseConfigDefaults loses the MaxRuntime check; new TestParseConfigIgnoresWorkerValues documents the contract - TestDescriptor_WorkerConfigFormIsAbsent pins that the form is gone so a future re-add forces a conscious revisit - TestDescriptor_AdminRuntimeDefaultsBoundExecutionTimeout pins the 1h default with a comment about the 90s scheduler floor * fix(s3/lifecycle): no per-pass timeout by default Lifecycle is a scheduled batch — its natural duration is "as long as today's events take." The 1h default ExecutionTimeoutSeconds from the previous commit was still a footgun: too low truncates legitimate large-bucket passes; too high makes the value meaningless. Set both ExecutionTimeoutSeconds and JobTypeMaxRuntimeSeconds to math.MaxInt32 (~68 years) to say "no timeout in practice" in a code-review-readable way. Operators who genuinely want a wall-clock cap can set one in the admin UI; the scheduler's context.WithTimeout machinery is unchanged (we just hand it an effectively-infinite duration). Note: the scheduler floors ExecutionTimeout at 90s (defaultScheduledExecutionTimeout in weed/admin/plugin/plugin_scheduler.go), so 0 doesn't mean "unlimited" — it clamps back to 90s. A literal math.MaxInt32 is the way to express the intent without touching the shared scheduler code. Test updated to pin math.MaxInt32 and document the rationale so a future tighter cap fails the test and forces conscious revisit.
96 lines
3.5 KiB
Go
96 lines
3.5 KiB
Go
package s3_lifecycle
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/plugin_pb"
|
|
)
|
|
|
|
func TestParseConfigDefaults(t *testing.T) {
|
|
cfg := ParseConfig(nil, nil)
|
|
if cfg.Workers != shardPipelineGoroutines {
|
|
t.Errorf("Workers default=%d, want %d", cfg.Workers, shardPipelineGoroutines)
|
|
}
|
|
}
|
|
|
|
func TestParseConfigIgnoresWorkerValues(t *testing.T) {
|
|
// Worker-side config form is currently empty. The old
|
|
// max_runtime_minutes knob duplicated the admin scheduler's
|
|
// Execution Timeout and was removed; anything in workerValues is
|
|
// now silently ignored. The single source of truth for the
|
|
// per-Execute wall-clock cap is AdminRuntimeDefaults.ExecutionTimeoutSeconds.
|
|
worker := map[string]*plugin_pb.ConfigValue{
|
|
"max_runtime_minutes": {Kind: &plugin_pb.ConfigValue_Int64Value{Int64Value: 120}},
|
|
}
|
|
cfg := ParseConfig(nil, worker)
|
|
if cfg.Workers != shardPipelineGoroutines {
|
|
t.Errorf("Workers default=%d, want %d", cfg.Workers, shardPipelineGoroutines)
|
|
}
|
|
}
|
|
|
|
func TestParseConfigMetaLogRetentionDefaultsToZero(t *testing.T) {
|
|
// Unset key keeps MetaLogRetention at 0, which runShard treats as
|
|
// "no retention info supplied" and falls back to maxTTL.
|
|
cfg := ParseConfig(nil, nil)
|
|
if cfg.MetaLogRetention != 0 {
|
|
t.Errorf("MetaLogRetention default=%v, want 0", cfg.MetaLogRetention)
|
|
}
|
|
}
|
|
|
|
func TestParseConfigMetaLogRetentionDaysConvertsToDuration(t *testing.T) {
|
|
admin := map[string]*plugin_pb.ConfigValue{
|
|
MetaLogRetentionDaysAdminKey: {Kind: &plugin_pb.ConfigValue_Int64Value{Int64Value: 7}},
|
|
}
|
|
cfg := ParseConfig(admin, nil)
|
|
if want := 7 * 24 * time.Hour; cfg.MetaLogRetention != want {
|
|
t.Errorf("MetaLogRetention=%v, want %v (7 days)", cfg.MetaLogRetention, want)
|
|
}
|
|
}
|
|
|
|
func TestParseConfigMetaLogRetentionNegativeStaysZero(t *testing.T) {
|
|
// A negative declaration is nonsense; stay at 0 so runShard's
|
|
// fallback applies rather than producing a negative window.
|
|
admin := map[string]*plugin_pb.ConfigValue{
|
|
MetaLogRetentionDaysAdminKey: {Kind: &plugin_pb.ConfigValue_Int64Value{Int64Value: -3}},
|
|
}
|
|
cfg := ParseConfig(admin, nil)
|
|
if cfg.MetaLogRetention != 0 {
|
|
t.Errorf("negative MetaLogRetention should stay 0, got %v", cfg.MetaLogRetention)
|
|
}
|
|
}
|
|
|
|
func TestParseConfigWalkerIntervalDefaultsToZero(t *testing.T) {
|
|
// Unset key keeps WalkerInterval at 0 so dailyrun.runShard fires the
|
|
// walker every pass (the pre-throttle behavior the s3tests fast
|
|
// driver and the in-repo integration tests rely on).
|
|
cfg := ParseConfig(nil, nil)
|
|
if cfg.WalkerInterval != 0 {
|
|
t.Errorf("WalkerInterval default=%v, want 0", cfg.WalkerInterval)
|
|
}
|
|
}
|
|
|
|
func TestParseConfigWalkerIntervalMinutesConvertsToDuration(t *testing.T) {
|
|
admin := map[string]*plugin_pb.ConfigValue{
|
|
WalkerIntervalMinutesAdminKey: {Kind: &plugin_pb.ConfigValue_Int64Value{Int64Value: 90}},
|
|
}
|
|
cfg := ParseConfig(admin, nil)
|
|
if want := 90 * time.Minute; cfg.WalkerInterval != want {
|
|
t.Errorf("WalkerInterval=%v, want %v", cfg.WalkerInterval, want)
|
|
}
|
|
}
|
|
|
|
func TestParseConfigWalkerIntervalNegativeStaysZero(t *testing.T) {
|
|
// Negative declarations stay at 0 so the worker keeps "fire every
|
|
// pass" rather than treating the negative as past-due (which would
|
|
// fire every pass anyway — but via a less obvious code path that
|
|
// future readers would have to trace).
|
|
admin := map[string]*plugin_pb.ConfigValue{
|
|
WalkerIntervalMinutesAdminKey: {Kind: &plugin_pb.ConfigValue_Int64Value{Int64Value: -10}},
|
|
}
|
|
cfg := ParseConfig(admin, nil)
|
|
if cfg.WalkerInterval != 0 {
|
|
t.Errorf("negative WalkerInterval should stay 0, got %v", cfg.WalkerInterval)
|
|
}
|
|
}
|