handlePeerFailure handles failed peer.
(ctx context.Context, peer *resource.Peer)
| 1202 | |
| 1203 | // handlePeerFailure handles failed peer. |
| 1204 | func (v *V1) handlePeerFailure(ctx context.Context, peer *resource.Peer) { |
| 1205 | if err := peer.FSM.Event(ctx, resource.PeerEventDownloadFailed); err != nil { |
| 1206 | peer.Log.Errorf("peer fsm event failed: %s", err.Error()) |
| 1207 | return |
| 1208 | } |
| 1209 | |
| 1210 | // Reschedule a new parent to children of peer to exclude the current failed peer. |
| 1211 | for _, child := range peer.Children() { |
| 1212 | child.Log.Infof("reschedule parent because of parent peer %s is failed", peer.ID) |
| 1213 | |
| 1214 | // Record the start time. |
| 1215 | start := time.Now() |
| 1216 | v.scheduling.ScheduleParentAndCandidateParents(ctx, child, child.BlockParents) |
| 1217 | |
| 1218 | // Collect SchedulingDuration metrics. |
| 1219 | metrics.ScheduleDuration.Observe(float64(time.Since(start).Milliseconds())) |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | // handleLegacySeedPeer handles seed server's task has left, |
| 1224 | // but did not notify the scheduler to leave the task. |