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-4766: Avoid unnecessary snapshots during leader election #2153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,17 @@ public void setZKDatabase(ZKDatabase zkDb) {
}

/**
* Restore sessions and data
* Restore sessions and data, takes a snapshot by default
*/
public void loadData() throws IOException, InterruptedException {
loadData(true);
}

/**
* Restore sessions and data
* @param needSnapshot if true, take a snapshot after loading data
*/
public void loadData(boolean needSnapshot) throws IOException, InterruptedException {
/*
* When a new leader starts executing Leader#lead, it
* invokes this method. The database, however, has been
Expand Down Expand Up @@ -546,7 +554,9 @@ public void loadData() throws IOException, InterruptedException {
.forEach(session -> killSession(session, zkDb.getDataTreeLastProcessedZxid()));

// Make a clean snapshot
Copy link
Member

Choose a reason for hiding this comment

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

Please update the comment in what cases needSnapshot would be true/false and why.

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good, added a comment 👍

takeSnapshot();
if (needSnapshot) {
takeSnapshot();
}
}

public File takeSnapshot() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ void lead() throws IOException, InterruptedException {
try {
self.setZabState(QuorumPeer.ZabState.DISCOVERY);
self.tick.set(0);
zk.loadData();
zk.loadData(false);

leaderStateSummary = new StateSummary(self.getCurrentEpoch(), zk.getLastProcessedZxid());

Expand Down
Loading