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 #2085

Open
wants to merge 1 commit into
base: branch-3.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -504,9 +504,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 @@ -537,7 +545,9 @@ public void loadData() throws IOException, InterruptedException {
.forEach(session -> killSession(session, zkDb.getDataTreeLastProcessedZxid()));

// Make a clean snapshot
takeSnapshot();
if (needSnapshot) {
takeSnapshot();
}
}

public void takeSnapshot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,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