worker

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

worker

导入路径:github.com/lfhy/compactfs/codec/worker,Go 包名为 worker。 本包将 chunk codec 放到可独立升级的算法进程中,通过 Unix socket 通信。

  • NewServer:注册 codec.Codec,处理版本化的编解码请求。
  • NewClient:连接算法进程,通过 Client.Codec 获取编解码代理。
  • StartProcess:启动与监督算法进程,支持替换二进制后重新启动。
  • DeviceLock:管理 FPGA 设备在算法进程之间的租借。
  • BuildVersion:通过链接参数设置独立的算法进程版本。

Linux 使用只读输入 FD 和独立输出 FD 传输完整 chunk;其他情况下使用有界的 二进制 body。协议包括能力协商、超时、重试、输出长度验证和取消处理,使用纯 Go。

import "github.com/lfhy/compactfs/codec/worker"

client := worker.NewClient(socket, timeout)
defer client.Close()
info, err := client.Connect(ctx)
// 检查 err 后使用代理;Name 对应已保存的算法格式。
algorithm := client.Codec("gzip")

为独立 worker 设置版本:

CGO_ENABLED=0 GOWORK=off go build \
  -ldflags '-X github.com/lfhy/compactfs/codec/worker.BuildVersion=codec-v2' \
  -o bin/compactfs-codec .

utils 提供进程内的文件读写任务池, codec/worker 提供算法进程服务。启动、升级和诊断见 算法 worker 指导。

Documentation

Overview

Package worker runs chunk codecs in an independently updatable process. The versioned HTTP protocol carries binary chunk bodies over a Unix socket.

Index

Constants

View Source
const DefaultMaxChunkBytes int64 = 64 << 20
View Source
const ProtocolVersion = 1

Variables

View Source
var BuildVersion = "dev"

BuildVersion may be set independently of the mount binary with -ldflags -X.

Functions

func ListenUnix

func ListenUnix(path string) (net.Listener, error)

ListenUnix refuses to replace a live socket or a regular file. A socket left behind by a killed worker can be reclaimed by its replacement.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(socket string, timeout time.Duration) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Codec

func (c *Client) Codec(name string) codec.Codec

Codec returns a proxy with a stable on-disk encoding name. CPU and FPGA implementations of gzip can be updated without changing existing refs.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) (Info, error)

Connect verifies protocol compatibility before a mount accepts writes.

type DeviceLock

type DeviceLock struct {
	// contains filtered or unexported fields
}

DeviceLock gives cooperating workers of the same Unix user one owner for a card's user BAR. Multiple mounts should share that owner's worker socket. Linux releases the advisory lock even when its owner is killed.

func (*DeviceLock) Acquire

func (l *DeviceLock) Acquire(device string) error

func (*DeviceLock) Close

func (l *DeviceLock) Close() error

type Info

type Info struct {
	Protocol      int                      `json:"protocol"`
	Version       string                   `json:"version"`
	PID           int                      `json:"pid"`
	Codecs        []string                 `json:"codecs"`
	MaxChunkBytes int64                    `json:"max_chunk_bytes"`
	Concurrency   int                      `json:"concurrency"`
	Prediction    *codec.PredictionOptions `json:"prediction,omitempty"`
	FileEncoding  bool                     `json:"file_encoding"`
	FileResults   bool                     `json:"file_results"`
	FileDecoding  bool                     `json:"file_decoding"`
}

type Process

type Process struct {
	Socket string
	// contains filtered or unexported fields
}

Process supervises a worker at a private socket. Re-exec always resolves the configured path again, so an atomically replaced binary is picked up after the old worker exits. It never owns backend data or namespace metadata.

func StartProcess

func StartProcess(options ProcessOptions) (*Process, error)

func (*Process) Close

func (p *Process) Close() error

type ProcessOptions

type ProcessOptions struct {
	// Binary implements the "worker" subcommand. Empty uses this executable.
	Binary string
	Args   []string
	Log    io.Writer
	// Config is private TOML configuration for the worker. Older workers can
	// ignore new keys while continuing to accept the existing --config flag.
	Config []byte
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(options ServerOptions) (*Server, error)

func (*Server) Close

func (s *Server) Close() error

Close cancels hijacked file requests, which http.Server.Shutdown does not own. Codecs finish before the worker releases its hardware lease.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown stops new file requests and drains those already using a codec. The HTTP listener must first stop accepting requests. On expiry Close cancels the remaining requests before the hardware lease can be released.

type ServerOptions

type ServerOptions struct {
	Codecs        map[string]codec.Codec
	Concurrency   int
	MaxChunkBytes int64
	Timeout       time.Duration
	Predictor     *codec.Predictor
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL