Files
seaweedfs/weed/command/mini_vector.go
Chris LuandClaude Opus 5.5 a551b7c7e6 weed-vector: size the caches itself, drop the tuning, config-dir and CLI namespace flags (#12906)
* master, s3: an S3 gateway advertises its Lance Namespace port

The gateway registers with the master already; it now says which port its
Lance Namespace listens on, and ListClusterNodes returns it, so admin can
tell workers where the catalog is instead of each deployment configuring it.

* admin: tell workers where the Lance Namespace is

Each S3 gateway that serves a Lance Namespace is now in the cluster context
admin sends with every request, and a preview request carries the context
too, so a worker can be pointed at admin alone.

* seaweed-worker: take the filers and the Lance Namespace from admin

Admin names both with every request, as it does for the Go worker, so
weed-worker needs only --admin. --namespace is used when admin names no
namespace, as an admin or gateways from before they could do so name none.
--masters and --filer-group are accepted and ignored; the filer group is the
one the filers report.

* helm: weed-worker needs only the admin address

The Lance container no longer derives a namespace URL or passes the masters
and filer group; worker.namespaceUrl, when set, is the worker's fallback.

* s3: advertise the Lance port only once its listener has bound

A gateway whose Lance port was taken kept advertising it, so workers that
picked that gateway sent every Lance request to a port nobody served.
The listener now binds before the master registration, and the port
reaches the master only when the bind succeeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: stop waiting for the cluster context at the caller's deadline

The admin provider builds the context with context.Background(), so a
master outage held a preview, which now loads the context before it is
sent, past its own deadline. Loading the context now returns when the
caller's context ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* helm: keep giving the Lance worker its masters, group and namespace

A worker image pinned to 4.55 or older needs the masters and the
namespace and exits without them, and a 4.56 worker under an older admin
needs the namespace. The chart now passes all three through the
environment, which a 4.56 worker reads only when admin names nothing,
and the namespace again defaults to the S3 service's Lance port.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* helm: give admin the filer group

Admin lists filers and S3 gateways from its own group, and the Lance
worker now takes its filers from admin, so with filer.filerGroup set the
worker had no filers. Admin now gets the group; an -filerGroup in
admin.extraArgs still wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* seaweed-worker: drop --namespace, --masters and --filer-group

Admin names the namespace and the filers with every request, so the worker
takes them from there alone. Handlers and the preview hold the admin-fed
cluster, which also carries the signing key. The live tests get the filer
through WEED_FILER and feed it to the worker as admin would.

* helm: drop worker.namespaceUrl

A worker from 4.56 takes the namespace from admin and has no option for it,
so the value could only reach a pinned older image; the environment still
gives one the S3 service's namespace, masters and filer group.

* weed-vector: size the caches itself, and drop the tuning and config-dir flags

The engine caches a quarter of the memory it may use, its cgroup limit or
the machine's, split 2:4:1 between file reads, loaded indexes and table
metadata as the three flags' defaults were, so a small pod is not
overcommitted and a large host is used. --read-cache-mb, --index-cache-mb,
--metadata-cache-mb, --nprobes and --exact-match-limit are gone, and with
them the perf test's cold mode. --config-dir is gone too: weed mini passes
the security.toml it finds there.

* weed-vector-cli: find the Lance Namespace through the masters

A table id is looked up in the namespace of an S3 gateway the masters
list, so --namespace is gone; a local path still needs no cluster.

* helm: weed-vector sizes its own caches

vector.readCacheMB and vector.nprobes are gone with the engine's flags; an
older pinned image keeps its own defaults.

* weed-vector: size the caches from the process's own memory cgroup

A systemd service is limited in its own group below the cgroup root, which
the root's limit file does not show. The engine now reads its group from
/proc/self/cgroup and takes the smallest limit of it and its ancestors.

* mini: leave an explicit WEED_VECTOR_SECURITY_TOML to the engine

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:10:01 -08:00

134 lines
4.1 KiB
Go

package command
import (
"context"
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
"time"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
"github.com/seaweedfs/seaweedfs/weed/security"
"github.com/seaweedfs/seaweedfs/weed/util"
)
func startMiniVector() error {
binary := *miniVectorBinary
if binary == "weed-vector" {
if executable, err := os.Executable(); err == nil {
candidate := filepath.Join(filepath.Dir(executable), binary)
if resolved, err := exec.LookPath(candidate); err == nil {
binary = resolved
}
}
}
if _, err := exec.LookPath(binary); err != nil {
return fmt.Errorf("%s is unavailable: install the vector component or set -vector.binary: %w", binary, err)
}
address := util.JoinHostPort(*miniIp, *miniVectorPort)
bindIP := *miniBindIp
if bindIP == "" {
bindIP = *miniIp
}
if net.ParseIP(bindIP) == nil {
ctx, cancel := context.WithTimeout(miniClientsCtx(), 5*time.Second)
addresses, err := net.DefaultResolver.LookupIPAddr(ctx, bindIP)
cancel()
if err != nil {
return fmt.Errorf("resolve vector bind address %s: %w", bindIP, err)
}
if len(addresses) == 0 {
return fmt.Errorf("vector bind address %s has no IP addresses", bindIP)
}
bindIP = addresses[0].String()
}
args := []string{"--listen=" + util.JoinHostPort(bindIP, *miniVectorPort), "--advertise=" + address, "--masters=" + string(pb.NewServerAddress(*miniIp, *miniMasterOptions.port, *miniMasterOptions.portGrpc))}
if miniFilerOptions.filerGroup != nil && *miniFilerOptions.filerGroup != "" {
args = append(args, "--filer-group="+*miniFilerOptions.filerGroup)
}
if *miniVectorMetricsPort > 0 {
args = append(args, fmt.Sprintf("--metrics-port=%d", *miniVectorMetricsPort), "--metrics-ip="+bindIP)
}
if directory := util.ConfigurationFileDirectory.String(); directory != "" {
path := filepath.Join(util.ResolvePath(directory), "security.toml")
if _, explicit := os.LookupEnv("WEED_VECTOR_SECURITY_TOML"); !explicit && util.FileExists(path) {
args = append(args, "--security-toml="+path)
}
}
command := exec.CommandContext(miniClientsCtx(), binary, args...)
command.Stdout, command.Stderr = os.Stdout, os.Stderr
if err := command.Start(); err != nil {
return err
}
done := trackMiniClient()
exited := make(chan error, 1)
go func() {
defer done()
err := command.Wait()
exited <- err
if err != nil && miniClientsCtx().Err() == nil {
glog.Errorf("vector engine exited: %v", err)
}
}()
ctx, cancel := context.WithTimeout(miniClientsCtx(), 30*time.Second)
defer cancel()
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for {
select {
case err := <-exited:
return fmt.Errorf("vector engine exited before readiness: %v", err)
case <-ctx.Done():
_ = command.Process.Kill()
return ctx.Err()
case <-ticker.C:
conn, err := net.DialTimeout("tcp", miniVectorLocalAddress(bindIP, *miniVectorPort), 100*time.Millisecond)
if err == nil {
_ = conn.Close()
if !miniVectorRegistered(ctx, address) {
continue
}
glog.V(0).Infof("vector engine ready on %s", address)
return nil
}
}
}
}
func miniVectorLocalAddress(bindIP string, port int) string {
if ip := net.ParseIP(bindIP); ip != nil && ip.IsUnspecified() {
if ip.To4() != nil {
bindIP = "127.0.0.1"
} else {
bindIP = "::1"
}
}
return util.JoinHostPort(bindIP, port)
}
func miniVectorRegistered(ctx context.Context, address string) bool {
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
master := pb.NewServerAddress(*miniIp, *miniMasterOptions.port, *miniMasterOptions.portGrpc)
ready := false
_ = pb.WithMasterClient(ctx, false, master, security.LoadClientTLS(util.GetViper(), "grpc.client"), false, func(client master_pb.SeaweedClient) error {
response, err := client.ListClusterNodes(ctx, &master_pb.ListClusterNodesRequest{ClientType: "vector", FilerGroup: *miniFilerOptions.filerGroup})
if err != nil {
return err
}
for _, node := range response.ClusterNodes {
if node.Address == address {
ready = true
break
}
}
return nil
})
return ready
}