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-4858: Remove the lock contention between snapshotting and the sync operation #2185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -135,6 +135,8 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
public static final String CLOSE_SESSION_TXN_ENABLED = "zookeeper.closeSessionTxn.enabled";
private static boolean closeSessionTxnEnabled = true;
private volatile CountDownLatch restoreLatch;
// exclusive lock for taking snapshot and restore
private final Object snapshotAndRestoreLock = new Object();

static {
LOG = LoggerFactory.getLogger(ZooKeeperServer.class);
Expand Down Expand Up @@ -567,14 +569,16 @@ public File takeSnapshot(boolean syncSnap) throws IOException {
* @return file snapshot file object
* @throws IOException
*/
public synchronized File takeSnapshot(boolean syncSnap, boolean isSevere, boolean fastForwardFromEdits) throws IOException {
public File takeSnapshot(boolean syncSnap, boolean isSevere, boolean fastForwardFromEdits) throws IOException {
long start = Time.currentElapsedTime();
File snapFile = null;
try {
if (fastForwardFromEdits) {
zkDb.fastForwardDataBase();
synchronized (snapshotAndRestoreLock) {
if (fastForwardFromEdits) {
zkDb.fastForwardDataBase();
}
snapFile = txnLogFactory.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts(), syncSnap);
}
snapFile = txnLogFactory.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts(), syncSnap);
} catch (IOException e) {
if (isSevere) {
LOG.error("Severe unrecoverable error, exiting", e);
Expand All @@ -598,7 +602,7 @@ public synchronized File takeSnapshot(boolean syncSnap, boolean isSevere, boolea
* @Return last processed zxid
* @throws IOException
*/
public synchronized long restoreFromSnapshot(final InputStream inputStream) throws IOException {
public long restoreFromSnapshot(final InputStream inputStream) throws IOException {
if (inputStream == null) {
throw new IllegalArgumentException("InputStream can not be null when restoring from snapshot");
}
Expand All @@ -623,9 +627,10 @@ public synchronized long restoreFromSnapshot(final InputStream inputStream) thro
restoreLatch = new CountDownLatch(1);

try {
// set to the new zkDatabase
setZKDatabase(newZKDatabase);

synchronized (snapshotAndRestoreLock) {
// set to the new zkDatabase
setZKDatabase(newZKDatabase);
}
// re-create SessionTrack
createSessionTracker();
} finally {
Expand Down
Loading