cluster

package
v1.6.10 Latest Latest
Warning

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

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

Documentation

Overview

Package cluster provides interfaces for distributed cluster operations. This abstraction allows swapping implementations (Olric, NATS, etc.) without changing the controller logic.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is returned when a key does not exist in a DMap.
	ErrKeyNotFound = errors.New("key not found")

	// ErrClosed is returned when operations are attempted on a closed store.
	ErrClosed = errors.New("store is closed")

	// ErrNotConnected is returned when the cluster is not connected.
	ErrNotConnected = errors.New("not connected to cluster")
)

Functions

This section is empty.

Types

type DMap

type DMap interface {
	// Name returns the name of this distributed map.
	Name() string

	// Get retrieves a value by key. Returns ErrKeyNotFound if not present.
	Get(ctx context.Context, key string) (int64, error)

	// Put stores a value for the given key.
	Put(ctx context.Context, key string, value int64) error

	// Delete removes the specified keys. Returns count of deleted keys.
	Delete(ctx context.Context, keys ...string) (int, error)

	// Scan returns an iterator over keys. Options can filter results.
	Scan(ctx context.Context, opts ...ScanOption) (Iterator, error)
}

DMap represents a distributed key-value map. Values are int64 (timestamps) to match current usage patterns.

type Iterator

type Iterator interface {
	// Next advances the iterator. Returns false when exhausted.
	Next() bool

	// Key returns the current key.
	Key() string

	// Close releases iterator resources.
	Close()
}

Iterator allows iteration over DMap keys.

type Member

type Member struct {
	// Name is the member's identifier (typically host:port).
	Name string

	// Hostname is the OS hostname for human-readable identification.
	// Used by sysdump collection to address nodes.
	Hostname string

	// Coordinator indicates if this member is the cluster coordinator.
	Coordinator bool
}

Member represents a node in the cluster.

type Membership

type Membership interface {
	// Members returns the current list of cluster members.
	Members(ctx context.Context) ([]Member, error)

	// SubscribeEvents returns a subscription for cluster membership events.
	// Events are published when nodes join or leave the cluster.
	SubscribeEvents(ctx context.Context) Subscription
}

Membership provides cluster membership information and events.

type MembershipEventKind

type MembershipEventKind string

MembershipEventKind indicates the type of membership change.

const (
	NodeJoined MembershipEventKind = "node-joined"
	NodeLeft   MembershipEventKind = "node-left"
)

type Message

type Message struct {
	Channel string
	Payload string
}

Message represents a pub/sub message.

type PubSub

type PubSub interface {
	// Publish sends a message to a channel. Returns number of subscribers that received it.
	Publish(ctx context.Context, channel string, message string) (int64, error)

	// Subscribe creates a subscription to the specified channels.
	Subscribe(ctx context.Context, channels ...string) Subscription
}

PubSub provides publish/subscribe messaging.

type ScanOption

type ScanOption func(*ScanOptions)

ScanOption configures scan behavior.

func WithPattern

func WithPattern(pattern string) ScanOption

WithPattern creates a ScanOption that filters keys by regex pattern.

type ScanOptions

type ScanOptions struct {
	// Pattern is a regex pattern for key matching.
	Pattern string
}

ScanOptions holds scan configuration.

func ApplyScanOptions

func ApplyScanOptions(opts ...ScanOption) ScanOptions

ApplyScanOptions applies all options to a ScanOptions struct.

type Store

type Store interface {
	// NewDMap creates or retrieves a distributed map by name.
	NewDMap(name string) (DMap, error)

	// PubSub returns the pub/sub interface for this cluster.
	PubSub() PubSub

	// Membership returns the cluster membership interface.
	Membership() Membership

	// Close shuts down the store and releases resources.
	Close(ctx context.Context) error
}

Store is the top-level factory for distributed cluster operations. It manages the lifecycle of the cluster connection and provides access to distributed maps, pub/sub, and membership information.

type Subscription

type Subscription interface {
	// Channel returns a channel that receives messages.
	Channel() <-chan Message

	// Close terminates the subscription.
	Close() error
}

Subscription represents an active subscription to one or more channels.

Directories

Path Synopsis
Package bootstrap orchestrates the TLS bootstrap ceremony with Raft-based leader election.
Package bootstrap orchestrates the TLS bootstrap ceremony with Raft-based leader election.
Package memory provides an in-memory implementation of the cluster.Store interface.
Package memory provides an in-memory implementation of the cluster.Store interface.
Package nats provides a NATS JetStream implementation of the cluster.Store interface.
Package nats provides a NATS JetStream implementation of the cluster.Store interface.

Jump to

Keyboard shortcuts

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