Skip to content

Commit

Permalink
ZOOKEEPER-4872: SnapshotCommand should not perform fastForwardFromEdits
Browse files Browse the repository at this point in the history
Author: Li Wang <liwang@apple.com>
  • Loading branch information
liwang committed Nov 4, 2024
1 parent 9d52264 commit fff3f55
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -554,26 +554,21 @@ public File takeSnapshot() throws IOException {
}

public File takeSnapshot(boolean syncSnap) throws IOException {
return takeSnapshot(syncSnap, true, false);
return takeSnapshot(syncSnap, true);
}

/**
* Takes a snapshot on the server.
*
* @param syncSnap syncSnap sync the snapshot immediately after write
* @param isSevere if true system exist, otherwise throw IOException
* @param fastForwardFromEdits whether fast forward database to the latest recorded transactions
*
* @return file snapshot file object
* @throws IOException
*/
public synchronized File takeSnapshot(boolean syncSnap, boolean isSevere, boolean fastForwardFromEdits) throws IOException {
public synchronized File takeSnapshot(boolean syncSnap, boolean isSevere) throws IOException {
long start = Time.currentElapsedTime();
File snapFile = null;
try {
if (fastForwardFromEdits) {
zkDb.fastForwardDataBase();
}
snapFile = txnLogFactory.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts(), syncSnap);
} catch (IOException e) {
if (isSevere) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public CommandResponse runGet(final ZooKeeperServer zkServer, final Map<String,

// take snapshot and stream out data if needed
try {
final File snapshotFile = zkServer.takeSnapshot(false, false, true);
final File snapshotFile = zkServer.takeSnapshot(false, false);
final long lastZxid = Util.getZxidFromName(snapshotFile.getName(), SNAPSHOT_FILE_PREFIX);
response.addHeader(RESPONSE_HEADER_LAST_ZXID, "0x" + ZxidUtils.zxidToString(lastZxid));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testRestoreFromSnapshot() throws Exception {
}

// take Snapshot
final File snapshotFile = zks.takeSnapshot(false, false, true);
final File snapshotFile = zks.takeSnapshot(false, false);
final long lastZxidFromSnapshot = Util.getZxidFromName(snapshotFile.getName(), SNAPSHOT_FILE_PREFIX);

// zk2 create more test data after snapshotting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testTakeSnapshot() throws Exception {
}

// takeSnapshot
zks.takeSnapshot(false, false, true);
zks.takeSnapshot(false, false);

// clean up
zk.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testRestoreAfterQuorumLost() throws Exception {

// create more data after restore
for (int i = NODE_COUNT * 2; i < NODE_COUNT * 3; i++) {
servers.zk[leaderId].create(PATH + "/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
servers.zk[leaderId].create(PATH + "/" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}

// validate all servers have expected data
Expand Down

0 comments on commit fff3f55

Please sign in to comment.