mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-07-25 01:22:39 +00:00
* Add GitHub Actions workflow for codespell on master * Add rudimentary codespell config * Tune codespell config: skip generated code, ignore camelCase, whitelist domain terms Add camelCase/PascalCase regex to ignore common Go/Rust/JS identifiers like allLocations, publishErr, ReadInside, FlushInterval. Also skip templ-generated *_templ.go files, and whitelist a handful of short/domain-specific words (visibles, fo, te, ser, bject, unparseable, keep-alives, tread, anc, ue) that show up as false positives across the tree. Co-Authored-By: Claude Code 2.1.217 / Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Fix ambiguous typos and protect false positives Fixes typos that codespell reports with multiple candidate suggestions (so `codespell -w` cannot auto-apply them), plus one inline pragma and one config entry to protect legitimate identifiers. Manual fixes (single correct answer chosen from context): - pattens -> patterns (5x) in filer/upload/shell flag help strings - finded -> found (2x) in tarantool storage.lua comment - spacify -> specify (2x) in helm chart values.yaml comment - wether -> whether in skiplist.go docstring - simpe -> simple in mq schema test case name False-positive protection: - Add `//codespell:ignore` next to `source GET's` (possessive of HTTP verb) in s3api_object_handlers_copy_stream.go - Whitelist `auther` in .codespellrc — it's a local variable meaning "authenticator" in weed/security/tls.go, not a typo of "author". Co-Authored-By: Claude Code 2.1.217 / Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Extend codespell ignore list: .git-meta path and thirdparty groupId Also skip `.git-meta` (scratch dir for commit messages that may contain typo words verbatim) and whitelist `thirdparty` — it appears as the literal Maven groupId `org.apache.hadoop.thirdparty` in hdfs3 poms and cannot be renamed. Co-Authored-By: Claude Code 2.1.217 / Claude Opus 4.7 (1M context) <noreply@anthropic.com> * [DATALAD RUNCMD] Fix non-ambiguous typos with codespell -w Auto-applied fixes to the 44 remaining single-suggestion typos across docs, comments, log messages, tests, config, and one Java pom. === Do not change lines below === { "chain": [], "cmd": "uvx codespell -w", "exit": 0, "extra_inputs": [], "inputs": [], "outputs": [], "pwd": "." } ^^^ Do not change lines above ^^^ * Revert breaking codespell fixes; whitelist unknwon and atleast Two of the auto-applied `codespell -w` fixes were false positives that would break the build/tests: - go.mod: `github.com/unknwon/goconfig` is a real Go module path — the upstream author's GitHub handle is literally `unknwon`. Renaming to `unknown` would fail dependency resolution. - test/benchmark/fuse_db/bin/{sqlite_verify.py,run_mysql.sh,run_sqlite.sh}: `atleast` is a literal CLI mode value (a string constant compared and passed as a positional argument). Rewriting to `at least` splits it into two arguments and breaks the mode check. Reverted those files and whitelisted both words in .codespellrc so future runs won't re-suggest the same broken fixes. Co-Authored-By: Claude Code 2.1.217 / Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Code 2.1.217 / Claude Opus 4.7 (1M context) <noreply@anthropic.com>
175 lines
4.8 KiB
Go
175 lines
4.8 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandVolumeServerState{})
|
|
}
|
|
|
|
type commandVolumeServerState struct {
|
|
env *CommandEnv
|
|
writer io.Writer
|
|
}
|
|
|
|
func (c *commandVolumeServerState) Name() string {
|
|
return "volumeServer.state"
|
|
}
|
|
|
|
func (c *commandVolumeServerState) Help() string {
|
|
return `query/update volume server state settings
|
|
|
|
volumeServer.state [-nodes <host:port>] [..state flags...]
|
|
|
|
This command display volume server state flags for the provided
|
|
list of nodes; if empty, all nodes in the topology are queried.
|
|
For example:
|
|
|
|
volumeServer.state --nodes 192.168.10.111:9000,192.168.10.112:9000
|
|
|
|
Additionally, if any flags are provided, these are applied
|
|
to the selected node(s). The command will display the resulting
|
|
state for each node *after* the state is updated. For example...
|
|
|
|
volumeServer.state --nodes 192.168.10.111:9000 --maintenanceOn
|
|
|
|
...will set the specified volume server to maintenance mode.
|
|
|
|
`
|
|
}
|
|
|
|
func (c *commandVolumeServerState) HasTag(CommandTag) bool {
|
|
return false
|
|
}
|
|
|
|
func (c *commandVolumeServerState) write(format string, a ...any) {
|
|
format = strings.TrimRight(format, " ")
|
|
if len(format) == 0 {
|
|
format = "\n"
|
|
}
|
|
fmt.Fprintf(c.writer, format, a...)
|
|
|
|
last := format[len(format)-1:]
|
|
if last != "\n" && last != "\r" {
|
|
fmt.Fprint(c.writer, "\n")
|
|
}
|
|
}
|
|
|
|
func (c *commandVolumeServerState) bool2Str(b bool) string {
|
|
if b {
|
|
return "yes"
|
|
}
|
|
return "no"
|
|
}
|
|
|
|
func (c *commandVolumeServerState) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
vsStateCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
nodesStr := vsStateCommand.String("nodes", "", "comma-separated list of volume servers <host>:<port> (optional)")
|
|
maintenanceOn := vsStateCommand.Bool("maintenanceOn", false, "enables maintenance mode on the server")
|
|
maintenanceOff := vsStateCommand.Bool("maintenanceOff", false, "disables maintenance mode on the server")
|
|
if err = vsStateCommand.Parse(args); err != nil {
|
|
return err
|
|
}
|
|
|
|
if *maintenanceOn && *maintenanceOff {
|
|
return fmt.Errorf("--maintenanceOn and --maintenanceOff are mutually exclusive")
|
|
}
|
|
|
|
volumeServerAddrs := []pb.ServerAddress{}
|
|
if *nodesStr != "" {
|
|
for _, addr := range strings.Split(*nodesStr, ",") {
|
|
volumeServerAddrs = append(volumeServerAddrs, pb.ServerAddress(addr))
|
|
}
|
|
} else {
|
|
dns, err := collectDataNodes(commandEnv, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, dn := range dns {
|
|
volumeServerAddrs = append(volumeServerAddrs, pb.ServerAddress(dn.Address))
|
|
}
|
|
}
|
|
slices.Sort(volumeServerAddrs)
|
|
if len(volumeServerAddrs) == 0 {
|
|
return fmt.Errorf("no volume servers specified")
|
|
}
|
|
|
|
c.env = commandEnv
|
|
c.writer = writer
|
|
|
|
for _, addr := range volumeServerAddrs {
|
|
state, err := c.getVolumeServerState(addr)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to load state from %v: %v", addr, err)
|
|
}
|
|
|
|
stateOrig := &volume_server_pb.VolumeServerState{}
|
|
proto.Merge(stateOrig, state)
|
|
|
|
// apply updates, if any
|
|
switch {
|
|
case *maintenanceOn:
|
|
state.Maintenance = true
|
|
case *maintenanceOff:
|
|
state.Maintenance = false
|
|
}
|
|
|
|
// update volume server state if settings changed
|
|
if !proto.Equal(state, stateOrig) {
|
|
state, err = c.setVolumeServerState(addr, state)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to update state for %v: %v", addr, err)
|
|
}
|
|
}
|
|
|
|
c.write("%v\t -> Maintenance mode: %s\n", addr.String(), c.bool2Str(state.GetMaintenance()))
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (c *commandVolumeServerState) getVolumeServerState(volumeServerAddress pb.ServerAddress) (*volume_server_pb.VolumeServerState, error) {
|
|
var state *volume_server_pb.VolumeServerState
|
|
|
|
err := operation.WithVolumeServerClient(false, volumeServerAddress, c.env.option.GrpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
|
|
res, err := volumeServerClient.GetState(context.Background(), &volume_server_pb.GetStateRequest{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
state = res.GetState()
|
|
return nil
|
|
})
|
|
|
|
return state, err
|
|
}
|
|
|
|
func (c *commandVolumeServerState) setVolumeServerState(volumeServerAddress pb.ServerAddress, state *volume_server_pb.VolumeServerState) (*volume_server_pb.VolumeServerState, error) {
|
|
var stateAfter *volume_server_pb.VolumeServerState
|
|
|
|
err := operation.WithVolumeServerClient(false, volumeServerAddress, c.env.option.GrpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
|
|
res, err := volumeServerClient.SetState(context.Background(), &volume_server_pb.SetStateRequest{
|
|
State: state,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
stateAfter = res.GetState()
|
|
return nil
|
|
})
|
|
|
|
return stateAfter, err
|
|
}
|