Skip to main content

Crate smg_mesh

Crate smg_mesh 

Source
Expand description

Mesh Gossip Protocol and Distributed State Synchronization

This crate provides mesh networking capabilities for distributed cluster state management:

  • Gossip protocol for node discovery and failure detection
  • CRDT-based state synchronization across cluster nodes
  • Consistent hashing for request routing
  • Partition detection and recovery

Modules§

gossip

Macros§

mesh_run

Structs§

AppState
App state entry (application configuration)
CrdtOrMap
CRDT OR-Map
MTLSConfig
mTLS configuration
MTLSManager
mTLS certificate manager
MembershipState
Membership state entry
MeshServerBuilder
MeshServerConfig
MeshServerHandler
MeshServerHandler It is the handler for the mesh server, which is responsible for the node management. Includes some basic node management logic, like shutdown, node discovery(TODO), node status update(TODO), etc.
MeshSyncManager
Mesh sync manager for coordinating state synchronization
OperationLog
Operation log, recording all state changes
PartitionDetector
Partition detector
RateLimitConfig
Global rate limit configuration
RateLimitWindow
Rate limit window manager Handles periodic reset of rate limit counters for time window management
StateStores
All state stores container
TenantDelta
Lightweight tenant change set for high-frequency sync (every gossip round). Contains only which tenants changed at which tree nodes — no tree structure, no prompt text. ~100 bytes per insert vs ~200KB for full TreeOperation.
TenantEvict
A tenant was evicted from a tree node.
TenantInsert
A tenant was added or refreshed at a tree node.
TreeInsertOp
Tree insert operation
TreeRemoveOp
Tree remove operation
TreeState
Tree state for a specific model Contains a sequence of operations that can be applied to reconstruct the tree
WorkerState
Worker state entry synced across mesh nodes.

Enums§

TreeKey
TreeOperation
Tree operation type

Constants§

GLOBAL_EVICTION_HASH
Sentinel value for TenantEvict.node_path_hash meaning “evict this tenant from ALL nodes” (global eviction).
GLOBAL_RATE_LIMIT_COUNTER_KEY
Key for global rate limit counter in RateLimitStore
GLOBAL_RATE_LIMIT_KEY
Key for global rate limit configuration in AppStore

Traits§

TreeStateSubscriber
WorkerStateSubscriber

Functions§

hash_node_path
Compute a compact 8-byte hash of a prefix path for node identification. Returns a non-zero hash; 0 is reserved for GLOBAL_EVICTION_HASH.
hash_token_path
Compute a compact 8-byte hash from token IDs. Returns a non-zero hash; 0 is reserved for GLOBAL_EVICTION_HASH.
init_mesh_metrics
Initialize mesh metrics descriptions
lz4_compress
Compress bytes with LZ4 for wire efficiency. Radix tree data compresses well (repetitive edge labels, worker URLs).
lz4_decompress
Decompress LZ4-compressed bytes with a size safety check. Rejects payloads claiming > 256 MB decompressed size to prevent OOM from corrupted or malicious size headers.

Type Aliases§

ClusterState
OptionalMTLSManager
Optional mTLS manager
OptionalMeshSyncManager
Optional mesh sync manager (can be None if mesh is not enabled)