data

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: 22 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.

Documentation

Overview

Package data implements bounded immutable-object HTTP transfers. Authentication is supplied by the cluster control layer; data checksums use XXH3-128 and are not cryptographic authentication of the body.

Index

Constants

View Source
const (
	Version                     = 1
	ScopedVersion               = 2
	DefaultMaxObjectBytes int64 = 8 << 20
	DefaultConcurrency          = 16
	TransferHeader              = "X-Compactfs-Transfer"
	DescriptorHeader            = "X-Compactfs-Descriptor"
	NodeHeader                  = "X-Compactfs-Node"
	StorageHeader               = "X-Compactfs-Storage"
)
View Source
const DefaultRequestTimeout = 2 * time.Minute
View Source
const DeleteConditionHeader = "X-Compactfs-Delete-Condition"
View Source
const ResponseSignatureHeader = "X-Cpfs-Response-Signature"

Variables

View Source
var (
	ErrInvalid   = errors.New("invalid data request")
	ErrIntegrity = errors.New("data integrity check failed")
	ErrConflict  = errors.New("immutable object conflict")
	ErrBusy      = errors.New("data service capacity exhausted")
)
View Source
var ErrProtected = errors.New("data object is protected or GC mark expired")

Functions

func ObjectKey

func ObjectKey(d Descriptor) string

func ReceiptBytes

func ReceiptBytes(r Receipt) []byte

func ResponseProof

func ResponseProof(r *http.Request, op Operation, t Transfer, h http.Header, status int) []byte

ResponseProof binds headers to the exact requested representation and attempt. Bulk bytes are checked separately using XXH3, avoiding an additional HMAC pass.

func SetTransfer

func SetTransfer(r *http.Request, t Transfer) error

func TransferObject

func TransferObject(t Transfer) cluster.ObjectScope

func ValidateNamespaceID

func ValidateNamespaceID(id string) error

ValidateNamespaceID accepts an opaque bounded identity, never a filesystem path. Empty identifies the legacy default namespace.

func VerifyResponse

func VerifyResponse(secret string, r *http.Response, op Operation, t Transfer) error

Types

type Client

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

Client owns its default HTTP transport. Caller-provided clients are borrowed. Get returns verified, owned bytes, never an unverified live network reader.

func NewClient

func NewClient(cfg ClientConfig) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) DeleteObject

func (c *Client) DeleteObject(ctx context.Context, node Node, tr Transfer, condition DeleteCondition) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, node Node, t Transfer) ([]byte, error)

Get races at most two endpoints belonging to one node. It cancels the losing request immediately after selecting legal headers. If the winner's body fails integrity, the canceled alternative is retried once sequentially.

func (*Client) Inventory

func (c *Client) Inventory(ctx context.Context, node Node, incarnation string, request InventoryRequest) (InventoryPage, error)

Inventory requires the expected persistent disk incarnation, never merely a NodeID which could have been reassigned to an empty replacement disk.

func (*Client) InventoryAt

func (c *Client) InventoryAt(ctx context.Context, node Node, incarnation string, request InventoryRequest) (InventoryPage, error)

InventoryAt is the explicit-incarnation spelling of Inventory.

func (*Client) Probe

func (c *Client) Probe(ctx context.Context, node Node, t Transfer) (string, error)

Probe chooses the first authenticated write endpoint among at most two approved addresses. It sends signed HEAD requests with no object body or storage mutation. It does not retry a PUT; the caller subsequently performs exactly one upload to the returned endpoint using its original transfer.

func (*Client) Put

func (c *Client) Put(ctx context.Context, node Node, t Transfer, body io.Reader) (Receipt, error)

Put deliberately chooses only the first endpoint. A failed/uncertain PUT is resolved by the caller using its original upload/attempt, never raced here.

func (*Client) StatObject

func (c *Client) StatObject(ctx context.Context, node Node, tr Transfer) (ObjectInfo, error)

type ClientConfig

type ClientConfig struct {
	HTTPClient     *http.Client
	MaxObjectBytes int64
	MaxConcurrent  int
	Authorize      func(*http.Request, Operation, Transfer) error
	VerifyResponse func(*http.Response, Operation, Transfer) error
	VerifyReceipt  func(Receipt) error
}

type DeleteCondition

type DeleteCondition struct {
	Epoch  string    `json:"epoch"`
	Before time.Time `json:"before"`
}

type Descriptor

type Descriptor struct {
	Version     int    `json:"version"`
	NamespaceID string `json:"namespace_id,omitempty"`
	ObjectID    string `json:"object_id"`
	RawHash     string `json:"raw_hash"`
	RawSize     int64  `json:"raw_size"`
	Codec       string `json:"codec"`
	WireVersion int    `json:"wire_version"`
	EncodedHash string `json:"encoded_hash"`
	EncodedSize int64  `json:"encoded_size"`
}

Descriptor identifies an exact encoded representation independently of its replica node or upload attempt. RawHash remains the existing content ID.

func NewDescriptor

func NewDescriptor(rawHash string, rawSize int64, codec string, encoded []byte) (Descriptor, error)

func NewScopedDescriptor

func NewScopedDescriptor(namespaceID, rawHash string, rawSize int64, codec string, encoded []byte) (Descriptor, error)

NewScopedDescriptor binds identical encoded bytes to a namespace-specific immutable object identity. Empty namespace preserves the original v1 ID.

func (Descriptor) ID

func (d Descriptor) ID() string

ID excludes ObjectID itself and all transport/upload identities.

func (Descriptor) Validate

func (d Descriptor) Validate(max int64) error

type ForwardConfig

type ForwardConfig struct {
	// Resolve must return an approved node; user-supplied URLs are not accepted.
	Resolve        func(nodeID string) (Node, error)
	Authorize      func(*http.Request, Operation, Transfer) error
	HTTPClient     *http.Client
	MaxObjectBytes int64
	MaxConcurrent  int
}

type Forwarder

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

Forwarder forwards opaque signed requests without taking ownership of credentials or file publication. It has a separate bounded connection pool.

func NewForwarder

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

func (*Forwarder) Close

func (f *Forwarder) Close()

func (*Forwarder) ServeHTTP

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

type InventoryPage

type InventoryPage struct {
	Epoch   string       `json:"epoch"`
	Before  time.Time    `json:"before"`
	Next    string       `json:"next,omitempty"`
	Objects []ObjectInfo `json:"objects"`
}

type InventoryRequest

type InventoryRequest struct {
	Epoch  string    `json:"epoch"`
	Before time.Time `json:"before"`
	Cursor string    `json:"cursor,omitempty"`
	Limit  int       `json:"limit"`
}

type Node

type Node struct {
	NodeID    string   `json:"node_id"`
	Endpoints []string `json:"endpoints"`
}

type ObjectInfo

type ObjectInfo struct {
	Descriptor     Descriptor `json:"descriptor"`
	DurableAt      time.Time  `json:"durable_at"`
	ProtectedUntil time.Time  `json:"protected_until"`
}

type Operation

type Operation string
const (
	Read      Operation = "read"
	Write     Operation = "write"
	Inventory Operation = "data:inventory"
	Stat      Operation = "data:stat"
	Delete    Operation = "data:delete"
)

type Receipt

type Receipt struct {
	Transfer
	DurableAt time.Time `json:"durable_at"`
	Signature string    `json:"signature,omitempty"`
}

type Server

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

Server does not own its Backend. Each active transfer owns one bounded buffer and PUT owns one temporary file, deleted before the handler returns.

func NewServer

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

func (*Server) Close

func (s *Server) Close() error

Close releases the optional catalog. The listener owner must first stop and join its HTTP handlers; Server never closes the borrowed object backend.

func (*Server) RegisterObject

func (s *Server) RegisterObject(ctx context.Context, d Descriptor, durableAt time.Time) error

RegisterObject imports an exact preexisting immutable representation into the maintenance catalog. The caller must hold exclusive initialization; the object is protected for a fresh lease and is never immediately collectible.

func (*Server) ServeHTTP

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

func (*Server) Stats

func (s *Server) Stats() Stats

type ServerConfig

type ServerConfig struct {
	NodeID             string
	StorageIncarnation string
	Backend            backend.Backend
	StagingDir         string
	MaxObjectBytes     int64
	MaxConcurrent      int
	// RequestTimeout bounds guard/lock admission, body I/O and response flush.
	// Zero uses DefaultRequestTimeout; callers may choose a larger bound.
	RequestTimeout time.Duration
	Authorize      func(*http.Request, Operation, Transfer) error
	SignReceipt    func(Receipt) (string, error)
	SignResponse   func(*http.Request, Operation, Transfer, http.Header) error
	// MaintenancePath enables a durable object catalog and authenticated GC.
	// Caller must stop HTTP handlers before Close. Empty disables management.
	MaintenancePath string
	ProtectionTTL   time.Duration
	MinGCAge        time.Duration
	Gate            func(context.Context) error
	// Guard owns admission through the complete response, including ordinary
	// transfers and maintenance. Updates take its corresponding write lock.
	Guard func(context.Context, func() error) error
}

type Stats

type Stats struct {
	Gets              uint64 `json:"gets"`
	Puts              uint64 `json:"puts"`
	ReadBytes         uint64 `json:"read_bytes"`
	WrittenBytes      uint64 `json:"written_bytes"`
	IntegrityFailures uint64 `json:"integrity_failures"`
	InFlight          int    `json:"in_flight"`
}

type Transfer

type Transfer struct {
	Descriptor         Descriptor `json:"descriptor"`
	NodeID             string     `json:"node_id"`
	StorageIncarnation string     `json:"storage_incarnation"`
	UploadID           string     `json:"upload_id,omitempty"`
	AttemptID          string     `json:"attempt_id,omitempty"`
}

func RequestTransfer

func RequestTransfer(r *http.Request) (Transfer, error)

Jump to

Keyboard shortcuts

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