peerorigin

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package peerorigin is the cadish peer-cache read-through origin (#7). It is an origin.Origin that, on Fetch, asks a PEER cadish node for the object instead of the real upstream. Composed BEFORE the real origin in an origin chain, it turns a region of cadish nodes into a cooperative cache: a local miss first tries the owning peer (LAN/RTT ≪ origin); only a peer miss falls through to origin.

Reuse, not reinvention: the peer pool is an internal/lb Upstream (consistent- hash shard-by-key over the peers, with lb's health FSM, failover, passive ejection and dns:// discovery). PeerOrigin only adds two things on top:

  • it routes by the CACHE KEY (lb.WithRoutingKey), so a given key always asks the same owning peer — the object is cached once per region, and a peer that already has it answers from its own cache; and
  • it stamps the X-Cadish-Peer hop header so the peer does NOT re-forward (loop/storm guard). A peer that sees the header serves only from its local cache and 404s a miss, which surfaces here as origin.ErrNotFound so the chain falls through to the real origin.

The streaming/ownership contract is honored verbatim — the lb.Upstream returns the peer body unchanged (a transparent close hook for connection accounting), so there is no extra copy and the server tees it into the local cache exactly as it tees an origin body.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PeerOrigin

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

PeerOrigin fetches an object from the owning peer cadish node.

func New

func New(peers *lb.Upstream, hopHeader, region, self string) *PeerOrigin

New builds a PeerOrigin over a peer pool (which MUST be a shard-by-key lb.Upstream so a cache key routes to its owning peer). hopHeader is the loop- guard header name (cluster.HopHeader) and region is its value, stamped on every peer fetch so the peer does not re-forward. self is this node's own peer URL: a key the ring assigns to us is served locally (ErrNotFound here), never fetched from ourselves — that would deadlock against request coalescing (a self-fetch is a second in-flight request for the same key, which the coalescer makes wait on the very request issuing it). The header name is passed in (rather than imported) so this package does not depend on internal/cluster (avoids an import cycle).

func (*PeerOrigin) Fetch

func (p *PeerOrigin) Fetch(ctx context.Context, req *origin.Request) (*origin.Response, error)

Fetch implements origin.Origin. It attaches the cache key as the lb routing key (so the peer pool's shard ring targets the owning peer), stamps the hop header, and delegates to the peer pool. A peer miss surfaces as origin.ErrNotFound and a peer-unreachable as a connection-class error, either of which lets a chain fall through to the real origin.

Jump to

Keyboard shortcuts

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