-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor/Clean leader election related classes #5937
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
|
||
import java.net.HttpURLConnection; | ||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
|
@@ -46,10 +45,9 @@ public class LeaderElector { | |
|
||
protected static final Double JITTER_FACTOR = 1.2; | ||
|
||
private KubernetesClient kubernetesClient; | ||
private LeaderElectionConfig leaderElectionConfig; | ||
private final KubernetesClient kubernetesClient; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
private final LeaderElectionConfig leaderElectionConfig; | ||
private final AtomicReference<LeaderElectionRecord> observedRecord = new AtomicReference<>(); | ||
private final AtomicReference<LocalDateTime> observedTime = new AtomicReference<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dropped the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why this was added on the first place. I need to do some digging before we can merge this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The go client switch how time was tracked so that it was local to each elector, but we never fully implemented that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I traced it back to the initial implementation but it was never used. I guess I left that there for a follow up. |
||
private final Executor executor; | ||
private boolean started; | ||
private boolean stopped; | ||
|
@@ -254,7 +252,6 @@ synchronized boolean tryAcquireOrRenew() { | |
private void updateObserved(LeaderElectionRecord leaderElectionRecord) { | ||
final LeaderElectionRecord current = observedRecord.getAndSet(leaderElectionRecord); | ||
if (!Objects.equals(leaderElectionRecord, current)) { | ||
observedTime.set(LocalDateTime.now()); | ||
final String currentLeader = current == null ? null : current.getHolderIdentity(); | ||
final String newLeader = leaderElectionRecord.getHolderIdentity(); | ||
if (!Objects.equals(newLeader, currentLeader)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just add
final
, nothing more changes in this class