mesh

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Unlicense Imports: 22 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

Index

Constants

View Source
const (
	ProtocolPeriod = 200 * time.Millisecond
	AckTimeout     = 100 * time.Millisecond
	IndirectK      = 3
	MaxPacketSize  = 1400
)
View Source
const (
	// HeaderSize: Type(1) + Flags(1) + Seq(4) + NumUpdates(1)
	HeaderSize = 7

	// Flags
	FlagCompressed uint8 = 0x01
)

Variables

This section is empty.

Functions

func CompressPayload

func CompressPayload(data []byte) []byte

CompressPayload compresses bytes using Snappy. Returns the original slice if compression doesn't save space or fails.

func DecompressPayload

func DecompressPayload(data []byte) ([]byte, error)

DecompressPayload decompresses Snappy compressed bytes.

func EncodeMember

func EncodeMember(m *Member, dst []byte) (int, error)

EncodeMember serializes a member update into a compact binary format. Format: ID Len (1) | ID | Addr Len (1) | Addr | GRPCAddr Len (1) | GRPCAddr | MetaAddr Len (1) | MetaAddr | Status (1) | Incarnation (4) | NumTags (1) | [KeyLen(1)|Key|ValLen(1)|Val]...

func EncodePacket

func EncodePacket(p *Packet, dst []byte) (int, error)

EncodePacket writes the packet header to dst. Retuns the number of bytes written. dst must be at least HeaderSize + len(payload).

func ExtractPodIPs

func ExtractPodIPs(data []byte) ([]string, error)

ExtractPodIPs scans the JSON response body from K8s API for podIPs. It avoids full unmarshaling and operates on the byte slice directly. It returns a slice of IP strings found in the "items" array.

Types

type DNSProvider

type DNSProvider struct {
	Record string
	Port   int
}

DNSProvider performs peer discovery using DNS A/AAAA records. It is useful for headless services in Kubernetes.

func NewDNSProvider

func NewDNSProvider(record string, port int) *DNSProvider

NewDNSProvider creates a new DNS discovery provider.

func (*DNSProvider) FindPeers

func (d *DNSProvider) FindPeers(ctx context.Context) ([]string, error)

FindPeers resolves the configured DNS record and returns a list of peer addresses.

func (*DNSProvider) Register

func (d *DNSProvider) Register(ctx context.Context, id string, port int) error

Register is a no-op for DNS provider as records are typically managed externally.

type DiscoveryConfig

type DiscoveryConfig struct {
	Provider      string // "static", "k8s", "dns"
	StaticPeers   string // comma separated
	DNSRecord     string // for dns provider
	Namespace     string // for k8s provider
	LabelSelector string // for k8s provider
}

DiscoveryConfig holds configuration for peer discovery

type DiscoveryProvider

type DiscoveryProvider interface {
	// FindPeers returns a list of peer addresses (host:port).
	FindPeers(ctx context.Context) ([]string, error)
	// Register announces this node to the discovery backend (if applicable).
	Register(ctx context.Context, id string, port int) error
}

DiscoveryProvider finds peer addresses to bootstrap the mesh.

type EventDelegate

type EventDelegate interface {
	NotifyJoin(member *Member)
	NotifyLeave(member *Member)
	NotifyUpdate(member *Member)
}

EventDelegate handles cluster membership change events

type Gossip

type Gossip struct {
	Config GossipConfig
	// contains filtered or unexported fields
}

func NewGossip

func NewGossip(cfg *GossipConfig) *Gossip

func (*Gossip) GetDiscoveryStatus

func (g *Gossip) GetDiscoveryStatus() (provider string, peers []string)

func (*Gossip) GetIdentity

func (g *Gossip) GetIdentity() Member

GetIdentity returns information about this node.

func (*Gossip) GetMemberByAddr

func (g *Gossip) GetMemberByAddr(addr string) (*Member, bool)

GetMemberByAddr looks up a member by any of their known addresses (Gossip, GRPC, Meta). It returns the Member and true if found, or nil and false otherwise.

func (*Gossip) GetMembers

func (g *Gossip) GetMembers() []Member

GetMembers returns a list of all known members.

func (*Gossip) Join

func (g *Gossip) Join(peerAddr string) error

func (*Gossip) Start

func (g *Gossip) Start() error

func (*Gossip) Stop

func (g *Gossip) Stop()

func (*Gossip) UpdateLocalTags

func (g *Gossip) UpdateLocalTags(tags map[string]string)

UpdateLocalTags updates the tags for the local node and triggers Gossip propagation.

func (*Gossip) UpdateMember

func (g *Gossip) UpdateMember(m *Member)

UpdateMember updates the state of a member and triggers delegates

type GossipConfig

type GossipConfig struct {
	ID            string
	Addr          string // Bind Addr
	Port          int
	AdvertiseAddr string // Public gossip address for containers/K8s
	Discovery     DiscoveryConfig

	ProtocolPeriod   time.Duration
	AckTimeout       time.Duration
	SuspicionTimeout time.Duration
	GRPCAddr         string // Public data service address
	MetaAddr         string // Public meta service address

	Delegate EventDelegate
}

type K8sProvider

type K8sProvider struct {
	Namespace     string
	LabelSelector string
	Port          int
	// contains filtered or unexported fields
}

K8sProvider performs discovery by querying the Kubernetes API directly. It is optimized for high performance and low memory allocation.

func NewK8sProvider

func NewK8sProvider(namespace, labelSelector string, port int) *K8sProvider

NewK8sProvider creates a new Kubernetes discovery provider.

func (*K8sProvider) FindPeers

func (k *K8sProvider) FindPeers(ctx context.Context) ([]string, error)

FindPeers queries the K8s API for pods matching the label selector.

func (*K8sProvider) Register

func (k *K8sProvider) Register(ctx context.Context, id string, port int) error

Register is a no-op for K8s provider.

type MDNSProvider

type MDNSProvider struct {
	Service string
	Domain  string
	// contains filtered or unexported fields
}

MDNSProvider uses Multicast DNS to find local peers.

func NewMDNSProvider

func NewMDNSProvider(service string) *MDNSProvider

func (*MDNSProvider) FindPeers

func (m *MDNSProvider) FindPeers(ctx context.Context) ([]string, error)

func (*MDNSProvider) Register

func (m *MDNSProvider) Register(ctx context.Context, id string, port int) error

func (*MDNSProvider) Shutdown

func (m *MDNSProvider) Shutdown()

Shutdown stops the mDNS server. Note: This method is not part of DiscoveryProvider interface but useful for cleanup.

type Member

type Member struct {
	ID          string
	Addr        string // Gossip Host:Port (UDP)
	GRPCAddr    string // Service Host:Port (gRPC Data)
	MetaAddr    string // Service Host:Port (gRPC Meta)
	Tags        map[string]string
	Status      MemberStatus
	Incarnation uint32
	LastSeen    time.Time
	SuspectAt   time.Time // When the node was marked Suspect
}

Member represents a peer in the mesh.

func DecodeMember

func DecodeMember(src []byte) (*Member, int, error)

DecodeMember parses a member from src.

func (*Member) Empty

func (m *Member) Empty() bool

Resolution Rules (SWIM) - Alive overrides Suspect if Incarnation > known - Suspect overrides Alive if Incarnation >= known - Dead overrides all

type MemberStatus

type MemberStatus uint8
const (
	StatusAlive   MemberStatus = 0
	StatusSuspect MemberStatus = 1
	StatusDead    MemberStatus = 2
)

type MemoryRegion

type MemoryRegion struct {
	Addr   uintptr
	Length uint64
	RKey   uint32
	Handle uint64 // internal handle
}

MemoryRegion represents a registered memory area for RDMA.

func (*MemoryRegion) Unregister

func (m *MemoryRegion) Unregister() error

Unregister releases the memory region.

type MultiProvider

type MultiProvider struct {
	Providers []DiscoveryProvider
}

MultiProvider chains multiple providers (e.g., Static + MDNS).

func NewMultiProvider

func NewMultiProvider(providers ...DiscoveryProvider) *MultiProvider

func (*MultiProvider) FindPeers

func (m *MultiProvider) FindPeers(ctx context.Context) ([]string, error)

func (*MultiProvider) Register

func (m *MultiProvider) Register(ctx context.Context, id string, port int) error

type Packet

type Packet struct {
	Type       PacketType
	Flags      uint8
	Seq        uint32
	NumUpdates uint8
	Payload    []byte // Remaining bytes (membership updates)
}

Packet represents a gossip message. It is designed to map directly to a byte buffer.

func DecodePacket

func DecodePacket(src []byte) (*Packet, error)

DecodePacket parses a packet from src. The returned Packet's Payload relies on the underlying src array (zero-copy).

type PacketType

type PacketType uint8

PacketType identifies the message intent.

const (
	PacketPing    PacketType = 1
	PacketAck     PacketType = 2
	PacketPingReq PacketType = 3
)

type RDMAConnection

type RDMAConnection struct {
	PeerAddr string
	RKey     uint32
	BaseAddr uint64
}

RDMAConnection represents a high-throughput RDMA link.

type RDMAContext

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

RDMAContext manages the RDMA lifecycle.

func NewRDMAContext

func NewRDMAContext(enabled bool) *RDMAContext

func (*RDMAContext) ProcessBytes

func (c *RDMAContext) ProcessBytes(n int64)

ProcessBytes records RDMA ingestion telemetry.

func (*RDMAContext) RecordError

func (c *RDMAContext) RecordError()

RecordError increments the RDMA error counter.

func (*RDMAContext) RegisterGPUMemory

func (c *RDMAContext) RegisterGPUMemory(ctx context.Context, ptr uintptr, size uint64) (*MemoryRegion, error)

RegisterGPUMemory registers GPU VRAM for remote direct access.

func (*RDMAContext) RegisterMemoryRegion

func (c *RDMAContext) RegisterMemoryRegion(data []byte) (*MemoryRegion, error)

RegisterMemoryRegion registers a host memory area for RDMA access.

type RDMAStat

type RDMAStat struct {
	BytesProcessed atomic.Int64
	ErrorCount     atomic.Int64
	ActivePeers    atomic.Int32
}

RDMAStat holds metrics for RDMA performance.

type Region

type Region struct {
	ID       uint64
	Centroid []float32
	Radius   float32
	OwnerID  string
}

Region represents a cluster of vectors owned by a peer.

type RegionItem

type RegionItem struct {
	ID       uint64
	Centroid []float32
	// You might keep pointer to original Region or OwnerID here
	Region *Region
}

RegionItem represents a data point in the spatial index.

type Router

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

Router determines which peers should receive a query. Router determines which peers should receive a query.

func NewRouter

func NewRouter() *Router

func (*Router) RemoveRegion

func (r *Router) RemoveRegion(ownerID string)

RemoveRegion removes all regions owned by a peer.

func (*Router) Route

func (r *Router) Route(query []float32, limit int) []string

Route returns the IDs of peers that might contain relevant vectors. It checks if distance(query, centroid) <= radius + epsilon.

func (*Router) UpdateRegion

func (r *Router) UpdateRegion(reg Region)

UpdateRegion adds or updates a region in the routing table.

type SpatialIndex

type SpatialIndex interface {
	Search(query []float32, radius float32) []RegionItem
}

SpatialIndex defines the interface for spatial lookups.

type StaticProvider

type StaticProvider struct {
	Peers []string
}

StaticProvider returns a fixed list of peers.

func NewStaticProvider

func NewStaticProvider(peers []string) *StaticProvider

func (*StaticProvider) FindPeers

func (s *StaticProvider) FindPeers(ctx context.Context) ([]string, error)

func (*StaticProvider) Register

func (s *StaticProvider) Register(ctx context.Context, id string, port int) error

type VPTree

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

VPTree implements a Vantage Point Tree.

func NewVPTree

func NewVPTree(items []RegionItem) *VPTree

NewVPTree builds a static VP-Tree from items.

func (*VPTree) Search

func (t *VPTree) Search(query []float32, radius float32) []RegionItem

Search finds all items within radius of query.

Directories

Path Synopsis
Package sync manages background delta replication from peers.
Package sync manages background delta replication from peers.

Jump to

Keyboard shortcuts

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