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

Method triggerSnapshotIfNeed

store/engine/raft/node.go:307–332  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

305}
306
307func (n *Node) triggerSnapshotIfNeed() error {
308 if n.appliedIndex-n.snapshotIndex <= n.snapshotThreshold.Load() {
309 return nil
310 }
311 snapshotBytes, err := n.dataStore.GetDataStoreSnapshot()
312 if err != nil {
313 return err
314 }
315 snap, err := n.dataStore.raftStorage.CreateSnapshot(n.appliedIndex, &n.confState, snapshotBytes)
316 if err != nil {
317 return err
318 }
319 if err := n.dataStore.saveSnapshot(snap); err != nil {
320 return err
321 }
322
323 compactIndex := uint64(1)
324 if n.appliedIndex > n.compactThreshold.Load() {
325 compactIndex = n.appliedIndex - n.compactThreshold.Load()
326 }
327 if err := n.dataStore.raftStorage.Compact(compactIndex); err != nil && !errors.Is(err, raft.ErrCompacted) {
328 return err
329 }
330 n.snapshotIndex = n.appliedIndex
331 return nil
332}
333
334func (n *Node) Set(ctx context.Context, key string, value []byte) error {
335 bytes, err := json.Marshal(&Event{

Callers 1

runRaftMessagesMethod · 0.95

Implementers 1

ClusterNodestore/cluster_node.go

Calls 2

GetDataStoreSnapshotMethod · 0.80
saveSnapshotMethod · 0.80

Tested by

no test coverage detected