ruanwenjun commented on code in PR #16873:
URL:
https://github.com/apache/dolphinscheduler/pull/16873#discussion_r1888121844
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/ha/AbstractHAServer.java:
##########
@@ -78,21 +83,30 @@ public boolean isActive() {
@Override
public boolean participateElection() {
final String electionLock = selectorPath + "-lock";
- try {
- if (registry.acquireLock(electionLock)) {
- if (!registry.exists(selectorPath)) {
- registry.put(selectorPath, serverIdentify, true);
- return true;
+ // If meet exception during participate election, will retry.
+ // This can avoid the situation that the server is not elected as
leader due to network jitter.
+ for (int i = 0; i < DEFAULT_MAX_RETRY_TIMES; i++) {
+ try {
+ try {
+ if (registry.acquireLock(electionLock)) {
+ if (!registry.exists(selectorPath)) {
+ registry.put(selectorPath, serverIdentify, true);
+ return true;
+ }
+ return
serverIdentify.equals(registry.get(selectorPath));
+ }
+ return false;
+ } finally {
+ registry.releaseLock(electionLock);
}
Review Comment:
The lock is only used when cluster changed, after selected an active server,
the lock will be released, so the lock will only hold for a short time. This is
only used for election, we use the lock here to make sure all registry plugins
can implement the election method in an easy way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]