mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
* worker: share the one-filer-per-store selection with other filer jobs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: add a meta_log_purge job that keeps the log past every TTL The job deletes whole metadata log days once per filer store, keeping every day that the longest filer.conf TTL, the longest S3 lifecycle rule, a registered retention floor or a running replay job's cursor still needs. A floor input that cannot be read stops the run before anything is deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: register meta_log_purge in the lifecycle lane Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * maintenance: stop purging the metadata log from the default scripts The meta_log_purge job now deletes old log days, keeping what TTLs, lifecycle rules and replay jobs still need. fs.log.purge stays for manual use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: let an idle filer_ttl rule's read position release the log filer_ttl no longer needs events up to read_ns, and an idle rule keeps an old ts_ns while read_ns advances, so the floor follows the later of the two. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: cap min_retention_days so a huge value cannot overflow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: show the min_retention_days limit in the admin form Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: give a registered retention floor the store's filer client A floor that only gets a context cannot tell which cluster or store it answers for, so it cannot ask that cluster's master or read the store's own settings. Pass the filer client the job already holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: keep the log an unfinished lifecycle walk will replay A cold-start or recovery walk that resumes across runs rewinds its shard cursor to the walk's start minus the longest lifecycle TTL once it completes. Until then only its walk checkpoint records that start, so a walk running for more than a day let the purge delete the creation events the rewound replay reads. A checkpoint with buckets done or partly walked now holds the floor at started_ns minus that TTL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: hold the walk start until the checkpoint goes stale A walk clears its checkpoint in finish() before each of its shards saves the rewound cursor, so a purge scan that read the old shard cursor and then the cleared checkpoint saw neither. A cleared checkpoint keeps started_ns, so every live checkpoint now holds the floor at its start minus the longest lifecycle TTL. A finished one stops holding once it has not been saved for cursorStaleAfter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: read walk checkpoints before the shard cursors they rewind A purge scan that read a shard cursor, then a checkpoint that a later walk had already replaced, saw neither the earlier walk's hold nor the rewind its shards saved. A walk replaces its checkpoint only after the previous walk's rewind is on disk, so reading the checkpoints first always sees one of the two. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * lifecycle: save a fresh walk's checkpoint at its first progress A walk that progressed during its first save interval and then stalled for more than a day had no checkpoint on disk, so the metadata log purge saw nothing holding the days its completion replays. A fresh walk now saves on its first finished entry or bucket; a resumed walk already has its record on disk and keeps the interval. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * lifecycle: rewrite an unchanged shard cursor so its mtime stays fresh A shard stuck on RETRY_LATER saved identical bytes each pass, and SaveInsideFiler skips identical content, so the file's mtime aged past the meta log purge's staleness cutoff while the shard still needed it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: keep the log day a reader from the cursor lists first Log files are named for their flush start, so a file from just before midnight holds events after a cursor just past it. The reader backs off one flush interval before choosing its first day; the purge now does too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: stop the meta log purge on an unreadable lifecycle policy LoadCompileInputs reports a bucket whose lifecycle XML does not parse separately from its error, so the purge used the shorter floors and deleted days that bucket's rules may need once the policy is fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: read shard cursors with the replay's loader in the meta log purge A shard cursor the replay refuses, such as an empty object, decoded as a zero position and released the purge; it now stops the run instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: saturate the meta log purge's TTL plus a day A lifecycle TTL near the largest duration wrapped negative once a day was added, so the purge fell back to the shorter floors; the walk hold at started_ns minus that TTL likewise dropped below zero and was lost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: leave disabled lifecycle rules out of the meta log purge floor AllActivePriorStates activates every compiled rule, so a disabled rule still held the log for its TTL, and disabling it could not release it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * worker: compute the meta log purge floor in SafeKeepFrom Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: fs.log.purge keeps the logs the meta log purge floor needs unless -force Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: run the fs.log.purge floor test without a master client Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
143 lines
4.6 KiB
Go
143 lines
4.6 KiB
Go
package plugin
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// SchedulerLane identifies an independent scheduling track. Each lane runs
|
|
// its own goroutine and maintains its own detection timing so that
|
|
// workloads in different lanes never block each other.
|
|
type SchedulerLane string
|
|
|
|
const (
|
|
// LaneDefault handles volume management operations (vacuum, balance,
|
|
// erasure coding) and admin scripts. It is the fallback lane for any
|
|
// job type that is not explicitly mapped elsewhere.
|
|
LaneDefault SchedulerLane = "default"
|
|
|
|
// LaneIceberg handles table-bucket Iceberg compaction and maintenance.
|
|
LaneIceberg SchedulerLane = "iceberg"
|
|
|
|
// LaneLifecycle handles S3 object store lifecycle management
|
|
// (expiration, transition, abort incomplete multipart uploads).
|
|
LaneLifecycle SchedulerLane = "lifecycle"
|
|
|
|
// LaneLance handles table-bucket Lance maintenance: fragment compaction,
|
|
// index optimization and version cleanup.
|
|
LaneLance SchedulerLane = "lance"
|
|
)
|
|
|
|
// AllLanes returns every defined scheduler lane in a stable order.
|
|
func AllLanes() []SchedulerLane {
|
|
return []SchedulerLane{LaneDefault, LaneIceberg, LaneLifecycle, LaneLance}
|
|
}
|
|
|
|
// laneIdleSleep maps each lane to its default idle sleep duration.
|
|
// Each lane can sleep for a different amount when no work is detected,
|
|
// independent of the per-job-type DetectionInterval.
|
|
var laneIdleSleep = map[SchedulerLane]time.Duration{
|
|
LaneDefault: 61 * time.Second,
|
|
LaneIceberg: 61 * time.Second,
|
|
LaneLifecycle: 5 * time.Minute,
|
|
LaneLance: 61 * time.Second,
|
|
}
|
|
|
|
// laneRequiresLock maps each lane to whether its job types must be
|
|
// serialised and run under the shared cluster admin lock. The default
|
|
// lane needs this because volume-management operations share global
|
|
// state; the lock is taken around each detection and each job so manual
|
|
// shell operations can interleave. Other lanes run each job type
|
|
// independently without the lock.
|
|
var laneRequiresLock = map[SchedulerLane]bool{
|
|
LaneDefault: true,
|
|
LaneIceberg: false,
|
|
LaneLifecycle: false,
|
|
// Lance maintenance rewrites files inside one table and shares no global
|
|
// state, so it has no more need of the cluster admin lock than Iceberg does.
|
|
LaneLance: false,
|
|
}
|
|
|
|
// LaneRequiresLock returns true if the given lane serialises its job types
|
|
// and runs them under the cluster admin lock. Unknown lanes default to true.
|
|
func LaneRequiresLock(lane SchedulerLane) bool {
|
|
if v, ok := laneRequiresLock[lane]; ok {
|
|
return v
|
|
}
|
|
return true
|
|
}
|
|
|
|
// LaneIdleSleep returns the idle sleep duration for the given lane,
|
|
// falling back to defaultSchedulerIdleSleep if the lane is unknown.
|
|
func LaneIdleSleep(lane SchedulerLane) time.Duration {
|
|
if d, ok := laneIdleSleep[lane]; ok {
|
|
return d
|
|
}
|
|
return defaultSchedulerIdleSleep
|
|
}
|
|
|
|
// jobTypeLaneMap is the hardcoded mapping from job type to scheduler lane.
|
|
// Job types not present here are assigned to LaneDefault.
|
|
var jobTypeLaneMap = map[string]SchedulerLane{
|
|
// Volume management (default lane)
|
|
"vacuum": LaneDefault,
|
|
"volume_balance": LaneDefault,
|
|
"ec_balance": LaneDefault,
|
|
"erasure_coding": LaneDefault,
|
|
"admin_script": LaneDefault,
|
|
|
|
// Iceberg table maintenance
|
|
"iceberg_maintenance": LaneIceberg,
|
|
|
|
// S3 lifecycle management
|
|
"s3_lifecycle": LaneLifecycle,
|
|
"filer_ttl": LaneLifecycle,
|
|
"meta_log_purge": LaneLifecycle,
|
|
|
|
// Lance table maintenance. Without these the job types fall back to the
|
|
// default lane, which serialises everything under the cluster admin lock
|
|
// and would queue a compaction behind volume balancing.
|
|
"lance_compact": LaneLance,
|
|
"lance_optimize_indices": LaneLance,
|
|
"lance_cleanup_versions": LaneLance,
|
|
"lance_vector_index": LaneLance,
|
|
"lance_metadata_index": LaneLance,
|
|
}
|
|
|
|
// JobTypeLane returns the scheduler lane for the given job type.
|
|
// Unknown job types are assigned to LaneDefault.
|
|
func JobTypeLane(jobType string) SchedulerLane {
|
|
if lane, ok := jobTypeLaneMap[jobType]; ok {
|
|
return lane
|
|
}
|
|
return LaneDefault
|
|
}
|
|
|
|
// LaneJobTypes returns the set of known job types assigned to the given lane.
|
|
func LaneJobTypes(lane SchedulerLane) []string {
|
|
var result []string
|
|
for jobType, l := range jobTypeLaneMap {
|
|
if l == lane {
|
|
result = append(result, jobType)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
// schedulerLaneState holds the per-lane runtime state used by the scheduler.
|
|
type schedulerLaneState struct {
|
|
lane SchedulerLane
|
|
wakeCh chan struct{}
|
|
|
|
loopMu sync.Mutex
|
|
loop schedulerLoopState
|
|
}
|
|
|
|
// newLaneState creates a schedulerLaneState for the given lane.
|
|
func newLaneState(lane SchedulerLane) *schedulerLaneState {
|
|
return &schedulerLaneState{
|
|
lane: lane,
|
|
wakeCh: make(chan struct{}, 1),
|
|
}
|
|
}
|