@@ -24,6 +24,21 @@ type SnapshotNodeHistory struct {
2424 // Threshold is the number of updates before a snapshot is taken.
2525 Threshold uint64
2626
27+ // Compress is the optional callback to compress the history snapshot.
28+ //
29+ // 1. The snapshot should be compressed in place.
30+ // 2. If grouping is used, the last sequence number of a group should be kept.
31+ // Earlier sequence numbers can then be removed.
32+ // 3. #2 implies that the last sequence number cannot be removed.
33+ //
34+ // For example, for snapshot 1, [2, 3, 4], (5), 6, (7), 8, 9, 10:
35+ // - [VALID] 1, [234], 6, (57), 8, 10
36+ // - [INVALID] 1, 4[234], 6, 7(57), 8, 9, 10
37+ // - [INVALID] 1, 3[234], 6, 7(57), 8, 9, 10
38+ // - [INVALID] 1, 4[234], 5(57), 6, 8, 9, 10
39+ // - [INVALID] 1, 4[234], 6, 8, 9, 10
40+ Compress func (* svs_ps.HistorySnap )
41+
2742 // pss is the struct from the svs layer.
2843 pss snapPsState
2944 // prevSeq is my last snapshot sequence number.
@@ -235,7 +250,7 @@ func (s *SnapshotNodeHistory) takeSnap(seqNo uint64) {
235250 index .SeqNos = append (index .SeqNos , seqNo )
236251
237252 // Create a new snapshot
238- snapshot := svs_ps.HistorySnap {
253+ snapshot := & svs_ps.HistorySnap {
239254 Entries : make ([]* svs_ps.HistorySnapEntry , 0 , seqNo - s .prevSeq ),
240255 }
241256
@@ -258,6 +273,11 @@ func (s *SnapshotNodeHistory) takeSnap(seqNo uint64) {
258273 })
259274 }
260275
276+ // Compress the snapshot
277+ if s .Compress != nil {
278+ s .Compress (snapshot )
279+ }
280+
261281 // Publish snapshot into our store
262282 snapName := s .snapName (s .pss .nodePrefix , s .pss .bootTime ).
263283 WithVersion (seqNo )
0 commit comments