Documentation
¶
Index ¶
- func NewTransactionService(nodeID string, dataStore *datastore.DataStore, ...) protoc.TransactionServiceServer
- func StartServer(nodeID string, port string, dataStore *datastore.DataStore, ...)
- type CheckpointData
- type CheckpointManager
- func (cm *CheckpointManager) CreateCheckpoint(checkpointID int64) error
- func (cm *CheckpointManager) GetLastCheckpointTime() time.Time
- func (cm *CheckpointManager) ListCheckpoints() ([]int64, error)
- func (cm *CheckpointManager) RestoreFromCheckpoint(checkpointID int64) error
- func (cm *CheckpointManager) Start()
- func (cm *CheckpointManager) Stop()
- type ConsensusManager
- type Node
- type RaftConfig
- type RaftNode
- func (rn *RaftNode) GetLeader() string
- func (rn *RaftNode) GetState() (int, bool)
- func (rn *RaftNode) HandleAppendEntries(leaderID string, term, prevLogIndex, prevLogTerm int, ...) (int, bool)
- func (rn *RaftNode) HanldeRequestVote(candidateID string, term, lastLogIndex, lastLogTerm int) (int, bool)
- func (rn *RaftNode) IsLeader() bool
- func (rn *RaftNode) ProposeCommand(command *protoc.Transaction) (bool, error)
- func (rn *RaftNode) RequestVote(peerID string, client protoc.TransactionServiceClient, ...) (bool, error)
- func (rn *RaftNode) Start()
- func (rn *RaftNode) Stop()
- type RaftState
- type SyncManager
- type SyncStats
- type TransactionService
- func (s *TransactionService) AppendEntries(ctx context.Context, req *protoc.AppendEntriesRequest) (*protoc.AppendEntriesResponse, error)
- func (s *TransactionService) Auth(ctx context.Context, req *protoc.AuthRequest) (*protoc.AuthResponse, error)
- func (s *TransactionService) Get(ctx context.Context, req *protoc.GetRequest) (*protoc.GetResponse, error)
- func (s *TransactionService) HandleTransaction(ctx context.Context, req *protoc.TransactionRequest) (*protoc.TransactionResponse, error)
- func (s *TransactionService) RequestVote(ctx context.Context, in *protoc.RequestVoteRequest) (*protoc.RequestVoteResponse, error)
- func (s *TransactionService) SyncState(ctx context.Context, req *protoc.SyncRequest) (sr *protoc.SyncResponse, e error)
- func (s *TransactionService) VerifyState(ctx context.Context, req *protoc.StateVerificationRequest) (svr *protoc.StateVerificationResponse, e error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTransactionService ¶
func NewTransactionService(nodeID string, dataStore *datastore.DataStore, consensusManager *ConsensusManager) protoc.TransactionServiceServer
NewTransactionService initializes a new TransactionService
func StartServer ¶
func StartServer(nodeID string, port string, dataStore *datastore.DataStore, consensusManager *ConsensusManager, useTLS bool, certDir string)
StartServer starts the gRPC server
Types ¶
type CheckpointData ¶
type CheckpointData struct { MerkleRoot string `json:"merkle_root"` KeyValues map[string]string `json:"key_values"` Timestamp time.Time `json:"timestamp"` }
CheckpointData represents the data stored in a checkpoint
type CheckpointManager ¶
type CheckpointManager struct {
// contains filtered or unexported fields
}
CheckpointManager manages checkpointing for fault tolerance
func NewCheckpointManager ¶
func NewCheckpointManager(dataStore *datastore.DataStore, checkpointDir string, interval time.Duration) *CheckpointManager
NewCheckpointManager creates a new CheckpointManager
func (*CheckpointManager) CreateCheckpoint ¶
func (cm *CheckpointManager) CreateCheckpoint(checkpointID int64) error
CreateCheckpoint creates a checkpoint with the given ID
func (*CheckpointManager) GetLastCheckpointTime ¶
func (cm *CheckpointManager) GetLastCheckpointTime() time.Time
GetLastCheckpointTime returns the time of the last checkpoint
func (*CheckpointManager) ListCheckpoints ¶
func (cm *CheckpointManager) ListCheckpoints() ([]int64, error)
ListCheckpoints lists all available checkpoints
func (*CheckpointManager) RestoreFromCheckpoint ¶
func (cm *CheckpointManager) RestoreFromCheckpoint(checkpointID int64) error
RestoreFromCheckpoint restores from a checkpoint with the given ID
func (*CheckpointManager) Start ¶
func (cm *CheckpointManager) Start()
Start starts the checkpointing process
func (*CheckpointManager) Stop ¶
func (cm *CheckpointManager) Stop()
Stop stops the checkpointing process
type ConsensusManager ¶
type ConsensusManager struct {
// contains filtered or unexported fields
}
ConsensusManager manages the Raft consensus algorithm
func NewConsensusManager ¶
func NewConsensusManager(config RaftConfig, dataStore *datastore.DataStore, networkManager interfaces.NetworkManagerI) *ConsensusManager
NewConsensusManager creates a new ConsensusManager
func (*ConsensusManager) GetLeader ¶
func (cm *ConsensusManager) GetLeader() string
GetLeader returns the ID of the current leader
func (*ConsensusManager) IsLeader ¶
func (cm *ConsensusManager) IsLeader() bool
IsLeader returns true if this node is the leader
func (*ConsensusManager) ProposeTransaction ¶
func (cm *ConsensusManager) ProposeTransaction(key, value string) (bool, error)
ProposeTransaction proposes a transaction to the Raft cluster
func (*ConsensusManager) Start ¶
func (cm *ConsensusManager) Start()
Start starts the ConsensusManager
type Node ¶
type Node struct { UseTLS bool DBPath string Port string // contains filtered or unexported fields }
type RaftConfig ¶
type RaftConfig struct { NodeID string // Unique identifier for this node PeerAddresses map[string]string // Map of node IDs to network addresses ElectionTimeoutMin int // Minimum election timeout in milliseconds ElectionTimeoutMax int // Maximum election timeout in milliseconds HeartbeatInterval int // Heartbeat interval in milliseconds }
RaftConfig contains configuration parameters for the Raft consensus algorithm
type RaftNode ¶
type RaftNode struct {
// contains filtered or unexported fields
}
RaftNode represents a node in the Raft consensus algorithm
func NewRaftNode ¶
func NewRaftNode(config RaftConfig, dataStore *datastore.DataStore, transactionHandler func(*protoc.Transaction) error) *RaftNode
NewRaftNode creates a new Raft node
func (*RaftNode) HandleAppendEntries ¶
func (rn *RaftNode) HandleAppendEntries(leaderID string, term, prevLogIndex, prevLogTerm int, entries []*protoc.LogEntry, leaderCommit int) (int, bool)
HandleAppendEntries handles an AppendEntries RPC from a peer
func (*RaftNode) HanldeRequestVote ¶
func (rn *RaftNode) HanldeRequestVote(candidateID string, term, lastLogIndex, lastLogTerm int) (int, bool)
HandleRequestVote handles a RequestVote RPC from a peer
func (*RaftNode) ProposeCommand ¶
func (rn *RaftNode) ProposeCommand(command *protoc.Transaction) (bool, error)
ProposeCommand proposes a new command to the Raft cluster
func (*RaftNode) RequestVote ¶
func (rn *RaftNode) RequestVote(peerID string, client protoc.TransactionServiceClient, term, lastLogIndex, lastLogTerm int) (bool, error)
requestVote sends a RequestVote RPC to a peer
type RaftState ¶
type RaftState int
RaftState represents the state of a node in the Raft consensus algorithm
type SyncManager ¶
type SyncManager struct {
// contains filtered or unexported fields
}
SyncManager manages state synchronization between nodes
func NewSyncManager ¶
func NewSyncManager(dataStore *datastore.DataStore, networkManager interfaces.NetworkManagerI) *SyncManager
NewSyncManager creates a new SyncManager
func (*SyncManager) SyncWithPeers ¶
func (sm *SyncManager) SyncWithPeers()
SyncWithPeers synchronizes state with all peers
type TransactionService ¶
type TransactionService struct { protoc.UnimplementedTransactionServiceServer // contains filtered or unexported fields }
TransactionService defines the gRPC service for handling transactions
func (*TransactionService) AppendEntries ¶
func (s *TransactionService) AppendEntries(ctx context.Context, req *protoc.AppendEntriesRequest) (*protoc.AppendEntriesResponse, error)
func (*TransactionService) Auth ¶
func (s *TransactionService) Auth(ctx context.Context, req *protoc.AuthRequest) (*protoc.AuthResponse, error)
func (*TransactionService) Get ¶
func (s *TransactionService) Get(ctx context.Context, req *protoc.GetRequest) (*protoc.GetResponse, error)
func (*TransactionService) HandleTransaction ¶
func (s *TransactionService) HandleTransaction(ctx context.Context, req *protoc.TransactionRequest) (*protoc.TransactionResponse, error)
HandleTransaction handles a transaction request
func (*TransactionService) RequestVote ¶
func (s *TransactionService) RequestVote(ctx context.Context, in *protoc.RequestVoteRequest) (*protoc.RequestVoteResponse, error)
func (*TransactionService) SyncState ¶
func (s *TransactionService) SyncState(ctx context.Context, req *protoc.SyncRequest) (sr *protoc.SyncResponse, e error)
func (*TransactionService) VerifyState ¶
func (s *TransactionService) VerifyState(ctx context.Context, req *protoc.StateVerificationRequest) (svr *protoc.StateVerificationResponse, e error)