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-4712: Follower.shutdown() and Observer.shutdown() do not correctly shutdown the syncProcessor, which may lead to data inconsistency #2032

Closed

Conversation

AlphaCanisMajoris
Copy link
Contributor

See ZOOKEEPER-4712 for more details.

This fix ensures that Follower.shutdown() and Observer.shutdown() will invoke syncProcessor.shutdown() correctly.
Besides, it ensures that syncProcessor.shutdown() will happen before zkDb.fastForwardDataBase(), which avoids possible data inconsistency.

…rrectly shutdown the syncProcessor, which may lead to data inconsistency
if (shutdownZKServer(fullyShutDown)) {
try {
if (syncProcessor != null) {
syncProcessor.shutdown();
Copy link

Choose a reason for hiding this comment

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

7% of developers fix this issue

THREAD_SAFETY_VIOLATION: Unprotected write. Non-private method LearnerZooKeeperServer.shutdown(...) indirectly writes to field this.syncProcessor.lastFlushTime outside of synchronization.
Reporting because another access to the same memory occurs on a background thread, although this access may not.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

Can you add a test case to simulate the bug you spot? I can understand it while a test case is expressive and prevent regressions.

* @param fullyShutDown true if another server using the same database will not replace this one in the same process
* @return true if the server is successfully shutdown, false if the server cannot be shutdown.
*/
public synchronized boolean shutdownZKServer(boolean fullyShutDown) {
Copy link
Member

Choose a reason for hiding this comment

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

Will these two new methods be protected? I don't think they are intended to be called by app users.

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 think protected will be enough for these two methods. I will correct it later.

@AlphaCanisMajoris
Copy link
Contributor Author

Can you add a test case to simulate the bug you spot? I can understand it while a test case is expressive and prevent regressions.

Sure I will try. Note that the bug is subtle and needs to be exposed with careful timing of multi-thread events. I will try to build a test case for the bug triggering.

…rrectly shutdown the syncProcessor, which may lead to data inconsistency
@kezhuw
Copy link
Member

kezhuw commented Sep 21, 2024

Superceded by #2154.

Thank you for your contribution! @AlphaCanisMajoris

@kezhuw kezhuw closed this Sep 21, 2024
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