Skip to content
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

SAMZA-1251 - Remove DebounceTimer dependency from ZkLeaderElector & ZkController #153

Closed
wants to merge 45 commits into from

Conversation

navina
Copy link
Contributor

@navina navina commented May 1, 2017

Addresses the following:

  • Makes LeaderElectionListener to be explicitly registered by the caller
  • Removes debouncetimer dependency from ZkLeaderElector implementation
  • [Bug] onBecomeLeader was scheduling a task in timer under "OnBecomeLeader", when it should actually be the same as "OnProcessorChange". Otherwise, it will not cancel when there is a new OnProcessorChange event.
  • [Transient Test Failure] TestScheduleAfterDebounceTime tests were relying on timing controlled by sleep. Fixed it by using latch

navina added 30 commits May 3, 2017 15:07
@navina
Copy link
Contributor Author

navina commented May 3, 2017

@xinyuiscool @sborya Can you guys please review this PR?

@navina navina changed the title SAMZA-1251 - Remove DebounceTimer dependency from ZkLeaderElector SAMZA-1251 - Remove DebounceTimer dependency from ZkLeaderElector & ZkController May 5, 2017
Copy link
Contributor

@xinyuiscool xinyuiscool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks for the cleanup.

@@ -84,7 +73,7 @@ private void timerOff(final String version, final Stat currentStatOfBarrierDone)
zkUtils.getZkClient().writeData(barrierDonePath, BARRIER_TIMED_OUT, currentStatOfBarrierDone.getVersion());
} catch (ZkBadVersionException e) {
// Expected. failed to write, make sure the value is "DONE"
///LOG.("Barrier timeout write failed");
///LOGGER.("Barrier timeout write failed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the commented-out logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

Copy link
Contributor

@sborya sborya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of small nits.

@@ -39,13 +39,9 @@
* ZK based standalone app.
*/
public class ScheduleAfterDebounceTime {
public static final Logger LOG = LoggerFactory.getLogger(ScheduleAfterDebounceTime.class);
public static final Logger LOGGER = LoggerFactory.getLogger(ScheduleAfterDebounceTime.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Samza is using LOG through out the code. I think we should keep it as LOG.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have settled on what is the convention. I have seen both being used. So, I simply decided to keep it consistent within the zk package in core. If you really want this changed, I can do it.

*/
void tryBecomeLeader(LeaderElectorListener leaderElectorListener);
void setLeaderElectorListener(LeaderElectorListener listener);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering, why having a listener as a part of the LE object is better then passing it to the tyBecomeLeader call?
Is there any advantage besides the semantic preferences?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It just makes the code more modularized and testable.
  2. Aside from that, if you are passing some kind of state within a recursive call, you need to manage the lifecycle of that instance in recursive function. It makes the code more vulnerable to bugs.
  3. Speaking of semantics, it is the same callback function that needs to be invoked in every call. So, there is really no need to pass around a listener that doesn't do anything different. Does this make sense?

@@ -36,44 +36,33 @@
* This class creates a barrier for version upgrade.
* Barrier is started by the participant responsible for the upgrade. (start())
* Each participant will mark its readiness and register for a notification when the barrier is reached. (waitFor())
* If a timer (started in start()) goes off before the barrier is reached, all the participants will unsubscribe
* If a timer (started in start()) goes off before the barrier is reached, all the participants will un-subscribe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh, I think unsubscribe is the right form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err.. yeah..I think I was blindly following IntelliJ's spelling suggestion. Thanks! I will fix it.

@@ -22,11 +22,18 @@

/**
* Api to the functionality provided by ZK
*
* Api for JC -> ZK communication
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please just write JC to ZK communication

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) ok

@@ -59,7 +58,7 @@ public Latch getLatch(int size, String latchId) {
public BarrierForVersionUpgrade getBarrier(String barrierId) {
return new ZkBarrierForVersionUpgrade(barrierId, zkUtils, debounceTimer, zkConfig.getZkBarrierTimeoutMs());
}
@VisibleForTesting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remember to get rid of this method completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I tried to get rid of this method. But the ZkBarrierVersionUpgrade depends on not only the timers but also the zkutils. I didn't want to start refactoring those classes as well. Perhaps you can address it as a part of SAMZA-1128
If it makes sense to address this in that JIRA, let me know. I will add a TODO in the code as well.


zkUtils.makeSurePersistentPathsExists(new String[]{keyBuilder.getProcessorsPath()});
}

@VisibleForTesting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I wish we didn't have to do this. Don't have any suggestions at the moment now, but if you do... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine to introduce constructors annotated with @VisibleForTesting. The goal is make it clear that it is not to be used in any case other than testing. I don't see any pressing reason for us to remove the constructor overload.

@asfgit asfgit closed this in fb7aa73 May 5, 2017
asfgit pushed a commit that referenced this pull request May 9, 2017
…bounceTimer

This PR depends on PR #153
* Treats all errors in jobcoordinator as FATAL and shuts-down the streamprocessor
* [Bug] Fixed bug reported in SAMZA-1241
* Introduced a callback to be associated with the timer (same callback for every Runnable failure)

**TBD**: some more unit tests

Author: Navina Ramesh <navina@apache.org>

Reviewers: Xinyu Liu <xiliu@apache.org>, Prateek Maheshwari <pmaheshw@linkedin.com>

Closes #166 from navina/SAMZA-1150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants