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

ZOOKEEPER-3037 - Add JVMPauseMonitor #904

Closed
wants to merge 5 commits into from

Conversation

nkalmar
Copy link
Contributor

@nkalmar nkalmar commented Apr 10, 2019

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Is this code taken from HBase or another ASF project?

@nkalmar
Copy link
Contributor Author

nkalmar commented Apr 10, 2019

Yes, JVMPauseMonitor is taken out of Hadoop Common

@eolivelli
Copy link
Contributor

@eolivelli
Copy link
Contributor

anyway this is a great feature, thanks !

@anmolnar
Copy link
Contributor

@nkalmar Please add some description to the pull request or link the Jira ticket.

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

Overall the code looks good to me, some comments on the testing side:

  • Currently the tests are not unit tests: they're testing multiple things in a single method. We need to split them.
  • Please don't use Thread.sleep() in unit tests,
  • The test file is called JvmPauseMonitorTest, but it's not testing the class that is named of. It tests the configuration parsing logic.
  • Please categorise your unit tests into separate classes based on the single piece of logic that you're testing, e.g. split them into QuorumPeerMainTest, QuorumPeerConfigTest, ServerConfigTest, etc.
  • Tests in JvmPauseMonitorTest should validate and only validate code in JvmPauseMonitor and its dependencies nothing else.
  • Similarly when you test QuorumPeerMain whether it uses JvmPauseMonitor correctly, you should mock JvmPauseMonitor and verify the interaction with mocked methods.

I know that this code has been borrowed from the HBase project, but I'd like to improve the testing side as much as we can without too many modification in the original logic.

@nkalmar nkalmar changed the title Zookeeper 3037 - Add JVMPauseMonitor Zookeeper-3037 - Add JVMPauseMonitor Apr 10, 2019
@nkalmar nkalmar changed the title Zookeeper-3037 - Add JVMPauseMonitor ZOOKEEPER-3037 - Add JVMPauseMonitor Apr 10, 2019
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Awesome.
I left some comments about the test

Assert.assertEquals(sleepTime, Long.valueOf(pauseMonitor.sleepTimeMs));
Assert.assertEquals(infoTH, Long.valueOf(pauseMonitor.infoThresholdMs));

Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to have a loop and wait at most X seconds for the condition to be true.
This way we will reduce flakyness

@nkalmar
Copy link
Contributor Author

nkalmar commented Apr 11, 2019

Thanks guys, refactored the unit tests. While I'm still using Thread.sleep(), the intention has changed. I think this is OK, but let me know if you have another solution to wait until a condition becomes true. (I know there are 3rd party libraries but I didn't want to introduce a dependency)

edit: I could just have an empty while loop or pull the value from JvmPauseMonitor...

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Looks good to me

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

Looking a lot better now. Just a few more nitpicks please.

}
}

String ret = "Detected pause in JVM or host machine (eg GC): pause of approximately " + extraSleepTime
Copy link
Contributor

Choose a reason for hiding this comment

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

Use String.format instead?

final Long warnTH = 5555L;
final Long infoTH = 555L;

QuorumPeerConfig quorumPeerConfig = new MockQuorumPeerConfig(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use the "mocked" version here, it's not needed.

Assert.assertEquals(warnTH, Long.valueOf(pauseMonitor.warnThresholdMs));
Assert.assertEquals(infoTH, Long.valueOf(pauseMonitor.infoThresholdMs));

while(pauseMonitor.getNumGcInfoThresholdExceeded() == 0 && pauseMonitor.getNumGcWarnThresholdExceeded() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to || here instead of &&.

monitorThread.start();
}

public void serviceStop() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is only used in the test currently. Please add it to shutdown() methods of ZooKeeperServer and QuorumPeer classes.

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

+1 lgtm

@nkalmar
Copy link
Contributor Author

nkalmar commented Apr 12, 2019

retest this please

@anmolnar
Copy link
Contributor

retest maven build

@asfgit asfgit closed this in e9adf6e Apr 18, 2019
@anmolnar
Copy link
Contributor

Merged to master. Thanks @nkalmar !

symat pushed a commit to symat/zookeeper that referenced this pull request Feb 5, 2021
https://issues.apache.org/jira/browse/ZOOKEEPER-3037

Author: Norbert Kalmar <[email protected]>

Reviewers: [email protected]

Closes apache#904 from nkalmar/ZOOKEEPER-3037 and squashes the following commits:

a610532 [Norbert Kalmar] ZOOKEEPER-3037 - add serviceStop() and improve unit tests
7d0baaa [Norbert Kalmar] ZOOKEEPER-3037 - refactor unit tests
97d2c61 [Norbert Kalmar] ZOOKEEPER-3037 - cite hadoop-common as source
3661389 [Norbert Kalmar] ZOOKEEPER-3037 - Add unit test and various improvements
f309757 [Norbert Kalmar] ZOOKEEPER-3037 - Add JvmPauseMonitor

(cherry picked from commit e9adf6e)
asfgit pushed a commit that referenced this pull request Feb 9, 2021
Backporting https://issues.apache.org/jira/browse/ZOOKEEPER-3037 from branch-3.6 to branch-3.5.

Author: Norbert Kalmar <nkalmaryahoo.com>

Reviewers: andorapache.org

Closes #904 from nkalmar/ZOOKEEPER-3037 and squashes the following commits:

a610532 [Norbert Kalmar] ZOOKEEPER-3037 - add serviceStop() and improve unit tests
7d0baaa [Norbert Kalmar] ZOOKEEPER-3037 - refactor unit tests
97d2c61 [Norbert Kalmar] ZOOKEEPER-3037 - cite hadoop-common as source
3661389 [Norbert Kalmar] ZOOKEEPER-3037 - Add unit test and various improvements
f309757 [Norbert Kalmar] ZOOKEEPER-3037 - Add JvmPauseMonitor

(cherry picked from commit e9adf6e)

Author: Norbert Kalmar <[email protected]>

Reviewers: Enrico Olivelli <[email protected]>, Mate Szalay-Beko <[email protected]>, Andor Molnar <[email protected]>

Closes #1594 from symat/ZOOKEEPER-3037-branch-3.5
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Sep 3, 2022
https://issues.apache.org/jira/browse/ZOOKEEPER-3037

Author: Norbert Kalmar <[email protected]>

Reviewers: [email protected]

Closes apache#904 from nkalmar/ZOOKEEPER-3037 and squashes the following commits:

a610532 [Norbert Kalmar] ZOOKEEPER-3037 - add serviceStop() and improve unit tests
7d0baaa [Norbert Kalmar] ZOOKEEPER-3037 - refactor unit tests
97d2c61 [Norbert Kalmar] ZOOKEEPER-3037 - cite hadoop-common as source
3661389 [Norbert Kalmar] ZOOKEEPER-3037 - Add unit test and various improvements
f309757 [Norbert Kalmar] ZOOKEEPER-3037 - Add JvmPauseMonitor
@nkalmar nkalmar deleted the ZOOKEEPER-3037 branch October 6, 2022 13:16
anmolnar pushed a commit to anmolnar/zookeeper that referenced this pull request May 21, 2024
https://issues.apache.org/jira/browse/ZOOKEEPER-3037

Author: Norbert Kalmar <[email protected]>

Reviewers: [email protected]

Closes apache#904 from nkalmar/ZOOKEEPER-3037 and squashes the following commits:

a610532 [Norbert Kalmar] ZOOKEEPER-3037 - add serviceStop() and improve unit tests
7d0baaa [Norbert Kalmar] ZOOKEEPER-3037 - refactor unit tests
97d2c61 [Norbert Kalmar] ZOOKEEPER-3037 - cite hadoop-common as source
3661389 [Norbert Kalmar] ZOOKEEPER-3037 - Add unit test and various improvements
f309757 [Norbert Kalmar] ZOOKEEPER-3037 - Add JvmPauseMonitor

(cherry picked from commit e9adf6e)
Change-Id: I7654fc85168bf163bdbbe96ebf73cb9ccf265e81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants