cluster

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 19 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

远程压缩

github.com/lfhy/compactfs/codec/cluster 把已注册的 CPU、FPGA 或现有 codec/worker 算法暴露为有界 HTTP 计算服务,并提供 codec.Codec 调度适配器。 算法包不依赖文件系统;发现、STS 和 HMAC 通过回调接入。

NewServer(ServerConfig) 接收按 wire 名称注册的 Codecs,例如 map[string]codec.Codec{"gzip": workerClient.Codec("fpga-gzip")}。 在同一个 HTTP listener 挂载 EncodePath,并通过 Stats() 把当前 Active、QueueDepth、MaxConcurrent 放进心跳。POST body 是原文, JobHeader 固定目标节点、incarnation、request ID、operation、算法、原文长度及 XXH3-128。返回 ResultHeader 和编码后的 body;没有收益时返回原文 raw。

New(Config) 的 Local 必须是相同 wire 算法的 CPU codec;Nodes 返回租约有效的 Member 快照。适配器在选定一个节点后只提交一次请求,远端失败或超时时回退 CPU。 调用方取消则直接返回取消错误。响应在完整 encoded 校验及本地解码后的原文长度、 XXH3 校验全部通过后才写 dst,失败输出不会混入 CPU 重试。

调度成本包含当前队列、执行并发、编码速率、原文和预计编码结果的双向传输量以及 RTT。 未知信息默认估计 CPU 64 MiB/s、远端 CPU 的四倍、网络 256 MiB/s、RTT 1 ms、 编码比率 0.5;这些是调度估计而非实测带宽,可通过 Config 和各 Member 覆盖。 小于默认 64 KiB 的 chunk 优先本地。ForceRemote 可用于明确验证计算链路; 不绕过能力、大小、签名或完整性校验。并发默认 4,额外排队默认 0,均有上限。

请求和响应的授权回调为必填项。组装方须为 compute:encode 发放精确 STS,scope 绑定 Job.RequestID、RawSize、RawHash,同时用 HMAC 认证整个 Job, 避免算法或 incarnation 被替换;响应 proof 认证整个 Result 及 request ID。 XXH3 仅用于 bulk 完整性,不能替代认证。可使用 HTTP 明文可信存储网络,或由入口代理终止 TLS。

压缩结果交回既有 chunk.Store,由它选择最终表示、持久化并发布引用;本包不写 Data 副本或元数据。读取仍按存量 Ref.Codec 选择解码器,不依据当前调度节点猜测格式。

验证真实服务进程可从仓库根目录执行:

CGO_ENABLED=0 GOWORK=off go build -trimpath -o bin/compactfs .
CPFS_COMPUTE_BINARY="$PWD/bin/compactfs" CPFS_COMPUTE_WORK_ROOT=/data1 \
  CGO_ENABLED=0 GOWORK=off go test ./cmd/... \
  -run '^TestComputeRealProcessesDiscoveryProxyAndFallback$' -count=3 -v

该回归在新目录启动 1 Meta、3 Data、CPU 压缩节点和 Gateway,通过共享的 core.Access 客户端验证发现、实际远程编码、RF3 同步和完整读回。代理客户端只允许 连接 Gateway,观测请求确认 /nodes/<id>/v1/compute/encode 经过 Gateway 和 Meta。 停止压缩进程后验证真实请求失败及同格式 CPU 回退;迁移认证 epoch 后验证旧 STS 拒绝、新 STS 成功以及用原配置重启后门禁保持。日志和 JSON 留在打印的工作目录。 这是回环网络的功能验证;不代表跨机网络、FUSE 吞吐或真实 FPGA 性能。

Documentation

Overview

Package cluster schedules bounded chunk compression over HTTP, independently of storage. Authorization and discovery belong to the caller's control plane.

Index

Constants

View Source
const (
	Version                    = 1
	EncodeOperation            = "compute:encode"
	EncodePath                 = "/v1/compute/encode"
	JobHeader                  = "X-Compactfs-Compute-Job"
	ResultHeader               = "X-Compactfs-Compute-Result"
	JobProofHeader             = "X-Cpfs-Compute-Job-Proof"
	ResultProofHeader          = "X-Cpfs-Compute-Result-Proof"
	DefaultMaxChunkBytes int64 = 64 << 20
)

Variables

View Source
var (
	ErrInvalid   = errors.New("invalid compression request")
	ErrIntegrity = errors.New("compression integrity check failed")
	ErrBusy      = errors.New("compression queue is full")
)

Functions

func Hash

func Hash(data []byte) string

func JobProof

func JobProof(j Job) []byte

JobProof is the bounded, domain-separated description the authorization layer authenticates in addition to its exact STS object scope.

func ResultProof

func ResultProof(requestID string, result Result, h http.Header, status int) []byte

ResultProof binds a response to the initiating request, the complete result description, and transport semantics without MACing bulk bytes.

func SetJob

func SetJob(r *http.Request, j Job) error

Types

type Codec

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

Codec owns only its default transport and bounded admission slots. It borrows Local and Nodes. No caller output is written before full validation.

func New

func New(cfg Config) (*Codec, error)

func (*Codec) Close

func (c *Codec) Close() error

func (*Codec) Decode

func (c *Codec) Decode(ctx context.Context, src io.Reader, dst io.Writer) error

func (*Codec) Encode

func (c *Codec) Encode(ctx context.Context, raw []byte, dst io.Writer) (codec.Stats, error)

func (*Codec) Name

func (c *Codec) Name() string

func (*Codec) Stats

func (c *Codec) Stats() Stats

type Config

type Config struct {
	NamespaceID           string
	Local                 codec.Codec
	Nodes                 func() []Member
	HTTPClient            *http.Client
	MaxChunkBytes         int64
	MaxConcurrent         int
	QueueDepth            int
	RemoteTimeout         time.Duration
	MinBytes              int64
	LocalBytesPerSecond   float64
	NetworkBytesPerSecond float64
	RoundTrip             time.Duration
	EstimatedRatio        float64
	ForceRemote           bool
	Authorize             func(*http.Request, Job) error
	VerifyResponse        func(*http.Response, Result) error
}

type ForwardConfig

type ForwardConfig struct {
	Resolve       func(Job) (string, error)
	Authorize     func(*http.Request, Job) error
	HTTPClient    *http.Client
	MaxChunkBytes int64
	MaxConcurrent int
	QueueDepth    int
	Timeout       time.Duration
}

type Forwarder

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

func NewForwarder

func NewForwarder(cfg ForwardConfig) (*Forwarder, error)

NewForwarder streams only to a registry-approved compute endpoint. It accepts logical node routes, never a caller-provided upstream URL.

func (*Forwarder) Close

func (f *Forwarder) Close() error

func (*Forwarder) ServeHTTP

func (f *Forwarder) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Job

type Job struct {
	NamespaceID        string `json:"namespace_id,omitempty"`
	Version            int    `json:"version"`
	Operation          string `json:"operation"`
	NodeID             string `json:"node_id"`
	StorageIncarnation string `json:"storage_incarnation"`
	RequestID          string `json:"request_id"`
	Algorithm          string `json:"algorithm"`
	RawHash            string `json:"raw_hash"`
	RawSize            int64  `json:"raw_size"`
}

func RequestJob

func RequestJob(r *http.Request) (Job, error)

func (Job) Validate

func (j Job) Validate(max int64) error

type Member

type Member struct {
	NodeID                string
	StorageIncarnation    string
	Endpoint              string
	Algorithms            []string
	EncodeBytesPerSecond  float64
	NetworkBytesPerSecond float64
	QueueDepth            int
	Active                int
	MaxConcurrent         int
	RoundTrip             time.Duration
}

Member is one lease-valid compute service, supplied as an owned registry snapshot. Rates are scheduling estimates, in bytes/second; zero uses Config.

type Result

type Result struct {
	Version     int    `json:"version"`
	Job         Job    `json:"job"`
	Codec       string `json:"codec"`
	EncodedHash string `json:"encoded_hash"`
	EncodedSize int64  `json:"encoded_size"`
}

func ResponseResult

func ResponseResult(r *http.Response) (Result, error)

func (Result) Validate

func (r Result) Validate(max int64) error

type Server

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

func NewServer

func NewServer(cfg ServerConfig) (*Server, error)

func (*Server) ServeHTTP

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

func (*Server) Stats

func (s *Server) Stats() ServerStats

type ServerConfig

type ServerConfig struct {
	NodeID             string
	StorageIncarnation string
	Codecs             map[string]codec.Codec
	MaxChunkBytes      int64
	MaxConcurrent      int
	QueueDepth         int
	Timeout            time.Duration
	// Guard serializes this complete request with authority/revocation updates.
	// It must retain admission until fn returns and must not recursively lock
	// operations used by Authorize/SignResponse. Static authorization may omit it.
	Guard        func(context.Context, func() error) error
	Authorize    func(*http.Request, Job) error
	SignResponse func(*http.Request, Result, http.Header) error
}

type ServerStats

type ServerStats struct {
	Active        int    `json:"active"`
	QueueDepth    int64  `json:"queue_depth"`
	MaxConcurrent int    `json:"max_concurrent"`
	Completed     uint64 `json:"completed"`
	Failed        uint64 `json:"failed"`
	Rejected      uint64 `json:"rejected"`
	RawBytes      uint64 `json:"raw_bytes"`
	EncodedBytes  uint64 `json:"encoded_bytes"`
}

type Stats

type Stats struct {
	RemoteAttempts  uint64 `json:"remote_attempts"`
	RemoteSuccess   uint64 `json:"remote_success"`
	CPUFallbacks    uint64 `json:"cpu_fallbacks"`
	LocalSelections uint64 `json:"local_selections"`
	Rejected        uint64 `json:"rejected"`
	Active          int    `json:"active"`
	QueueDepth      int64  `json:"queue_depth"`
}

Jump to

Keyboard shortcuts

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