MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / followerApply

Method followerApply

kayak/runtime.go:413–469  ·  view source on GitHub ↗
(l *kt.Log, checkPrepare bool)

Source from the content-addressed store, hash-verified

411}
412
413func (r *Runtime) followerApply(l *kt.Log, checkPrepare bool) (err error) {
414 if l == nil {
415 err = errors.Wrap(kt.ErrInvalidLog, "log is nil")
416 return
417 }
418 if atomic.LoadUint32(&r.started) != 1 {
419 err = kt.ErrStopped
420 return
421 }
422
423 ctx, task := trace.NewTask(context.Background(), "Kayak.FollowerApply."+l.Type.String())
424 defer task.End()
425
426 tm := timer.NewTimer()
427
428 var storageErr error
429
430 defer func() {
431 log.
432 WithFields(log.Fields{
433 "t": l.Type.String(),
434 "i": l.Index,
435 "se": storageErr,
436 }).
437 WithFields(tm.ToLogFields()).
438 WithError(err).
439 Debug("kayak follower apply")
440 }()
441
442 r.peersLock.RLock()
443 defer r.peersLock.RUnlock()
444
445 tm.Add("peers_lock")
446
447 if r.role == proto.Leader {
448 // not follower
449 err = kt.ErrNotFollower
450 return
451 }
452
453 // verify log structure
454 switch l.Type {
455 case kt.LogPrepare:
456 err = r.followerPrepare(ctx, tm, l, checkPrepare)
457 case kt.LogRollback:
458 err = r.followerRollback(ctx, tm, l)
459 case kt.LogCommit:
460 storageErr, err = r.followerCommit(ctx, tm, l)
461 }
462
463 if err == nil {
464 r.updateNextIndex(ctx, l)
465 r.triggerLogAwaits(l)
466 }
467
468 return
469}

Callers 2

FollowerApplyMethod · 0.95
runMethod · 0.80

Calls 15

ToLogFieldsMethod · 0.95
AddMethod · 0.95
followerPrepareMethod · 0.95
followerRollbackMethod · 0.95
followerCommitMethod · 0.95
updateNextIndexMethod · 0.95
triggerLogAwaitsMethod · 0.95
NewTaskFunction · 0.92
NewTimerFunction · 0.92
WithFieldsFunction · 0.92
DebugMethod · 0.80
WithErrorMethod · 0.80

Tested by

no test coverage detected