MCPcopy
hub / github.com/dgraph-io/dgraph / CreateSnapshot

Method CreateSnapshot

raftwal/storage.go:273–303  ·  view source on GitHub ↗

---------------- Raft.Storage interface complete. CreateSnapshot generates a snapshot with the given ConfState and data and writes it to disk.

(i uint64, cs *raftpb.ConfState, data []byte)

Source from the content-addressed store, hash-verified

271
272// CreateSnapshot generates a snapshot with the given ConfState and data and writes it to disk.
273func (w *DiskStorage) CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte) error {
274 glog.V(2).Infof("CreateSnapshot i=%d, cs=%+v", i, cs)
275
276 w.lock.Lock()
277 defer w.lock.Unlock()
278
279 first := w.firstIndex()
280 if i < first {
281 glog.Errorf("i=%d<first=%d, ErrSnapOutOfDate", i, first)
282 return raft.ErrSnapOutOfDate
283 }
284
285 e, err := w.wal.seekEntry(i)
286 if err != nil {
287 return err
288 }
289
290 var snap raftpb.Snapshot
291 snap.Metadata.Index = i
292 snap.Metadata.Term = e.Term()
293 x.AssertTrue(cs != nil)
294 snap.Metadata.ConfState = *cs
295 snap.Data = data
296
297 if err := w.meta.StoreSnapshot(&snap); err != nil {
298 return err
299 }
300 // Now we delete all the files which are below the snapshot index.
301 w.wal.deleteBefore(snap.Metadata.Index)
302 return nil
303}
304
305// TODO(Aman): In the raft example here, we store the snapshot first, followed by entries
306// and then, hard state. https://github.com/etcd-io/etcd/blob/main/contrib/raftexample/raft.go

Callers 6

applySnapshotMethod · 0.80
overwriteSnapshotFunction · 0.80
TestCalculateSnapshotFunction · 0.80
applyCommittedMethod · 0.80
TestStorageBigFunction · 0.80

Calls 10

firstIndexMethod · 0.95
AssertTrueFunction · 0.92
InfofMethod · 0.80
seekEntryMethod · 0.80
StoreSnapshotMethod · 0.80
deleteBeforeMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45
ErrorfMethod · 0.45
TermMethod · 0.45

Tested by 3

TestCalculateSnapshotFunction · 0.64
TestStorageBigFunction · 0.64