You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2022/10/21 09:47:37 UTC
[GitHub] [druid] cryptoe opened a new pull request, #13251: [Draft] Adding new state to leader election
cryptoe opened a new pull request, #13251:
URL: https://github.com/apache/druid/pull/13251
<!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
<!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
Currently, in the Druid Leader selector, we have 2 states only. Either the process is a leader or not.
But we need a 3rd state which represents an initialized leader on which external callers should gate on.
According to the zookeeper, once we receive the callback inside `LeaderLatchListener#isLeader()` that candidate is the leader. In Druid, we can take some time in running the `DruidLeaderSelector#listener` since there are a lot of DB operations done in both the overlord and the coordinator which can take time. Also for all "endpoints", a leader is usable only when it's initialized.
Another race condition was how `CuratorDruidLeaderSelector` was updating the boolean variable `leader`.
As `DruidLeaderSelector#listener#becomeLeader()` can take some time to run, zk can choose to change leadership behind the scenes. So now we can have two processes thinking they are the leaders. Changed `CuratorDruidLeaderSelector#isLeader()` to gate on the "latchStatus" rather than the local boolean `leader` variable.
As the `leader` variable is updated in a single-threaded executor service the following situation can very well happen.
Lets say we have two overlords foo, bar.
```
t0: foo is chosen the leader by ZK, print "Grayskull"----------------------------------------t10: initialized
----t1: notLeader listener is called but is waiting cause exec is single threaded -------------------t11: bar isNotLeader()-> leader =false
-------t2: bar is leader, print "Grayskull"-----------t5: initialized
```
Between t5-t11, both foo,bar think they are the leaders.
##### Key changed/added classes in this PR
* `DruidLeaderSelector`
* `CuratorLeaderSelector`
* `DruidCoordinator`
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Adding new state to leader election (druid)
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #13251: Adding new state to leader election
URL: https://github.com/apache/druid/pull/13251
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Adding new state to leader election (druid)
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13251:
URL: https://github.com/apache/druid/pull/13251#issuecomment-1935130615
This pull request/issue has been closed due to lack of activity. If you think that
is incorrect, or the pull request requires review, you can revive the PR at any time.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] churromorales commented on pull request #13251: Adding new state to leader election
Posted by GitBox <gi...@apache.org>.
churromorales commented on PR #13251:
URL: https://github.com/apache/druid/pull/13251#issuecomment-1309377209
does this not affect the `druid-kubernetes-extensions` where it is k8s based?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] cryptoe commented on pull request #13251: Adding new state to leader election
Posted by GitBox <gi...@apache.org>.
cryptoe commented on PR #13251:
URL: https://github.com/apache/druid/pull/13251#issuecomment-1286740140
UT's are incoming :)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Adding new state to leader election (druid)
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13251:
URL: https://github.com/apache/druid/pull/13251#issuecomment-1885969390
This pull request has been marked as stale due to 60 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If you think
that's incorrect or this pull request should instead be reviewed, please simply
write any comment. Even if closed, you can still revive the PR at any time or
discuss it on the dev@druid.apache.org list.
Thank you for your contributions.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
[GitHub] [druid] kfaraz commented on a diff in pull request #13251: Adding new state to leader election
Posted by GitBox <gi...@apache.org>.
kfaraz commented on code in PR #13251:
URL: https://github.com/apache/druid/pull/13251#discussion_r1001765586
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskMaster.java:
##########
@@ -236,8 +227,10 @@ public Optional<String> getRedirectLocation()
String leader = overlordLeaderSelector.getCurrentLeader();
// do not redirect when
// leader is not elected
- // leader is the current node
- if (leader == null || leader.isEmpty() || overlordLeaderSelector.isLeader()) {
+ // leader is the current node but not intialized.
+ if (leader == null
+ || leader.isEmpty()
+ || overlordLeaderSelector.isLeader() == DruidLeaderSelector.LeaderState.ELECTED) {
Review Comment:
Shouldn't this also include the case when `isLeader` returns `INITIALIZED`?
##########
server/src/main/java/org/apache/druid/rpc/ServiceClient.java:
##########
@@ -37,7 +37,7 @@
*/
public interface ServiceClient
{
- long MAX_REDIRECTS = 3;
+ long MAX_REDIRECTS = 5;
Review Comment:
Maybe add a comment on why we need this value at 5.
##########
server/src/main/java/org/apache/druid/server/coordinator/DruidCoordinator.java:
##########
@@ -731,7 +759,7 @@ private void stopBeingLeader()
lookupCoordinatorManager.stop();
metadataRuleManager.stop();
segmentsMetadataManager.stopPollingDatabasePeriodically();
-
+ exec.shutdownNow();
Review Comment:
This need not be shutdown here as each `DutiesRunnable` which runs on this executor individually checks whether it should REPEAT or STOP.
If we do want to shutdown to be sure, however, then we must also re-initialize it in `becomeLeader`.
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/TaskMaster.java:
##########
@@ -170,7 +161,7 @@ public void stopBeingLeader()
{
giant.lock();
try {
- initialized = false;
Review Comment:
Doesn't removing this mean that we miss out on the state of initialization of this class itself?
##########
server/src/main/java/org/apache/druid/server/coordinator/DruidCoordinator.java:
##########
@@ -873,10 +901,14 @@ public void run()
try {
final long globalStart = System.nanoTime();
synchronized (lock) {
- if (!coordLeaderSelector.isLeader()) {
- log.info("LEGGO MY EGGO. [%s] is leader.", coordLeaderSelector.getCurrentLeader());
+ DruidLeaderSelector.LeaderState leaderState = coordLeaderSelector.isLeader();
+ if (leaderState == DruidLeaderSelector.LeaderState.NOT_ELECTED) {
+ log.info("I am no longer the leader. Current leader is [%s].", coordLeaderSelector.getCurrentLeader());
stopBeingLeader();
return;
+ } else if (leaderState == DruidLeaderSelector.LeaderState.ELECTED) {
+ throw new ISE(
Review Comment:
Better to just log an error here and return.
An exception thrown here is just caught, logged and swallowed in `ScheduledExecutors.scheduledAtFixedRate()`.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org