return nil when genearte snapshot failed (#206)

Co-authored-by: Connor <zbk602423539@gmail.com>
This commit is contained in:
xiongjiwei 2020-06-28 15:18:49 +08:00 committed by GitHub
parent 3513f5d1b4
commit cb91131143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -156,7 +156,9 @@ func (ps *PeerStorage) Snapshot() (eraftpb.Snapshot, error) {
if ps.snapState.StateType == snap.SnapState_Generating { if ps.snapState.StateType == snap.SnapState_Generating {
select { select {
case s := <-ps.snapState.Receiver: case s := <-ps.snapState.Receiver:
snapshot = *s if s != nil {
snapshot = *s
}
default: default:
return snapshot, raft.ErrSnapshotTemporarilyUnavailable return snapshot, raft.ErrSnapshotTemporarilyUnavailable
} }

View File

@ -82,6 +82,7 @@ func (snapCtx *snapContext) handleGen(regionId uint64, notifier chan<- *eraftpb.
snap, err := doSnapshot(snapCtx.engines, snapCtx.mgr, regionId) snap, err := doSnapshot(snapCtx.engines, snapCtx.mgr, regionId)
if err != nil { if err != nil {
log.Errorf("failed to generate snapshot!!!, [regionId: %d, err : %v]", regionId, err) log.Errorf("failed to generate snapshot!!!, [regionId: %d, err : %v]", regionId, err)
notifier <- nil
} else { } else {
notifier <- snap notifier <- snap
} }