sharding

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: 30 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

This section is empty.

Variables

This section is empty.

Functions

func DefaultHealthCheck

func DefaultHealthCheck(conn *grpc.ClientConn) bool

DefaultHealthCheck uses gRPC connectivity state

func PartitionProxyInterceptor

func PartitionProxyInterceptor(rm *RingManager, forwarder *RequestForwarder) grpc.UnaryServerInterceptor

PartitionProxyInterceptor creates a unary server interceptor for request routing

func PartitionProxyStreamInterceptor

func PartitionProxyStreamInterceptor(rm *RingManager, forwarder *RequestForwarder, aggregator *StreamAggregator) grpc.StreamServerInterceptor

PartitionProxyStreamInterceptor creates a stream server interceptor for request routing

Types

type ConsistentHash

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

ConsistentHash implements a consistent hashing ring with hot key caching

func NewConsistentHash

func NewConsistentHash(vnodes int) *ConsistentHash

NewConsistentHash creates a new ring with specified vnodes and hot key caching

func NewConsistentHashWithCache

func NewConsistentHashWithCache(vnodes, cacheCapacity int, cacheTTL time.Duration) *ConsistentHash

NewConsistentHashWithCache creates a new ring with custom cache configuration

func (*ConsistentHash) AddNode

func (c *ConsistentHash) AddNode(nodeID string)

AddNode adds a new node to the ring

func (*ConsistentHash) ClearCache

func (c *ConsistentHash) ClearCache()

ClearCache purges the hot key cache

func (*ConsistentHash) GetMetrics

func (c *ConsistentHash) GetMetrics() ConsistentHashMetrics

GetMetrics returns current cache metrics

func (*ConsistentHash) GetNode

func (c *ConsistentHash) GetNode(key string) string

GetNode returns the node responsible for the given key Uses hot key caching for improved performance on repeated lookups

func (*ConsistentHash) GetNodeUncached

func (c *ConsistentHash) GetNodeUncached(key string) string

GetNodeUncached returns the node without using cache (for testing or cache-invalidated paths)

func (*ConsistentHash) GetPreferenceList

func (c *ConsistentHash) GetPreferenceList(key string, n int) []string

GetPreferenceList returns the top N distinct nodes for a key (Replication Strategy)

func (*ConsistentHash) NodeCount

func (c *ConsistentHash) NodeCount() int

NodeCount returns the number of nodes in the ring

func (*ConsistentHash) RemoveNode

func (c *ConsistentHash) RemoveNode(nodeID string)

RemoveNode removes a node from the ring

func (*ConsistentHash) TotalHashCount

func (c *ConsistentHash) TotalHashCount() int

TotalHashCount returns total number of hash points

func (*ConsistentHash) UpdateVNodeCount

func (c *ConsistentHash) UpdateVNodeCount(nodeID string, count int)

UpdateVNodeCount updates the number of virtual nodes for a specific nodeID. This is used for load-based rebalancing (dynamic weighting).

func (*ConsistentHash) VirtualNodeCount

func (c *ConsistentHash) VirtualNodeCount() int

VirtualNodeCount returns the number of virtual nodes

type ConsistentHashMetrics

type ConsistentHashMetrics struct {
	CacheHits   int64
	CacheMisses int64
	CacheSize   int
}

ConsistentHashMetrics holds performance metrics for the ring

type ForwarderConfig

type ForwarderConfig struct {
	DialTimeout         time.Duration
	Logger              zerolog.Logger
	HealthCheckInterval time.Duration
	HealthCheckFunc     HealthCheckFunc
	MaxConnAge          time.Duration
}

ForwarderConfig holds configuration for the forwarder

func DefaultForwarderConfig

func DefaultForwarderConfig() ForwarderConfig

DefaultForwarderConfig returns default config

type HealthCheckFunc

type HealthCheckFunc func(conn *grpc.ClientConn) bool

HealthCheckFunc is a function that checks if a connection is healthy

type NodeResolver

type NodeResolver interface {
	GetNodeAddr(nodeID string) string
}

NodeResolver resolves node IDs to addresses

type RequestForwarder

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

RequestForwarder handles forwarding gRPC requests to remote nodes

func NewRequestForwarder

func NewRequestForwarder(cfg *ForwarderConfig, resolver NodeResolver) *RequestForwarder

NewRequestForwarder creates a new forwarder

func (*RequestForwarder) Close

func (f *RequestForwarder) Close() error

Close closes all connections and stops the health check goroutine

func (*RequestForwarder) Forward

func (f *RequestForwarder) Forward(ctx context.Context, targetNodeID string, req any, method string) (any, error)

Forward forwards a unary request to the target node transparently. It uses byteCodec to handle any request/response type as raw bytes.

func (*RequestForwarder) ForwardStream

func (f *RequestForwarder) ForwardStream(ctx context.Context, targetNodeID string, serverStream grpc.ServerStream, method string, initialRequest any) error

ForwardStream handles transparent proxying for streaming gRPC calls. initialRequest is optional and should be provided if the request has already been consumed by the handler (e.g., in Server-Streaming RPCs like DoGet).

func (*RequestForwarder) GetConn

func (f *RequestForwarder) GetConn(ctx context.Context, target string) (*grpc.ClientConn, error)

GetConn returns or creates a connection to the target

type Result

type Result struct {
	NodeID string
	Data   any
	Error  error
}

Result holds the result from a single node

type RingManager

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

RingManager coordinates the consistent hash ring with the cluster membership state

func NewRingManager

func NewRingManager(localNodeID string, logger zerolog.Logger) *RingManager

NewRingManager creates a new RingManager

func (*RingManager) GetMembers

func (rm *RingManager) GetMembers() []string

GetMembers returns a list of all known node IDs in the ring

func (*RingManager) GetMetaAddr

func (rm *RingManager) GetMetaAddr(nodeID string) string

GetMetaAddr returns the metadata/search service network address for a given node ID

func (*RingManager) GetNode

func (rm *RingManager) GetNode(key string) string

GetNode returns the owner of a key

func (*RingManager) GetNodeAddr

func (rm *RingManager) GetNodeAddr(nodeID string) string

GetNodeAddr returns the data service network address for a given node ID

func (*RingManager) GetPreferenceList

func (rm *RingManager) GetPreferenceList(key string, n int) []string

GetPreferenceList returns the replication nodes for a key

func (*RingManager) IsLocalKey

func (rm *RingManager) IsLocalKey(key string) bool

IsLocalKey returns true if the key belongs to the local node

func (*RingManager) NotifyJoin

func (rm *RingManager) NotifyJoin(member *mesh.Member)

NotifyJoin is invoked when a node joins the cluster

func (*RingManager) NotifyLeave

func (rm *RingManager) NotifyLeave(member *mesh.Member)

NotifyLeave is invoked when a node leaves the cluster

func (*RingManager) NotifyUpdate

func (rm *RingManager) NotifyUpdate(member *mesh.Member)

NotifyUpdate is invoked when a node is updated

func (*RingManager) RouteGeo

func (rm *RingManager) RouteGeo(dataset string, lat, lon float64, radiusKm float64) []string

func (*RingManager) RouteTemporal

func (rm *RingManager) RouteTemporal(dataset string, startTime, endTime int64) []string

func (*RingManager) UpdateNodeLoad

func (rm *RingManager) UpdateNodeLoad(nodeID string, load float64)

UpdateNodeLoad updates the reported load for a node and triggers rebalancing if necessary

type ScatterFn

type ScatterFn func(ctx context.Context, nodeID string) (any, error)

ScatterFn is the function to execute on each node It takes a context (with timeout) and the target node ID

type ScatterGather

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

ScatterGather coordinates distributed request execution

func NewScatterGather

func NewScatterGather(rm *RingManager, forwarder *RequestForwarder, logger zerolog.Logger) *ScatterGather

NewScatterGather creates a new ScatterGather coordinator

func (*ScatterGather) Scatter

func (sg *ScatterGather) Scatter(ctx context.Context, fn ScatterFn) ([]Result, error)

Scatter executes the given function across all independent nodes in the cluster. It supports a strict consistency mode (all must succeed) or best-effort. This is used for Global Search where we query all shards.

type StreamAggregator

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

StreamAggregator consolidates results from multiple Flight streams

func NewStreamAggregator

func NewStreamAggregator(mem memory.Allocator, logger zerolog.Logger) *StreamAggregator

NewStreamAggregator creates a new aggregator

func (*StreamAggregator) Aggregate

func (sa *StreamAggregator) Aggregate(ctx context.Context, sg *ScatterGather, k int, scatterFn ScatterFn) ([]arrow.RecordBatch, error)

Aggregate performs a scatter-gather-merge for Flight streams. It executes the scatter function, collects all resulting streams, reads them into memory, merges (sorts) the results, and returns the top K rows as a new RecordBatch.

Fault Tolerance: Failed shards are logged and ignored. Partial results are returned.

type TimeBounds

type TimeBounds struct {
	Min int64
	Max int64
}

TimeBounds represents a min and max timestamp.

Jump to

Keyboard shortcuts

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