MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / applyEntry

Method applyEntry

store/engine/raft/node.go:471–509  ·  view source on GitHub ↗
(entry raftpb.Entry)

Source from the content-addressed store, hash-verified

469}
470
471func (n *Node) applyEntry(entry raftpb.Entry) error {
472 switch entry.Type {
473 case raftpb.EntryNormal:
474 return n.dataStore.applyDataEntry(entry)
475 case raftpb.EntryConfChangeV2, raftpb.EntryConfChange:
476 // apply config change to the state machine
477 var cc raftpb.ConfChange
478 if err := cc.Unmarshal(entry.Data); err != nil {
479 return err
480 }
481
482 n.confState = *n.raftNode.ApplyConfChange(cc)
483 switch cc.Type {
484 case raftpb.ConfChangeAddNode:
485 if cc.NodeID != n.config.ID && len(cc.Context) > 0 {
486 n.logger.Info("Add the new peer", zap.String("context", string(cc.Context)))
487 n.transport.AddPeer(types.ID(cc.NodeID), []string{string(cc.Context)})
488 n.peers.Store(cc.NodeID, string(cc.Context))
489 }
490 case raftpb.ConfChangeRemoveNode:
491 if cc.NodeID == n.config.ID {
492 n.logger.Info("I have been removed from the cluster, will shutdown")
493 n.Close()
494 return nil
495 }
496 n.transport.RemovePeer(types.ID(cc.NodeID))
497 n.peers.Delete(cc.NodeID)
498 n.logger.Info("Remove the peer", zap.Uint64("node_id", cc.NodeID))
499 case raftpb.ConfChangeUpdateNode:
500 n.transport.UpdatePeer(types.ID(cc.NodeID), []string{string(cc.Context)})
501 if _, ok := n.peers.Load(cc.NodeID); ok {
502 n.peers.Store(cc.NodeID, string(cc.Context))
503 }
504 case raftpb.ConfChangeAddLearnerNode:
505 // TODO: add the learner node
506 }
507 }
508 return nil
509}
510
511func (n *Node) Process(ctx context.Context, m raftpb.Message) error {
512 return n.raftNode.Step(ctx, m)

Callers 1

applyEntriesMethod · 0.95

Implementers 1

ClusterNodestore/cluster_node.go

Calls 9

CloseMethod · 0.95
applyDataEntryMethod · 0.80
InfoMethod · 0.80
AddPeerMethod · 0.80
RemovePeerMethod · 0.80
UpdatePeerMethod · 0.80
IDMethod · 0.65
DeleteMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected