Giter Club home page Giter Club logo

Comments (7)

Black-max12138 avatar Black-max12138 commented on July 4, 2024

Based on the code inference, we infer that the following situation occurs:
1、The lease queried before the controller-manager request of the master1 node times out is the penultimate renewal of the controller-manager before the master2 node is powered off, not the last renewal.
2、After controller-manager of master2 updates the lease, controller-manager of master1 fails to obtain the latest lease due to the persistent connection of http2.
3、When the http2 connection is disconnected and reconnected, the latest lease information is obtained.
4、However, the lease in the memory is not the latest lease. Therefore, le.observedTime is updated to the current time based on the code.

if !bytes.Equal(le.observedRawRecord, oldLeaderElectionRawRecord) {
le.setObservedRecord(oldLeaderElectionRecord)
le.observedRawRecord = oldLeaderElectionRawRecord
}
if len(oldLeaderElectionRecord.HolderIdentity) > 0 &&
le.observedTime.Add(time.Second*time.Duration(oldLeaderElectionRecord.LeaseDurationSeconds)).After(now.Time) &&
!le.IsLeader() {
klog.V(4).Infof("lock is held by %v and has not yet expired", oldLeaderElectionRecord.HolderIdentity)
return false
}

So the question is why does le.setObservedRecord update observedTime to the current time instead of renewTime?
func (le *LeaderElector) setObservedRecord(observedRecord *rl.LeaderElectionRecord) {
le.observedRecordLock.Lock()
defer le.observedRecordLock.Unlock()
le.observedRecord = *observedRecord
le.observedTime = le.clock.Now()
}

If update observedTime to renewTime, does that fix the problem?

from kubernetes.

zhifei92 avatar zhifei92 commented on July 4, 2024

/sig apps

from kubernetes.

mengjiao-liu avatar mengjiao-liu commented on July 4, 2024

/triage accepted

from kubernetes.

zhifei92 avatar zhifei92 commented on July 4, 2024

If update observedTime to renewTime, does that fix the problem?

observedTime is necessary .Utilizing observedTime contributes to ensuring consistency, robustness, and correctness in the election process.

from kubernetes.

zhifei92 avatar zhifei92 commented on July 4, 2024

The log entries you've shared indicate a situation where master1, already recognized as the leader, is inexplicably initiating another leadership acquisition attempt.

Consider testing version 1.30 to check if the problem remains unresolved. The following code should alleviate your issue to some degree:

func (le *LeaderElector) tryAcquireOrRenew(ctx context.Context) bool {
now := metav1.NewTime(le.clock.Now())
leaderElectionRecord := rl.LeaderElectionRecord{
HolderIdentity: le.config.Lock.Identity(),
LeaseDurationSeconds: int(le.config.LeaseDuration / time.Second),
RenewTime: now,
AcquireTime: now,
}
// 1. fast path for the leader to update optimistically assuming that the record observed
// last time is the current version.
if le.IsLeader() && le.isLeaseValid(now.Time) {
oldObservedRecord := le.getObservedRecord()
leaderElectionRecord.AcquireTime = oldObservedRecord.AcquireTime
leaderElectionRecord.LeaderTransitions = oldObservedRecord.LeaderTransitions
err := le.config.Lock.Update(ctx, leaderElectionRecord)
if err == nil {
le.setObservedRecord(&leaderElectionRecord)
return true
}
klog.Errorf("Failed to update lock optimitically: %v, falling back to slow path", err)
}

from kubernetes.

Black-max12138 avatar Black-max12138 commented on July 4, 2024

The log entries you've shared indicate a situation where master1, already recognized as the leader, is inexplicably initiating another leadership acquisition attempt.

Consider testing version 1.30 to check if the problem remains unresolved. The following code should alleviate your issue to some degree:

func (le *LeaderElector) tryAcquireOrRenew(ctx context.Context) bool {
now := metav1.NewTime(le.clock.Now())
leaderElectionRecord := rl.LeaderElectionRecord{
HolderIdentity: le.config.Lock.Identity(),
LeaseDurationSeconds: int(le.config.LeaseDuration / time.Second),
RenewTime: now,
AcquireTime: now,
}
// 1. fast path for the leader to update optimistically assuming that the record observed
// last time is the current version.
if le.IsLeader() && le.isLeaseValid(now.Time) {
oldObservedRecord := le.getObservedRecord()
leaderElectionRecord.AcquireTime = oldObservedRecord.AcquireTime
leaderElectionRecord.LeaderTransitions = oldObservedRecord.LeaderTransitions
err := le.config.Lock.Update(ctx, leaderElectionRecord)
if err == nil {
le.setObservedRecord(&leaderElectionRecord)
return true
}
klog.Errorf("Failed to update lock optimitically: %v, falling back to slow path", err)
}

I think you may have missed my point. What I want to know is why observedTime is used instead of renewTime to determine if the lease has expired.

if len(oldLeaderElectionRecord.HolderIdentity) > 0 &&
le.observedTime.Add(time.Second*time.Duration(oldLeaderElectionRecord.LeaseDurationSeconds)).After(now.Time) &&
!le.IsLeader() {
klog.V(4).Infof("lock is held by %v and has not yet expired", oldLeaderElectionRecord.HolderIdentity)
return false
}

from kubernetes.

zhifei92 avatar zhifei92 commented on July 4, 2024

I think you may have missed my point. What I want to know is why observedTime is used instead of renewTime to determine if the lease has expired.

No, I know what you mean. As I said above, you can't do it this way.

from kubernetes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.