Files
seaweedfs/weed/parquet_pushdown/daemon/server.go
T
Chris Lu e181e2c035 parquet_pushdown(M0-C3): daemon bootstrap (config, filer client, server)
Add weed/parquet_pushdown/daemon, the host process for the
SeaweedParquetPushdown service:

- Config carries bind ip/port, filer addresses, trust mode, and the
  ConnectorTrustedAck flag that gates the dev-only connector-trusted
  trust mode (default refuses it; explicit ack required).
- filerClient probes the filer with GetFilerConfiguration at startup
  so bad endpoints fail fast, mirroring the iam command's pattern.
  Bounded by a 60s timeout; later milestones use the same client to
  read Parquet data and side-index blobs.
- server.go wires it together: load TLS, probe filer, build the
  Service, listen on (host, localhost) gRPC ports, register the
  service + reflection on each, install grace.OnInterrupt for
  GracefulStop, and Serve.

Run() returns an error so the calling weed pushdown command can
report startup failures instead of glog.Fatalf.
2026-04-25 13:40:45 -07:00

78 lines
2.4 KiB
Go

package daemon
import (
"context"
"fmt"
"net"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/parquet_pushdown"
"github.com/seaweedfs/seaweedfs/weed/pb"
pbpushdown "github.com/seaweedfs/seaweedfs/weed/pb/parquet_pushdown_pb"
"github.com/seaweedfs/seaweedfs/weed/security"
"github.com/seaweedfs/seaweedfs/weed/util"
"github.com/seaweedfs/seaweedfs/weed/util/grace"
)
// Run starts the pushdown daemon. It blocks until the gRPC server
// returns (graceful shutdown on SIGTERM, or error from Serve). Always
// validates the config first.
func Run(cfg Config) error {
if err := cfg.Validate(); err != nil {
return fmt.Errorf("pushdown config: %w", err)
}
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
// Probe the filer until reachable so we fail fast on bad config
// and emit a clear "waiting for filers" log otherwise. Bound the
// probe so the daemon doesn't sit forever if the operator hands
// in an unreachable filer.
probeCtx, probeCancel := context.WithTimeout(context.Background(), 60*time.Second)
defer probeCancel()
fc := newFilerClient(cfg.FilerAddresses, grpcDialOption)
if err := fc.waitUntilReachable(probeCtx); err != nil {
return fmt.Errorf("filer probe failed: %w", err)
}
svc := parquet_pushdown.New(parquet_pushdown.Options{
Version: cfg.Version,
TrustMode: cfg.TrustMode,
})
grpcL, localL, err := util.NewIpAndLocalListeners(cfg.IP, cfg.Port, 0)
if err != nil {
return fmt.Errorf("listen on grpc port %d: %w", cfg.Port, err)
}
grpcS := pb.NewGrpcServer()
pbpushdown.RegisterSeaweedParquetPushdownServer(grpcS, svc)
reflection.Register(grpcS)
grace.OnInterrupt(grpcS.GracefulStop)
if localL != nil {
localGrpcS := pb.NewGrpcServer()
pbpushdown.RegisterSeaweedParquetPushdownServer(localGrpcS, svc)
reflection.Register(localGrpcS)
grace.OnInterrupt(localGrpcS.GracefulStop)
go serve(localGrpcS, localL, "pushdown localhost")
}
glog.V(0).Infof("pushdown daemon listening on %s:%d (trust=%s)", cfg.IP, cfg.Port, cfg.TrustMode)
return serve(grpcS, grpcL, "pushdown")
}
func serve(s *grpc.Server, l net.Listener, label string) error {
if err := s.Serve(l); err != nil && err != grpc.ErrServerStopped {
glog.Errorf("%s server serve error: %v", label, err)
return err
}
return nil
}