Skip to content

Commit

Permalink
dragonboat: fixed snapshot compction
Browse files Browse the repository at this point in the history
Previously, snapshot compaction is triggerred everytime when an incoming
snapshot is saved. This can potentially delete snapshots that are about
to be restored.
  • Loading branch information
lni committed Aug 8, 2020
1 parent e14b6a5 commit 26d7877
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
3 changes: 0 additions & 3 deletions execengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,9 +977,6 @@ func (s *execEngine) onSnapshotSaved(updates []pb.Update,
if err := node.removeSnapshotFlagFile(ud.Snapshot.Index); err != nil {
return err
}
if err := node.compactSnapshots(ud.Snapshot.Index); err != nil {
return err
}
}
}
return nil
Expand Down
23 changes: 10 additions & 13 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func (n *node) compactSnapshot(req rsm.SSRequest, index uint64) error {
if index > compactionOverhead {
n.ss.setCompactLogTo(index - compactionOverhead)
}
return n.snapshotter.Compact(index)
return n.compactSnapshots(index)
}

func (n *node) getCompactionOverhead(req rsm.SSRequest) uint64 {
Expand Down Expand Up @@ -771,7 +771,7 @@ func (n *node) recoverFromSnapshot(rec rsm.Task) (uint64, error) {
return 0, err
}
}
if err := n.snapshotter.Compact(index); err != nil {
if err := n.compactSnapshots(index); err != nil {
plog.Errorf("%s snapshotter.Compact failed %v", n.id(), err)
return 0, err
}
Expand Down Expand Up @@ -857,18 +857,15 @@ func (n *node) shrinkSnapshots(index uint64) error {
}

func (n *node) compactSnapshots(index uint64) error {
if n.snapshotLock.TryLock() {
defer n.snapshotLock.Unlock()
if err := n.snapshotter.Compact(index); err != nil {
return err
}
n.sysEvents.Publish(server.SystemEvent{
Type: server.SnapshotCompacted,
ClusterID: n.clusterID,
NodeID: n.nodeID,
Index: index,
})
if err := n.snapshotter.Compact(index); err != nil {
return err
}
n.sysEvents.Publish(server.SystemEvent{
Type: server.SnapshotCompacted,
ClusterID: n.clusterID,
NodeID: n.nodeID,
Index: index,
})
return nil
}

Expand Down

0 comments on commit 26d7877

Please sign in to comment.