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 05:14:12 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/master f7281f304 -> 425fdbb8f


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

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

Reviewers: Michael Han <hanm@apache.org>

Closes #241 from eribeiro/ZOOKEEPER-2662 and squashes the following commits:

1d24e06 [Edward Ribeiro] Addressed review comments
7ce89d7 [Edward Ribeiro] ZOOKEEPER-2662: Export a metric for txn log sync times


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

Branch: refs/heads/master
Commit: 425fdbb8fa64ea839072701187fa7a24bfe10bda
Parents: f7281f3
Author: Edward Ribeiro <edward.ribeiro@gmail.com>
Authored: Thu Apr 27 22:14:08 2017 -0700
Committer: Michael Han <hanm@apache.org>
Committed: Thu Apr 27 22:14:08 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  | 23 +++++++++++
 8 files changed, 109 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/425fdbb8/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 92d3c13..e2fba10 100644
--- a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
+++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
@@ -944,6 +944,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/425fdbb8/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/425fdbb8/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/425fdbb8/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/425fdbb8/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 84c526b..40a5cd6 100644
--- a/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
+++ b/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
@@ -431,6 +431,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/425fdbb8/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/425fdbb8/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..9bc2b0e 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.createEmptyTestDir();
+        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/425fdbb8/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
index 3d20e39..7a80efd 100644
--- a/src/java/test/org/apache/zookeeper/server/persistence/FileTxnSnapLogTest.java
+++ b/src/java/test/org/apache/zookeeper/server/persistence/FileTxnSnapLogTest.java
@@ -19,8 +19,11 @@
 package org.apache.zookeeper.server.persistence;
 
 import org.apache.jute.Record;
+import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.server.DataTree;
+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;
@@ -113,6 +116,26 @@ public class FileTxnSnapLogTest {
         attemptAutoCreateDb(dataDir, snapDir, sessions, priorAutocreateDbValue, "false",
0L);
     }
 
+    @Test
+    public void testGetTxnLogSyncElapsedTime() throws IOException {
+        File tmpDir = ClientBase.createEmptyTestDir();
+        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();
+        }
+    }
+
     private void attemptAutoCreateDb(File dataDir, File snapDir, Map<Long, Integer>
sessions,
                                      String priorAutocreateDbValue, String autoCreateValue,
                                      long expectedValue) throws IOException {


Mime
View raw message