mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* weed: report the host transparent huge page policy at startup Go maps the heap with MADV_HUGEPAGE, so the host THP policy applies to a SeaweedFS process whether or not the operator asked for it, and the advice in the Go GC guide depends on the heap size. Operators had no way to see which mode a node actually runs in. Log enabled/defrag/khugepaged.max_ptes_none once at startup from the long-running commands, and print the Go toolchain in `weed version` so a support bundle identifies the runtime that produced the binary. Nothing changes the policy: THP is host-wide, and GODEBUG=disablethp=1 remains the only per-process control. Refs #5437 * build: declare Go 1.27.4, the toolchain the releases already use The 4.55 release binaries report go1.27.4 (`go version -m` on the published tarball), while go.mod still said 1.26.6, the Dockerfiles pinned golang:1.26, and the release workflows left the Go version to the action default of "the latest stable at build time". A source build, a container and a downloaded tarball therefore ran different toolchains from the same tag, and the next release could silently pick up another one. Set the go directive to 1.27.4 in the root module and in the four modules that build in CI, bump the 16 Dockerfiles, and pin goversion: 1.27.4 in the 16 release and dev action steps. `go mod tidy` now emits the two require blocks Go 1.27 expects; no dependency version changed. Go 1.27's gofmt realigns 8 files. * weed mini: report the THP policy after quieting stderr The startup line ran from the dispatch point before runMini applied quietMiniLogs, so every weed mini start on Linux printed it to stderr, which mini keeps for the welcome banner, warnings and errors. Log it from runMini after quietMiniLogs so it lands in the log file only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: report whether the Go heap can use huge pages The runtime advises only GC metadata with MADV_HUGEPAGE and leaves the heap arenas to the host default, so under enabled=madvise the heap stays on small pages. The log still printed go_heap_disabled=false there, which reads as "the heap uses THP". Report go_heap_thp, true only under enabled=always without GODEBUG=disablethp, and drop the struct comment that said the heap is mapped with MADV_HUGEPAGE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: count an inherited PR_SET_THP_DISABLE in go_heap_thp A launcher can disable THP for the process with prctl, and children inherit it, so enabled=always alone does not mean the heap gets huge pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: read GODEBUG disablethp the way the runtime does The runtime applies GODEBUG left to right, so with disablethp=1,disablethp=0 the heap keeps THP, while the helper stopped at the first disablethp=1. The helper also missed other nonzero values such as disablethp=2, which the runtime treats as disabled, and trimmed spaces around keys, which the runtime keeps. Take the last disablethp with an integer value, treat any nonzero value as disabled, and match keys exactly. The parser now takes the GODEBUG string, so it is tested without changing the environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: honor per-size THP policies in go_heap_thp Since Linux 6.8 each anonymous huge page size has its own policy in hugepages-<size>kB/enabled, and only "inherit" follows the top-level knob. A 64kB size set to "always" gives the unadvised heap huge pages under a top-level "madvise" or "never", and a 2048kB size set to "never" takes them away under "always", but the log judged only the top-level value. Read the per-size policies and report go_heap_thp=true when any size reaches the heap. Under a top-level "never", the "disabled by the host" line is now printed only when no size reaches the heap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: report go_heap_thp=unknown when the process setting is unreadable If PR_GET_THP_DISABLE fails, for example because a seccomp profile rejects it, the process THP setting is not known, but the log treated it as allowed and could print go_heap_thp=true. Print go_heap_thp=unknown in that case. It stays false when the host or GODEBUG already rules out heap huge pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * util: report go_heap_thp=unknown when a per-size THP policy is unreadable An unreadable hugepages-<size>kB/enabled was skipped, so the log could say the host disabled THP while that size allowed it. Keep it as an empty mode and report unknown unless a readable size already allows huge pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: take the Go version from go.mod in tests and releases posix-compliance pinned GO_VERSION 1.26 and built go 1.27.4 modules only through the GOTOOLCHAIN auto-switch; nine workflows used go-version ^1.26 and the kafka jobs ran in golang:1.26-alpine. Read the version from go.mod with go-version-file, as the other setup-go steps already do, moving checkout ahead of setup-go where it came after so the file exists. The posix report takes the version from the setup-go output. The release and dev builds pinned goversion 1.27.4 in 16 places. The pinned go-release-action reads the go directive when goversion is go.mod, so the binaries now follow go.mod without a second copy of the version. * weed: report the THP policy from every long-running command mount, worker, iam, master.follower, the filer sync/backup/remote/replicate daemons and the mq agent and kafka gateway keep serving after startup like the commands already listed; mount is likely where heap size matters most. fuse is not listed: its first process starts a child with the same arguments and waits, so logging at dispatch would print the line twice. It logs in runFuse just before handing over to runMount, which only the child reaches. --------- Co-authored-by: Konstantin Lebedev <whitefox@mayflower.work> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
228 lines
5.2 KiB
Go
228 lines
5.2 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"io"
|
|
"io/fs"
|
|
"os"
|
|
"strings"
|
|
"sync"
|
|
"text/template"
|
|
"time"
|
|
"unicode"
|
|
"unicode/utf8"
|
|
|
|
weed_server "github.com/seaweedfs/seaweedfs/weed/server"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
flag "github.com/seaweedfs/seaweedfs/weed/util/fla9"
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
"github.com/seaweedfs/seaweedfs/weed/command"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
|
|
)
|
|
|
|
var IsDebug *bool
|
|
|
|
var commands = command.Commands
|
|
|
|
var exitStatus = 0
|
|
var exitMu sync.Mutex
|
|
|
|
func setExitStatus(n int) {
|
|
exitMu.Lock()
|
|
if exitStatus < n {
|
|
exitStatus = n
|
|
}
|
|
exitMu.Unlock()
|
|
}
|
|
|
|
//go:embed static
|
|
var static embed.FS
|
|
|
|
func init() {
|
|
weed_server.StaticFS, _ = fs.Sub(static, "static")
|
|
|
|
flag.Var(&util.ConfigurationFileDirectory, "config_dir", "directory with toml configuration files")
|
|
}
|
|
|
|
func main() {
|
|
glog.MaxSize = 1024 * 1024 * 10
|
|
glog.MaxFileCount = 5
|
|
flag.Usage = usage
|
|
|
|
err := sentry.Init(sentry.ClientOptions{
|
|
SampleRate: 0.1,
|
|
EnableTracing: true,
|
|
TracesSampleRate: 0.1,
|
|
})
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "sentry.Init: %v", err)
|
|
}
|
|
// Flush buffered events before the program terminates.
|
|
// Set the timeout to the maximum duration the program can afford to wait.
|
|
defer sentry.Flush(2 * time.Second)
|
|
|
|
if command.AutocompleteMain(commands) {
|
|
return
|
|
}
|
|
|
|
flag.Parse()
|
|
|
|
args := flag.Args()
|
|
if len(args) < 1 {
|
|
usage()
|
|
}
|
|
|
|
if args[0] == "help" {
|
|
help(args[1:])
|
|
for _, cmd := range commands {
|
|
if len(args) >= 2 && cmd.Name() == args[1] && cmd.Run != nil {
|
|
fmt.Fprintf(os.Stderr, "Default Parameters:\n")
|
|
cmd.Flag.PrintDefaults()
|
|
}
|
|
}
|
|
return
|
|
}
|
|
if args[0] != command.GetFuseCommandName() {
|
|
util_http.InitGlobalHttpClient()
|
|
}
|
|
for _, cmd := range commands {
|
|
if cmd.Name() == args[0] && cmd.Run != nil {
|
|
cmd.Flag.Usage = func() { cmd.Usage() }
|
|
cmd.Flag.Parse(args[1:])
|
|
args = cmd.Flag.Args()
|
|
IsDebug = cmd.IsDebug
|
|
if isLongRunningCommand(cmd.Name()) {
|
|
util.LogTransparentHugePages()
|
|
}
|
|
if !cmd.Run(cmd, args) {
|
|
fmt.Fprintf(os.Stderr, "\n")
|
|
cmd.Flag.Usage()
|
|
fmt.Fprintf(os.Stderr, "Default Parameters:\n")
|
|
cmd.Flag.PrintDefaults()
|
|
// Command execution failed - general error
|
|
setExitStatus(1)
|
|
}
|
|
// A command can also record a failure without returning false.
|
|
setExitStatus(command.CommandExitStatus())
|
|
exit()
|
|
return
|
|
}
|
|
}
|
|
|
|
// Unknown command - syntax error
|
|
fmt.Fprintf(os.Stderr, "weed: unknown subcommand %q\nRun 'weed help' for usage.\n", args[0])
|
|
setExitStatus(2)
|
|
exit()
|
|
}
|
|
|
|
// isLongRunningCommand reports whether the command keeps serving after
|
|
// startup. Only those report the host THP policy, so one-shot tools stay quiet.
|
|
// mini and fuse report it themselves: mini after quieting stderr, fuse only in
|
|
// the child that serves the mount, not in the parent that starts it.
|
|
func isLongRunningCommand(name string) bool {
|
|
switch name {
|
|
case "server", "master", "master.follower", "volume", "filer", "s3", "iam",
|
|
"admin", "worker", "webdav", "sftp", "mount",
|
|
"filer.sync", "filer.backup", "filer.meta.backup", "filer.replicate",
|
|
"filer.remote.sync", "filer.remote.gateway",
|
|
"mq.broker", "mq.agent", "mq.kafka.gateway":
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
var usageTemplate = `
|
|
SeaweedFS: store billions of files and serve them fast!
|
|
|
|
Usage:
|
|
|
|
weed command [arguments]
|
|
|
|
The commands are:
|
|
{{range .}}{{if .Runnable}}
|
|
{{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}}
|
|
|
|
Use "weed help [command]" for more information about a command.
|
|
|
|
`
|
|
|
|
var helpTemplate = `{{if .Runnable}}Usage: weed {{.UsageLine}}
|
|
{{end}}
|
|
{{.Long}}
|
|
`
|
|
|
|
// tmpl executes the given template text on data, writing the result to w.
|
|
func tmpl(w io.Writer, text string, data interface{}) {
|
|
t := template.New("top")
|
|
t.Funcs(template.FuncMap{"trim": strings.TrimSpace, "capitalize": capitalize})
|
|
template.Must(t.Parse(text))
|
|
if err := t.Execute(w, data); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func capitalize(s string) string {
|
|
if s == "" {
|
|
return s
|
|
}
|
|
r, n := utf8.DecodeRuneInString(s)
|
|
return string(unicode.ToTitle(r)) + s[n:]
|
|
}
|
|
|
|
func printUsage(w io.Writer) {
|
|
tmpl(w, usageTemplate, commands)
|
|
}
|
|
|
|
func usage() {
|
|
printUsage(os.Stderr)
|
|
fmt.Fprintf(os.Stderr, "For Logging, use \"weed [logging_options] [command]\". The logging options are:\n")
|
|
flag.PrintDefaults()
|
|
// Invalid command line usage - syntax error
|
|
setExitStatus(2)
|
|
exit()
|
|
}
|
|
|
|
// help implements the 'help' command.
|
|
func help(args []string) {
|
|
if len(args) == 0 {
|
|
printUsage(os.Stdout)
|
|
// Success - help displayed correctly
|
|
return
|
|
}
|
|
if len(args) != 1 {
|
|
fmt.Fprintf(os.Stderr, "usage: weed help command\n\nToo many arguments given.\n")
|
|
// Invalid help usage - syntax error
|
|
setExitStatus(2)
|
|
exit()
|
|
}
|
|
|
|
arg := args[0]
|
|
|
|
for _, cmd := range commands {
|
|
if cmd.Name() == arg {
|
|
tmpl(os.Stdout, helpTemplate, cmd)
|
|
// Success - help for specific command displayed correctly
|
|
return
|
|
}
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "Unknown help topic %#q. Run 'weed help'.\n", arg)
|
|
// Unknown help topic - syntax error
|
|
setExitStatus(2)
|
|
exit()
|
|
}
|
|
|
|
var atexitFuncs []func()
|
|
|
|
func exit() {
|
|
for _, f := range atexitFuncs {
|
|
f()
|
|
}
|
|
// os.Exit below skips main's deferred flush.
|
|
sentry.Flush(2 * time.Second)
|
|
os.Exit(exitStatus)
|
|
}
|