-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[ZOOKEEPER-3657] Implementing snapshot schedule to avoid high latency issue due to disk contention #1191
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
base: master
Are you sure you want to change the base?
[ZOOKEEPER-3657] Implementing snapshot schedule to avoid high latency issue due to disk contention #1191
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,14 @@ public class ZooDefs { | |
|
|
||
| public static final String ZOOKEEPER_NODE_SUBTREE = "/zookeeper/"; | ||
|
|
||
| /** | ||
| * WARN: please don't retain the order, which is used to check | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you mean "don't change" or "retain", as opposed to "don't retain"? my understanding is the order must be preserved here for the code to work. |
||
| * the op during snapshot schedule. | ||
| */ | ||
| public enum SnapPingCode { | ||
| CHECK, SNAP, SKIP, CANCEL; | ||
| } | ||
|
|
||
| @InterfaceAudience.Public | ||
| public interface OpCode { | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.zookeeper.server; | ||
|
|
||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Util class Used to control the behavior abouthow we take snapshot. | ||
| */ | ||
| public class SnapshotGenerator { | ||
| private static final Logger LOG = LoggerFactory.getLogger(SnapshotGenerator.class); | ||
|
|
||
| public static final String PURGE_AFTER_SNAPSHOT = "zookeeper.purgeAfterSnapshot.enabled"; | ||
| private static boolean purgeAfterSnapshot; | ||
|
|
||
| public static final String FSYNC_SNAPSHOT_FROM_SCHEDULER = "zookeeper.fsyncSnapshotFromScheduler"; | ||
| private static boolean fsyncSnapshotFromScheduler; | ||
|
|
||
| static { | ||
| purgeAfterSnapshot = Boolean.getBoolean(PURGE_AFTER_SNAPSHOT); | ||
| LOG.info("{} = {}", PURGE_AFTER_SNAPSHOT, purgeAfterSnapshot); | ||
|
|
||
| fsyncSnapshotFromScheduler = Boolean.parseBoolean( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use Boolean.getBoolean so it's consistent with previous property parsing code (also less verbose)? |
||
| System.getProperty(FSYNC_SNAPSHOT_FROM_SCHEDULER, "true")); | ||
| LOG.info("{} = {}", FSYNC_SNAPSHOT_FROM_SCHEDULER, fsyncSnapshotFromScheduler); | ||
| } | ||
|
|
||
| public static boolean getPurgeAfterSnapshot() { | ||
| return purgeAfterSnapshot; | ||
| } | ||
|
|
||
| public static void setPurgeAfterSnapshot(boolean enabled) { | ||
| purgeAfterSnapshot = enabled; | ||
| LOG.info("{} = {}", PURGE_AFTER_SNAPSHOT, purgeAfterSnapshot); | ||
| } | ||
|
|
||
| public static void setFsyncSnapshotFromScheduler(boolean fsync) { | ||
| fsyncSnapshotFromScheduler = fsync; | ||
| LOG.info("{} = {}", FSYNC_SNAPSHOT_FROM_SCHEDULER, fsyncSnapshotFromScheduler); | ||
| } | ||
|
|
||
| public static boolean getFsyncSnapshotFromScheduler() { | ||
| return fsyncSnapshotFromScheduler; | ||
| } | ||
|
|
||
| private final ZooKeeperServer zks; | ||
| private final ExecutorService worker; | ||
| private final AtomicBoolean isTakingSnapshot; | ||
|
|
||
| public SnapshotGenerator(final ZooKeeperServer zks) { | ||
| this.zks = zks; | ||
| this.worker = Executors.newFixedThreadPool(1); | ||
| this.isTakingSnapshot = new AtomicBoolean(false); | ||
| } | ||
|
|
||
| public boolean takeSnapshot(boolean syncSnap) { | ||
| // Only allow a single snapshot in progress. | ||
| if (isTakingSnapshot.compareAndSet(false, true)) { | ||
| this.worker.execute(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| try { | ||
| zks.takeSnapshot(syncSnap); | ||
| if (purgeAfterSnapshot) { | ||
| zks.purge(); | ||
| } | ||
| } catch (Exception e) { | ||
| LOG.warn("Unexpected exception", e); | ||
| } finally { | ||
| isTakingSnapshot.compareAndSet(true, false); | ||
| } | ||
| } | ||
| }); | ||
| return true; | ||
| } else { | ||
| LOG.warn("Previous snapshot is still in-flight, too busy to snap, skipping"); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public boolean isSnapInProgress() { | ||
| return isTakingSnapshot.get(); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these really java system properties only? Put a config foo in zoo.cfg and ZK will parse them and generate a zookeeoer.foo. similar for other "java only system properties" listed here. might need update doc.