zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject zookeeper git commit: ZOOKEEPER-2662: Export a metric for txn log sync times
Date Fri, 28 Apr 2017 15:58:05 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.5 7dfaeb4de -> 1a4042be5


ZOOKEEPER-2662: Export a metric for txn log sync times

Addressed review comments

Author: Edward Ribeiro <edward.ribeiro@gmail.com>

Reviewers: Michael Han <hanm@apache.org>

Closes #243 from eribeiro/ZOOKEEPER-2662-branch-3.5


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/1a4042be
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/1a4042be
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/1a4042be

Branch: refs/heads/branch-3.5
Commit: 1a4042be56d97c66a21f76b48cf44fc7baabf538
Parents: 7dfaeb4
Author: Edward Ribeiro <edward.ribeiro@gmail.com>
Authored: Fri Apr 28 08:58:01 2017 -0700
Committer: Michael Han <hanm@apache.org>
Committed: Fri Apr 28 08:58:01 2017 -0700

----------------------------------------------------------------------
 .../zookeeper/server/ZooKeeperServer.java       |  7 +++
 .../zookeeper/server/ZooKeeperServerBean.java   |  5 ++
 .../zookeeper/server/ZooKeeperServerMXBean.java |  5 ++
 .../server/persistence/FileTxnLog.java          | 15 ++++--
 .../server/persistence/FileTxnSnapLog.java      |  8 +++
 .../zookeeper/server/persistence/TxnLog.java    |  8 ++-
 .../server/ZooKeeperServerBeanTest.java         | 42 +++++++++++++++
 .../server/persistence/FileTxnSnapLogTest.java  | 56 ++++++++++++++++++++
 8 files changed, 142 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/1a4042be/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
index 91b810c..026a4a4 100644
--- a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
+++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
@@ -943,6 +943,13 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider
{
         return this.txnLogFactory;
     }
 
+    /**
+     * Returns the elapsed sync of time of transaction log in milliseconds.
+     */
+    public long getTxnLogElapsedSyncTime() {
+        return txnLogFactory.getTxnLogElapsedSyncTime();
+    }
+
     public String getState() {
         return "standalone";
     }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/1a4042be/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
index 0273896..38780bb 100644
--- a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
+++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
@@ -162,4 +162,9 @@ public class ZooKeeperServerBean implements ZooKeeperServerMXBean, ZKMBeanInfo
{
         }
         return "";
     }
+
+    @Override
+    public long getTxnLogElapsedSyncTime() {
+        return zks.getTxnLogElapsedSyncTime();
+    }
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/1a4042be/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
index b95e265..e326e5b 100644
--- a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
+++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
@@ -125,4 +125,9 @@ public interface ZooKeeperServerMXBean {
      * @return secure client address
      */
     public String getSecureClientAddress();
+
+    /**
+     * Returns the elapsed sync of time of transaction log in milliseconds.
+     */
+    public long getTxnLogElapsedSyncTime();
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/1a4042be/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
index 3a6ebd5..ee62bcc 100644
--- a/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
+++ b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
@@ -132,6 +132,8 @@ public class FileTxnLog implements TxnLog {
     long currentSize;
     File logFileWrite = null;
 
+    private volatile long syncElapsedMS = -1L;
+
     /**
      * constructor for FileTxnLog. Take the directory
      * where the txnlogs are stored
@@ -319,7 +321,7 @@ public class FileTxnLog implements TxnLog {
     }
 
     /**
-     * commit the logs. make sure that evertyhing hits the
+     * commit the logs. make sure that everything hits the
      * disk
      */
     public synchronized void commit() throws IOException {
@@ -333,8 +335,7 @@ public class FileTxnLog implements TxnLog {
 
                 log.getChannel().force(false);
 
-                long syncElapsedMS =
-                    TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startSyncNS);
+                syncElapsedMS = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startSyncNS);
                 if (syncElapsedMS > fsyncWarningThresholdMS) {
                     LOG.warn("fsync-ing the write ahead log in "
                             + Thread.currentThread().getName()
@@ -350,6 +351,14 @@ public class FileTxnLog implements TxnLog {
     }
 
     /**
+     *
+     * @return elapsed sync time of transaction log in miliseconds
+     */
+    public long getTxnLogSyncElapsedTime() {
+        return syncElapsedMS;
+    }
+
+    /**
      * start reading all the transactions from the given zxid
      * @param zxid the zxid to start reading transactions from
      * @return returns an iterator to iterate through the transaction

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/1a4042be/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
index 94617bd..7d4491d 100644
--- a/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
+++ b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
@@ -405,6 +405,14 @@ public class FileTxnSnapLog {
     }
 
     /**
+     *
+     * @return elapsed sync time of transaction log commit in milliseconds
+     */
+    public long getTxnLogElapsedSyncTime() {
+        return txnLog.getTxnLogSyncElapsedTime();
+    }
+
+    /**
      * roll the transaction logs
      * @throws IOException
      */

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/1a4042be/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java b/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java
index 2b32d52..b829e8d 100644
--- a/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java
+++ b/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java
@@ -77,11 +77,17 @@ public interface TxnLog {
     long getDbId() throws IOException;
     
     /**
-     * commmit the trasaction and make sure
+     * commmit the transaction and make sure
      * they are persisted
      * @throws IOException
      */
     void commit() throws IOException;
+
+    /**
+     *
+     * @return transaction log's elapsed sync time in miliseconds
+     */
+    long getTxnLogSyncElapsedTime();
    
     /** 
      * close the transactions logs

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/1a4042be/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
index e92c7e7..08adfdc 100644
--- a/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
+++ b/src/java/test/org/apache/zookeeper/server/ZooKeeperServerBeanTest.java
@@ -18,10 +18,19 @@
 package org.apache.zookeeper.server;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
 import java.io.IOException;
 import java.net.InetSocketAddress;
+
+import org.apache.jute.Record;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
+import org.apache.zookeeper.test.ClientBase;
+import org.apache.zookeeper.txn.SetDataTxn;
+import org.apache.zookeeper.txn.TxnHeader;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -39,6 +48,39 @@ public class ZooKeeperServerBeanTest {
     }
 
     @Test
+    public void testTxnLogElapsedSyncTime() throws IOException {
+
+        File tmpDir = ClientBase.createTmpDir();
+        FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(new File(tmpDir, "data"),
+                new File(tmpDir, "data_txnlog"));
+
+        ZooKeeperServer zks = new ZooKeeperServer();
+        zks.setTxnLogFactory(fileTxnSnapLog);
+
+        ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks);
+        long elapsedTime = serverBean.getTxnLogElapsedSyncTime();
+        assertEquals(-1, elapsedTime);
+
+        TxnHeader hdr = new TxnHeader(1, 1, 1, 1, ZooDefs.OpCode.setData);
+        Record txn = new SetDataTxn("/foo", new byte[0], 1);
+        Request req = new Request(0, 0, 0, hdr, txn, 0);
+
+        try {
+
+            zks.getTxnLogFactory().append(req);
+            zks.getTxnLogFactory().commit();
+            elapsedTime = serverBean.getTxnLogElapsedSyncTime();
+
+            assertNotEquals(-1, elapsedTime);
+
+            assertEquals(elapsedTime, serverBean.getTxnLogElapsedSyncTime());
+
+        } finally {
+            fileTxnSnapLog.close();
+        }
+    }
+
+    @Test
     public void testGetSecureClientPort() throws IOException {
         ZooKeeperServer zks = new ZooKeeperServer();
         /**

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/1a4042be/src/java/test/org/apache/zookeeper/server/persistence/FileTxnSnapLogTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/persistence/FileTxnSnapLogTest.java
b/src/java/test/org/apache/zookeeper/server/persistence/FileTxnSnapLogTest.java
new file mode 100644
index 0000000..71e9c8d
--- /dev/null
+++ b/src/java/test/org/apache/zookeeper/server/persistence/FileTxnSnapLogTest.java
@@ -0,0 +1,56 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.persistence;
+
+import org.apache.jute.Record;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.server.Request;
+import org.apache.zookeeper.test.ClientBase;
+import org.apache.zookeeper.txn.SetDataTxn;
+import org.apache.zookeeper.txn.TxnHeader;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+public class FileTxnSnapLogTest {
+
+
+    @Test
+    public void testGetTxnLogSyncElapsedTime() throws IOException {
+        File tmpDir = ClientBase.createTmpDir();
+        FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(new File(tmpDir, "data"),
+                new File(tmpDir, "data_txnlog"));
+
+        TxnHeader hdr = new TxnHeader(1, 1, 1, 1, ZooDefs.OpCode.setData);
+        Record txn = new SetDataTxn("/foo", new byte[0], 1);
+        Request req = new Request(0, 0, 0, hdr, txn, 0);
+
+        try {
+            fileTxnSnapLog.append(req);
+            fileTxnSnapLog.commit();
+            long syncElapsedTime = fileTxnSnapLog.getTxnLogElapsedSyncTime();
+            Assert.assertNotEquals("Did not update syncElapsedTime!", -1L, syncElapsedTime);
+        } finally {
+            fileTxnSnapLog.close();
+        }
+    }
+
+}


Mime
View raw message