server

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 50 Imported by: 0 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 server is skylite's HTTPS server: the client protocol of ADR 0005 (docs/content/docs/decisions/0005-client-protocol.md) with the authentication of ADR 0006.

This version serves PUT /v1/databases/{db}, which creates a database, the stateless query and describe requests on leaders and opt-in followers (see query.go), and write channels with autocommit writes, transactions and cancel on leaders (see channel.go). Each configured database has an office loop (internal/office). With a peer listener configured, a request this server cannot serve is forwarded one hop to the pod that can (see forward.go). resolve and GET status are answered by the leader (see resolve.go); resolve is forwarded to it, and another pod answers status with not_serving. Admission control is that of ADR 0005 decision 9 (see budget.go and admit), except that HTTP connections and response frames are not charged to the memory budget.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Azure

type Azure struct {
	// Account is the storage account name, used to sign requests with a shared
	// key and, when Endpoint is empty, to form the account URL
	// https://<account>.blob.core.windows.net.
	Account string `json:"account"`
	// Container is the name of an existing container.
	Container string `json:"container"`
	// Endpoint, if set, is the blob service account URL, for example
	// "http://127.0.0.1:10000/devstoreaccount1" for Azurite. If empty,
	// https://<account>.blob.core.windows.net is used.
	Endpoint string `json:"endpoint"`
	// SharedKeyFile is the path of a file holding the base64-encoded account
	// shared key. Exactly one of SharedKeyFile, SharedKeyEnv and Entra must be
	// set.
	SharedKeyFile string `json:"shared_key_file"`
	// SharedKeyEnv names an environment variable holding the base64-encoded
	// account shared key. Exactly one of SharedKeyFile, SharedKeyEnv and Entra
	// must be set.
	SharedKeyEnv string `json:"shared_key_env"`
	// Entra signs requests with an Entra ID token from azidentity's
	// DefaultAzureCredential: a service principal in the AZURE_* environment
	// variables, workload identity, a managed identity, then the Azure CLI,
	// Azure Developer CLI and Azure PowerShell logins; AZURE_TOKEN_CREDENTIALS
	// narrows the chain. It needs an https endpoint. Exactly one of
	// SharedKeyFile, SharedKeyEnv and Entra must be set.
	Entra bool `json:"entra"`
}

Azure is an Azure Blob Storage container.

type Config

type Config struct {
	// Listen is the TCP address to listen on, for example ":8443".
	Listen string `json:"listen"`
	// TLS names the server's certificate and key. Exactly one of TLS and
	// Plaintext must be set.
	TLS *TLS `json:"tls"`
	// Plaintext serves HTTP/1.1 and HTTP/2 without TLS, for a server behind
	// a mesh or proxy that terminates TLS.
	Plaintext bool `json:"plaintext"`
	// Auth is the authentication and authorisation configuration of ADR 0006.
	Auth auth.Config `json:"auth"`
	// Storage is the object store that holds the databases.
	Storage Storage `json:"storage"`
	// Databases names the databases this server stands for: for each, it
	// takes office when it can and serves query and describe while it
	// leads. A database need not exist yet; the server takes office once it
	// does.
	Databases []string `json:"databases"`
	// FollowerReads enables stateless reads on fresh local followers. When
	// the file leaves it out, Load sets it to true if Peer is set: without
	// a peer listener a ready standby could not deliver writes.
	FollowerReads bool `json:"follower_reads"`
	// Peer, if set, lets this server forward a request it cannot serve
	// itself, one hop, to the pod that can (ADR 0005 decision 7).
	Peer *Peer `json:"peer"`
	// ProbeListen, if set, is a TCP address for a plain HTTP listener that
	// answers GET /readyz: 200 while this server can serve at least one
	// database and no leader is blocked at its tail bound, 503 otherwise.
	ProbeListen string `json:"probe_listen"`
	// MemoryBudget, if set, is the memory budget of ADR 0005 decision 9 in
	// bytes, from 384 MiB to 64 GiB. When it is 0, New takes three
	// quarters of the container's memory limit, or of GOMEMLIMIT if lower,
	// and 2 GiB without either.
	MemoryBudget int64 `json:"memory_budget"`
}

Config is the server's configuration, read from a JSON file by Load. It holds no secret: S3 and GCS take their credentials from their SDKs' default credential chains, and Azure reads its shared key from a file or environment variable named in the configuration.

func Load

func Load(path string) (Config, error)

Load reads and validates the configuration file at path. Unknown fields are refused.

func (Config) Validate

func (c Config) Validate() error

Validate reports the first problem with the configuration, if any.

type GCS

type GCS struct {
	Bucket   string `json:"bucket"`
	Endpoint string `json:"endpoint"`
}

GCS is a Google Cloud Storage bucket.

type LocalFS

type LocalFS struct {
	Path string `json:"path"`
}

LocalFS is a directory on a local file system.

type Peer

type Peer struct {
	// Listen is the TCP address of the peer listener, for example ":8444".
	Listen string `json:"listen"`
	// AddressEnv names an environment variable holding the host:port other
	// pods dial to reach this pod's peer listener, for example
	// "$(POD_IP):8444" set from the downward API.
	AddressEnv string `json:"address_env"`
	// CertFile and KeyFile are this pod's peer certificate and key, used
	// both as server and as client certificate.
	CertFile string `json:"cert_file"`
	KeyFile  string `json:"key_file"`
	// CAFile holds the PEM certificates that issue peer certificates.
	CAFile string `json:"ca_file"`
	// ServerName is the DNS name every peer certificate carries.
	ServerName string `json:"server_name"`
}

Peer is the pod-to-pod listener and its mutual TLS. Every pod of a deployment presents a certificate issued by CAFile, which must issue peer certificates and nothing else, for ServerName, and requires one from the pod that calls it.

type S3

type S3 struct {
	Bucket    string `json:"bucket"`
	Region    string `json:"region"`
	Endpoint  string `json:"endpoint"`
	PathStyle bool   `json:"path_style"`
}

S3 is an Amazon S3 bucket or one of an S3-compatible service.

type Server

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

Server serves the client protocol. Create it with New.

func New

func New(cfg Config, log *slog.Logger) (*Server, error)

New validates cfg, loads the TLS certificate and the JWKS files, and opens the storage backend. S3 and GCS take their credentials from their SDKs' default credential chains; Azure reads its shared key from the configured file or environment variable. A nil log discards log records. New sends no request.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener) error

Serve serves at most 1,024 connections at a time from ln until ctx is done. It runs an office loop for each configured database, and the readiness probe if one is configured. When ctx is done it reports itself not ready, stops accepting connections, waits up to a minute for running requests, then leaves office, releasing each lease, closes the store and returns. It returns nil after a clean shutdown, and an error if it had to close connections with requests still running.

func (*Server) ServeHTTP

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

ServeHTTP answers one request with ADR 0005's headers and NDJSON frames, ending with one terminal frame.

type Storage

type Storage struct {
	// Prefix is prepended, with a "/", to every database's keys. Empty means
	// the databases' keys start at the root of the store.
	Prefix  string   `json:"prefix"`
	LocalFS *LocalFS `json:"localfs"`
	S3      *S3      `json:"s3"`
	GCS     *GCS     `json:"gcs"`
	Azure   *Azure   `json:"azure"`
}

Storage selects one backend and the key prefix the databases live under. Exactly one of LocalFS, S3, GCS and Azure must be set.

type TLS

type TLS struct {
	CertFile string `json:"cert_file"`
	KeyFile  string `json:"key_file"`
}

TLS names PEM files holding the server's certificate chain and its key.

Jump to

Keyboard shortcuts

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