You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2019/10/25 23:30:01 UTC

[kudu] 02/02: [scripts] a tool to print out HybridTime timestamps

This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 27e207b02c28d5ac23835a96a0823078def14a8b
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Thu Oct 24 10:01:27 2019 -0700

    [scripts] a tool to print out HybridTime timestamps
    
    This is Todd's script to output HybridTime timestamps in human-readable
    form (works with Python2 and Python3).  The script reads from standard
    input until EOF/EOS and outputs the result into standard output.
    
    The script is useful when analyzing hybrid timestamps found in Kudu
    WAL files.  For example:
    
    $ echo 6435399373400084500 | python convert-hybrid-timestamp.py
    2019-10-15 05:27:05.146505 L=20
    
    Change-Id: Ifc5b0d20c6f1bca0994d00a347ff14e4ae64a14c
    Reviewed-on: http://gerrit.cloudera.org:8080/14541
    Tested-by: Alexey Serbin <as...@cloudera.com>
    Reviewed-by: Bankim Bhavsar <ba...@cloudera.com>
    Reviewed-by: Andrew Wong <aw...@cloudera.com>
---
 src/kudu/scripts/convert-hybrid-timestamp.py | 40 ++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/kudu/scripts/convert-hybrid-timestamp.py b/src/kudu/scripts/convert-hybrid-timestamp.py
new file mode 100644
index 0000000..2ee09d3
--- /dev/null
+++ b/src/kudu/scripts/convert-hybrid-timestamp.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+#
+# 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.
+
+#
+# An example of usage:
+#
+# $ echo 6435399373400084500 | python convert-hybrid-timestamp.py
+# 2019-10-15 05:27:05.146505 L=20
+#
+
+import time
+import re
+import sys
+
+def convert_ts(ts_match):
+  ts_i = int(ts_match.group(0))
+  phys, logical = (ts_i >> 12, ts_i & ((1 << 12) - 1))
+  phys_sec = phys / 1000000
+  phys_micros = phys % 1000000
+  f = time.strftime("%F %H:%M:%S", time.localtime(phys_sec))
+  return "%s.%06d L=%d" % (f, phys_micros, logical)
+
+for l in sys.stdin.readlines():
+  print(re.sub(r"\d{10,19}", convert_ts, l))