Documentation
¶
Index ¶
- type Config
- type Operation
- type OperationType
- type PeerBuilder
- type PeerHandle
- type RegionSnapshot
- type Router
- func (r *Router) BroadcastFlush() error
- func (r *Router) BroadcastTick() error
- func (r *Router) Deregister(id uint64)
- func (r *Router) Peer(id uint64) (*peer.Peer, bool)
- func (r *Router) Register(p *peer.Peer) error
- func (r *Router) SendCommand(id uint64, req *pb.RaftCmdRequest) error
- func (r *Router) SendPropose(id uint64, data []byte) error
- func (r *Router) SendRaft(id uint64, msg myraft.Message) error
- func (r *Router) SendTick(id uint64) error
- type SchedulerClient
- type SchedulerMode
- type SchedulerStatus
- type Store
- func (s *Store) Close()
- func (s *Store) Peer(id uint64) (*peer.Peer, bool)
- func (s *Store) Peers() []PeerHandle
- func (s *Store) ProposeAddPeer(regionID uint64, meta raftmeta.PeerMeta) error
- func (s *Store) ProposeCommand(ctx context.Context, req *pb.RaftCmdRequest) (*pb.RaftCmdResponse, error)
- func (s *Store) ProposeMerge(targetRegionID, sourceRegionID uint64) error
- func (s *Store) ProposeRemovePeer(regionID, peerID uint64) error
- func (s *Store) ProposeSplit(parentID uint64, childMeta raftmeta.RegionMeta, splitKey []byte) error
- func (s *Store) ReadCommand(ctx context.Context, req *pb.RaftCmdRequest) (*pb.RaftCmdResponse, error)
- func (s *Store) RegionMetaByID(regionID uint64) (raftmeta.RegionMeta, bool)
- func (s *Store) RegionMetas() []raftmeta.RegionMeta
- func (s *Store) RegionMetrics() *metrics.RegionMetrics
- func (s *Store) RegionSnapshot() RegionSnapshot
- func (s *Store) Router() *Router
- func (s *Store) SchedulerStatus() SchedulerStatus
- func (s *Store) StartPeer(cfg *peer.Config, bootstrapPeers []myraft.Peer) (*peer.Peer, error)
- func (s *Store) Step(msg myraft.Message) error
- func (s *Store) StopPeer(id uint64)
- func (s *Store) TransferLeader(regionID, targetPeerID uint64) error
- func (s *Store) VisitPeers(fn func(*peer.Peer))
- type StoreStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Router *Router
PeerBuilder PeerBuilder
LocalMeta *raftmeta.Store
WorkDir string
Scheduler SchedulerClient
HeartbeatInterval time.Duration
StoreID uint64
OperationQueueSize int
OperationCooldown time.Duration
OperationInterval time.Duration
OperationBurst int
CommandApplier func(*pb.RaftCmdRequest) (*pb.RaftCmdResponse, error)
CommandTimeout time.Duration
}
Config configures Store construction. Only the Router field is optional; the store fills in a default router when omitted.
type Operation ¶ added in v0.7.1
type Operation struct {
Type OperationType
Region uint64
Source uint64
Target uint64
}
Operation represents a scheduling decision to be executed by store runtime.
type OperationType ¶ added in v0.7.1
type OperationType uint8
OperationType identifies the scheduler operation kind.
const ( OperationNone OperationType = iota OperationLeaderTransfer )
func (OperationType) String ¶ added in v0.7.1
func (t OperationType) String() string
type PeerBuilder ¶
type PeerBuilder func(meta raftmeta.RegionMeta) (*peer.Config, error)
PeerBuilder constructs peer configuration for the provided region metadata. It allows the store to spawn new peers for splits without external callers wiring the configuration manually.
type PeerHandle ¶
type PeerHandle struct {
ID uint64
Peer *peer.Peer
Region *raftmeta.RegionMeta
}
PeerHandle is a lightweight view of a peer registered with the store. It is designed for diagnostics and scheduling components so they can iterate over the cluster topology without touching the internal map directly.
type RegionSnapshot ¶
type RegionSnapshot struct {
Regions []raftmeta.RegionMeta `json:"regions"`
}
RegionSnapshot provides an external view of the tracked Region metadata.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router mimics TinyKV's raftstore router by providing an addressable abstraction for driving peer state machines. Each peer registers itself with the router so other components (store loops, RPC handlers, tests) can deliver raft traffic or administrative ticks without holding the peer reference directly.
func (*Router) BroadcastFlush ¶
BroadcastFlush forces processReady on all registered peers. This mirrors TinyKV's behavior of draining the ready queue when necessary.
func (*Router) BroadcastTick ¶
BroadcastTick invokes Tick on every registered peer. The first error is returned to the caller.
func (*Router) Deregister ¶
Deregister removes a peer mapping. The caller is responsible for closing the peer after deregistration.
func (*Router) Register ¶
Register wires a peer into the router. Register must only be called once per peer ID.
func (*Router) SendCommand ¶ added in v0.2.0
func (r *Router) SendCommand(id uint64, req *pb.RaftCmdRequest) error
SendCommand encodes the provided raft command and submits it to the peer.
func (*Router) SendPropose ¶
SendPropose submits an application proposal to the peer.
type SchedulerClient ¶ added in v0.7.1
type SchedulerClient interface {
PublishRegion(context.Context, raftmeta.RegionMeta)
RemoveRegion(context.Context, uint64)
StoreHeartbeat(context.Context, StoreStats) []Operation
Status() SchedulerStatus
Close() error
}
SchedulerClient publishes store state to the control plane and returns any scheduling decisions that should be applied locally.
type SchedulerMode ¶ added in v0.7.2
type SchedulerMode string
SchedulerStatus captures local/control-plane scheduler health. It is a diagnostic view only; stores must not treat it as routing authority.
const ( SchedulerModeHealthy SchedulerMode = "healthy" SchedulerModeDegraded SchedulerMode = "degraded" )
type SchedulerStatus ¶ added in v0.7.1
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store hosts a collection of peers and exposes the concrete runtime helpers used by raftstore. It owns peer registration, region metadata, optional control-plane heartbeats, and command application.
func NewStore ¶
NewStore constructs a Store using concrete dependencies. It keeps peer construction, region tracking, and scheduler heartbeats explicit rather than routing them through callback chains.
func (*Store) Close ¶
func (s *Store) Close()
Close stops background workers associated with the store.
func (*Store) Peers ¶
func (s *Store) Peers() []PeerHandle
Peers returns a snapshot describing every peer managed by the store.
func (*Store) ProposeAddPeer ¶
ProposeAddPeer issues a configuration change to add the provided peer to the region's raft group. Local region metadata is updated once the configuration change is committed and applied.
func (*Store) ProposeCommand ¶ added in v0.2.0
func (s *Store) ProposeCommand(ctx context.Context, req *pb.RaftCmdRequest) (*pb.RaftCmdResponse, error)
ProposeCommand submits a raft command to the leader hosting the target region. When the store is not leader or the request header is invalid the returned response includes an appropriate RegionError.
func (*Store) ProposeMerge ¶
ProposeMerge submits a merge admin command merging source region into target.
func (*Store) ProposeRemovePeer ¶
ProposeRemovePeer issues a configuration change removing the peer with the provided peer ID from the region's raft group.
func (*Store) ProposeSplit ¶
ProposeSplit issues a split command through the raft log of the parent region. The child metadata must describe the new region configuration.
func (*Store) ReadCommand ¶ added in v0.2.0
func (s *Store) ReadCommand(ctx context.Context, req *pb.RaftCmdRequest) (*pb.RaftCmdResponse, error)
ReadCommand executes the provided read-only raft command locally on the leader. The command must only include read operations (Get/Scan). The method returns a RegionError when the store is not leader for the target region.
func (*Store) RegionMetaByID ¶
func (s *Store) RegionMetaByID(regionID uint64) (raftmeta.RegionMeta, bool)
RegionMetaByID returns the stored metadata for the provided region, along with a boolean indicating whether it exists.
func (*Store) RegionMetas ¶
func (s *Store) RegionMetas() []raftmeta.RegionMeta
RegionMetas collects the known raftmeta.RegionMeta entries from registered peers. This mirrors the TinyKV store exposing region layout information to schedulers and debugging endpoints.
func (*Store) RegionMetrics ¶
func (s *Store) RegionMetrics() *metrics.RegionMetrics
RegionMetrics returns the metrics recorder tracking region state counts.
func (*Store) RegionSnapshot ¶
func (s *Store) RegionSnapshot() RegionSnapshot
RegionSnapshot returns a snapshot containing all region metadata currently known to the store. The resulting slice is safe for callers to modify.
func (*Store) Router ¶
Router exposes the underlying router reference so transports can reuse the same registration hub.
func (*Store) SchedulerStatus ¶ added in v0.7.1
func (s *Store) SchedulerStatus() SchedulerStatus
SchedulerStatus returns the current scheduler health view by combining the local queue state with the control-plane client status.
func (*Store) StartPeer ¶
StartPeer builds and registers a peer according to the supplied configuration. The peer is automatically registered with the Store router. When bootstrapPeers is non-empty StartPeer will call Bootstrap with those peers after the peer is registered.
func (*Store) Step ¶ added in v0.2.0
Step forwards the provided raft message to the target peer hosted on this store.
func (*Store) TransferLeader ¶
TransferLeader initiates leadership transfer for the specified region to the provided peer ID.
func (*Store) VisitPeers ¶
VisitPeers executes the provided callback for every peer registered with the store. The callback receives a snapshot of the peer pointer so callers can perform operations without holding the store lock for extended periods.
type StoreStats ¶ added in v0.7.1
type StoreStats struct {
StoreID uint64 `json:"store_id"`
RegionNum uint64 `json:"region_num"`
LeaderNum uint64 `json:"leader_num"`
Capacity uint64 `json:"capacity"`
Available uint64 `json:"available"`
UpdatedAt time.Time `json:"updated_at"`
}
StoreStats captures minimal store-level heartbeat information.