mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-30 04:37:07 +00:00
* wdclient: bound the wait for a master leader by the caller's context WithClient waited on GetMaster with context.Background(), so a caller that arrived while no master leader was known parked in a 200ms poll loop until one appeared, whatever deadline it had already set on the RPC. Each retry above it then left another goroutine in the same wait. Take the context in WithClient and WithClientCustomGetMaster and hand it to GetMaster, and stop the retry loop once it is done. The dial keeps context.Background(): fn brings its own RPC context, so a cancellation seen here cannot be attributed to the shared connection. Call sites pass whatever they hold: the request context in the filer's CollectionList, DeleteCollection and Statistics handlers and in the credential store's propagation, the operation context in the shell's s3.bucket.delete and the kafka gateway's broker and filer discovery, and context.Background() where there is none - the shell commands, the admin dashboard wrapper, and the exclusive locker's initial lease. The locker's release keeps its own uncancelled context so a slow unlock cannot turn into a ghost lock. Claude-Session: https://claude.ai/code/session_01BjDWtZsCoZY6x4pdDmGWxU * wdclient: test that WithClient gives up with the caller's context Claude-Session: https://claude.ai/code/session_01BjDWtZsCoZY6x4pdDmGWxU * wdclient: cut the master retry backoff short when the caller gives up util.Retry sleeps unconditionally between attempts, so a transient error arriving just before the caller's deadline still cost it a full backoff step. Use the context-aware util.RetryWithBackoff, the same helper the volume lookup in this file already uses. Two call sites went with it: the shell's lock-holder lookup builds its three second bound before WithClient so it also covers finding the leader, as its comment already promised, and the filer's post-delete collection cleanup goes back to an uncancelled context - the entry is already gone, so a caller that hung up must not leave the collection behind. Claude-Session: https://claude.ai/code/session_01BjDWtZsCoZY6x4pdDmGWxU * wdclient: test that a cancel during backoff ends the retry Claude-Session: https://claude.ai/code/session_01BjDWtZsCoZY6x4pdDmGWxU
179 lines
5.3 KiB
Go
179 lines
5.3 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandClusterPs{})
|
|
}
|
|
|
|
type commandClusterPs struct {
|
|
}
|
|
|
|
func (c *commandClusterPs) Name() string {
|
|
return "cluster.ps"
|
|
}
|
|
|
|
func (c *commandClusterPs) Help() string {
|
|
return `check current cluster process status
|
|
|
|
cluster.ps
|
|
|
|
`
|
|
}
|
|
|
|
func (c *commandClusterPs) HasTag(CommandTag) bool {
|
|
return false
|
|
}
|
|
|
|
func (c *commandClusterPs) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
clusterPsCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
if err = clusterPsCommand.Parse(args); err != nil {
|
|
return nil
|
|
}
|
|
|
|
listClusterNodes := func(clientType string) ([]*master_pb.ListClusterNodesResponse_ClusterNode, error) {
|
|
var nodes []*master_pb.ListClusterNodesResponse_ClusterNode
|
|
err := commandEnv.MasterClient.WithClient(context.Background(), false, func(client master_pb.SeaweedClient) error {
|
|
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
|
ClientType: clientType,
|
|
FilerGroup: *commandEnv.option.FilerGroup,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
nodes = resp.ClusterNodes
|
|
return nil
|
|
})
|
|
return nodes, err
|
|
}
|
|
|
|
filerNodes, err := listClusterNodes(cluster.FilerType)
|
|
if err != nil {
|
|
return
|
|
}
|
|
mqBrokerNodes, err := listClusterNodes(cluster.BrokerType)
|
|
if err != nil {
|
|
return
|
|
}
|
|
s3Nodes, err := listClusterNodes(cluster.S3Type)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if len(mqBrokerNodes) > 0 {
|
|
fmt.Fprintf(writer, "* message queue brokers %d\n", len(mqBrokerNodes))
|
|
for _, node := range mqBrokerNodes {
|
|
fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
|
|
if node.DataCenter != "" {
|
|
fmt.Fprintf(writer, " DataCenter: %v\n", node.DataCenter)
|
|
}
|
|
if node.Rack != "" {
|
|
fmt.Fprintf(writer, " Rack: %v\n", node.Rack)
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(s3Nodes) > 0 {
|
|
fmt.Fprintf(writer, "* s3 servers %d\n", len(s3Nodes))
|
|
for _, node := range s3Nodes {
|
|
fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
|
|
if node.DataCenter != "" {
|
|
fmt.Fprintf(writer, " DataCenter: %v\n", node.DataCenter)
|
|
}
|
|
if node.Rack != "" {
|
|
fmt.Fprintf(writer, " Rack: %v\n", node.Rack)
|
|
}
|
|
}
|
|
}
|
|
|
|
filerSignatures := make(map[*master_pb.ListClusterNodesResponse_ClusterNode]int32)
|
|
fmt.Fprintf(writer, "* filers %d\n", len(filerNodes))
|
|
for _, node := range filerNodes {
|
|
fmt.Fprintf(writer, " * %s (%v) %v\n", node.Address, node.Version, time.Unix(0, node.CreatedAtNs).UTC())
|
|
if node.DataCenter != "" {
|
|
fmt.Fprintf(writer, " DataCenter: %v\n", node.DataCenter)
|
|
}
|
|
if node.Rack != "" {
|
|
fmt.Fprintf(writer, " Rack: %v\n", node.Rack)
|
|
}
|
|
pb.WithFilerClient(false, 0, pb.ServerAddress(node.Address), commandEnv.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
|
resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{})
|
|
if err == nil {
|
|
if resp.FilerGroup != "" {
|
|
fmt.Fprintf(writer, " filer group: %s\n", resp.FilerGroup)
|
|
}
|
|
fmt.Fprintf(writer, " signature: %d\n", resp.Signature)
|
|
filerSignatures[node] = resp.Signature
|
|
} else {
|
|
fmt.Fprintf(writer, " failed to connect: %v\n", err)
|
|
}
|
|
return err
|
|
})
|
|
}
|
|
for _, node := range filerNodes {
|
|
pb.WithFilerClient(false, 0, pb.ServerAddress(node.Address), commandEnv.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
|
fmt.Fprintf(writer, "* filer %s metadata sync time\n", node.Address)
|
|
selfSignature := filerSignatures[node]
|
|
for peer, peerSignature := range filerSignatures {
|
|
if selfSignature == peerSignature {
|
|
continue
|
|
}
|
|
if resp, err := client.KvGet(context.Background(), &filer_pb.KvGetRequest{Key: filer.GetPeerMetaOffsetKey(peerSignature)}); err == nil && len(resp.Value) == 8 {
|
|
lastTsNs := int64(util.BytesToUint64(resp.Value))
|
|
fmt.Fprintf(writer, " %s: %v\n", peer.Address, time.Unix(0, lastTsNs).UTC())
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
// collect volume servers
|
|
var volumeServers []pb.ServerAddress
|
|
t, _, err := collectTopologyInfo(commandEnv, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, dc := range t.DataCenterInfos {
|
|
for _, r := range dc.RackInfos {
|
|
for _, dn := range r.DataNodeInfos {
|
|
volumeServers = append(volumeServers, pb.NewServerAddressFromDataNode(dn))
|
|
}
|
|
}
|
|
}
|
|
|
|
fmt.Fprintf(writer, "* volume servers %d\n", len(volumeServers))
|
|
for _, dc := range t.DataCenterInfos {
|
|
fmt.Fprintf(writer, " * data center: %s\n", dc.Id)
|
|
for _, r := range dc.RackInfos {
|
|
fmt.Fprintf(writer, " * rack: %s\n", r.Id)
|
|
for _, dn := range r.DataNodeInfos {
|
|
pb.WithVolumeServerClient(false, pb.NewServerAddressFromDataNode(dn), commandEnv.option.GrpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
|
|
resp, err := client.VolumeServerStatus(context.Background(), &volume_server_pb.VolumeServerStatusRequest{})
|
|
if err == nil {
|
|
fmt.Fprintf(writer, " * %s (%v)\n", dn.Id, resp.Version)
|
|
}
|
|
return err
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|