You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ca...@apache.org on 2013/05/16 18:49:11 UTC
svn commit: r1483440 - in /zookeeper/trunk: CHANGES.txt
src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
Author: camille
Date: Thu May 16 16:49:11 2013
New Revision: 1483440
URL: http://svn.apache.org/r1483440
Log:
ZOOKEEPER-1642. Leader loading database twice (fpj via camille)
Modified:
zookeeper/trunk/CHANGES.txt
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1483440&r1=1483439&r2=1483440&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Thu May 16 16:49:11 2013
@@ -352,6 +352,8 @@ BUGFIXES:
ZOOKEEPER-1324. Remove Duplicate NEWLEADER packets
from the Leader to the Follower. (Thawan, fpj via fpj)
+
+ ZOOKEEPER-1642. Leader Loading Database Twice (fpj via camille)
IMPROVEMENTS:
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java?rev=1483440&r1=1483439&r2=1483440&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java Thu May 16 16:49:11 2013
@@ -230,7 +230,31 @@ public class ZooKeeperServer implements
* Restore sessions and data
*/
public void loadData() throws IOException, InterruptedException {
- setZxid(zkDb.loadDataBase());
+ /*
+ * When a new leader starts executing Leader#lead, it
+ * invokes this method. The database, however, has been
+ * initialized before running leader election so that
+ * the server could pick its zxid for its initial vote.
+ * It does it by invoking QuorumPeer#getLastLoggedZxid.
+ * Consequently, we don't need to initialize it once more
+ * and avoid the penalty of loading it a second time. Not
+ * reloading it is particularly important for applications
+ * that host a large database.
+ *
+ * The following if block checks whether the database has
+ * been initialized or not. Note that this method is
+ * invoked by at least one other method:
+ * ZooKeeperServer#startdata.
+ *
+ * See ZOOKEEPER-1642 for more detail.
+ */
+ if(zkDb.isInitialized()){
+ setZxid(zkDb.getDataTreeLastProcessedZxid());
+ }
+ else {
+ setZxid(zkDb.loadDataBase());
+ }
+
// Clean up dead sessions
LinkedList<Long> deadSessions = new LinkedList<Long>();
for (Long session : zkDb.getSessions()) {