mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
The change of this PR's 22 commits, carried onto current main as one commit (its base was 1884 commits behind). Fitted to main: - pacing: main's rule that fallback-only leases are not paced stays; a healthy lease is paced at the budget over the held normal and urgent slots (this PR's rule) instead of over the configured slot count. TestFallbackDoesNotUnpaceAHealthyLease keeps its property (a healthy lease beside a fallback lease is paced) with a 500 ms deadline, since a lone holder now gets the whole budget. - the cut loop keeps main's attempted hook and afterStaging (a failed attempt that staged new chunks retries at the next poll), with the ticket handling; the random retry delay is gone, as this PR intends. - imports and constants: neither side's removed ones return. - invariants: main's new rows and this PR's new and restated rows; the slot-wait row is this PR's (ticket order, the next poll). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
2.4 KiB
Go
58 lines
2.4 KiB
Go
package hostlimit
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// CheckLaunch refuses a host-limit configuration whose premises do not
|
|
// hold, before the process uses it. The directory must exist as a real
|
|
// directory, outside temporary directories that cleaners empty, not on a
|
|
// remote file system (kernel file locks and the host monotonic clock that
|
|
// orders tickets belong to one host), and a configuration already published
|
|
// there by other
|
|
// processes must equal this one. The premise that every process on the
|
|
// host uses the same directory cannot be checked from one process.
|
|
func CheckLaunch(c Config) error {
|
|
return checkLaunch(c, []string{"/tmp", "/var/tmp", "/dev/shm", os.TempDir()}, remoteFS)
|
|
}
|
|
|
|
func checkLaunch(c Config, tempRoots []string, remote func(string) (string, bool)) error {
|
|
if err := c.Validate(); err != nil {
|
|
return err
|
|
}
|
|
dir := filepath.Clean(c.Directory)
|
|
info, err := os.Lstat(dir)
|
|
if err != nil {
|
|
return fmt.Errorf("hostlimit: --host-limit-dir %s: %w", dir, err)
|
|
}
|
|
if !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
|
|
return fmt.Errorf("hostlimit: --host-limit-dir %s must be a directory, not a symlink or a file", dir)
|
|
}
|
|
for _, root := range tempRoots {
|
|
root = filepath.Clean(root)
|
|
if root != "" && root != "." && (dir == root || strings.HasPrefix(dir, root+string(filepath.Separator))) {
|
|
return fmt.Errorf("hostlimit: --host-limit-dir %s is under %s, which temporary-file cleaners empty", dir, root)
|
|
}
|
|
}
|
|
if fs, isRemote := remote(dir); isRemote {
|
|
return fmt.Errorf("hostlimit: --host-limit-dir %s is on %s, a remote file system; slot locks and ticket order need a file system local to this host: use a local directory (for example under /run or /var/lib)", dir, fs)
|
|
}
|
|
existing, err := os.ReadFile(filepath.Join(dir, "configuration.json"))
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
return fmt.Errorf("hostlimit: --host-limit-dir %s: %w", dir, err)
|
|
}
|
|
expected, _ := json.Marshal(c)
|
|
if string(existing) != string(expected) {
|
|
return fmt.Errorf("hostlimit: --host-limit-dir %s holds %s written with other host-limit flags (%s; this process: %s): every process on the host must use identical flags. After an upgrade that changed them, stop every process using the directory, remove %s, then start them again", dir, filepath.Join(dir, "configuration.json"), existing, expected, filepath.Join(dir, "configuration.json"))
|
|
}
|
|
return nil
|
|
}
|