package pluginworker import ( "context" "fmt" "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/plugin_pb" "github.com/seaweedfs/seaweedfs/weed/security" "github.com/seaweedfs/seaweedfs/weed/wdclient" "google.golang.org/grpc" ) // AdminFilerClient reaches one filer with the admin token, so files such as // filer.conf are read from that filer's own store, including chunk-backed ones. type AdminFilerClient struct { Address pb.ServerAddress GrpcDialOption grpc.DialOption } func (c *AdminFilerClient) WithFilerClient(streamingMode bool, fn func(filer_pb.SeaweedFilerClient) error) error { return pb.WithGrpcFilerClient(streamingMode, 0, c.Address, c.GrpcDialOption, security.FilerAdminToken, fn) } func (c *AdminFilerClient) AdjustedUrl(location *filer_pb.Location) string { return location.Url } func (c *AdminFilerClient) GetDataCenter() string { return "" } func (c *AdminFilerClient) GetLookupFileIdFunction() wdclient.LookupFileIdFunctionType { return filer.LookupFn(c) } // ClusterFilerAddresses returns the non-empty filer addresses of the cluster context. func ClusterFilerAddresses(clusterContext *plugin_pb.ClusterContext) []pb.ServerAddress { var filers []pb.ServerAddress for _, address := range clusterContext.GetFilerAddresses() { if address != "" { filers = append(filers, pb.ServerAddress(address)) } } return filers } // OneFilerPerStore keeps the first reachable filer of each store signature: // filers sharing a store share its rows, and a filer with its own store has // rows no other filer's job reaches. func OneFilerPerStore(ctx context.Context, filers []pb.ServerAddress, grpcDialOption grpc.DialOption, sender DetectionSender) []pb.ServerAddress { seen := make(map[int32]bool) var picked []pb.ServerAddress for _, address := range filers { var signature int32 err := pb.WithGrpcFilerClient(false, 0, address, grpcDialOption, security.FilerAdminToken, func(client filer_pb.SeaweedFilerClient) error { resp, err := client.GetFilerConfiguration(ctx, &filer_pb.GetFilerConfigurationRequest{}) if err != nil { return err } signature = resp.Signature return nil }) if err != nil { _ = sender.SendActivity(BuildDetectorActivity("filer_unreachable", fmt.Sprintf("filer %s: %v", address, err), nil)) continue } if seen[signature] { continue } seen[signature] = true picked = append(picked, address) } return picked }