[GitHub] zookeeper pull request #619: ZOOKEEPER-3142: Extend SnapshotFormatter to dum...

2018-09-14 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/zookeeper/pull/619


---


[GitHub] zookeeper pull request #619: ZOOKEEPER-3142: Extend SnapshotFormatter to dum...

2018-09-13 Thread enixon
Github user enixon commented on a diff in the pull request:

https://github.com/apache/zookeeper/pull/619#discussion_r217561012
  
--- Diff: src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java 
---
@@ -34,79 +36,133 @@
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.zookeeper.data.StatPersisted;
 import org.apache.zookeeper.server.persistence.FileSnap;
+import org.apache.zookeeper.server.persistence.Util;
+import org.json.simple.JSONValue;
+
+import static 
org.apache.zookeeper.server.persistence.FileSnap.SNAPSHOT_FILE_PREFIX;
 
 /**
  * Dump a snapshot file to stdout.
+ *
+ * For JSON format, followed https://dev.yorhel.nl/ncdu/jsonfmt
  */
 @InterfaceAudience.Public
 public class SnapshotFormatter {
 
+private static Integer INODE_IDX = 1000;
--- End diff --

Per https://dev.yorhel.nl/ncdu/jsonfmt:

"Inode number as reported by lstat().st_ino. Together with the Device ID 
this uniquely identifies a file in this dump. In the case of hard links, two 
objects may appear with the same (dev,ino) combination. A value of 0 is assumed 
if this field is absent. This is currently (ncdu 1.9-1.13) not a problem as 
long as the hlnkc field is false, otherwise it will consider everything with 
the same dev and empty ino values as a single hardlinked file. Accepted values 
are in the range of 0 <= ino < 2^64."

For us, it's just an arbitrary counter to mark each znode as a unique 
entity.


---


[GitHub] zookeeper pull request #619: ZOOKEEPER-3142: Extend SnapshotFormatter to dum...

2018-09-13 Thread enixon
Github user enixon commented on a diff in the pull request:

https://github.com/apache/zookeeper/pull/619#discussion_r217561003
  
--- Diff: src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java 
---
@@ -34,79 +36,133 @@
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.zookeeper.data.StatPersisted;
 import org.apache.zookeeper.server.persistence.FileSnap;
+import org.apache.zookeeper.server.persistence.Util;
+import org.json.simple.JSONValue;
+
+import static 
org.apache.zookeeper.server.persistence.FileSnap.SNAPSHOT_FILE_PREFIX;
 
 /**
  * Dump a snapshot file to stdout.
+ *
+ * For JSON format, followed https://dev.yorhel.nl/ncdu/jsonfmt
  */
 @InterfaceAudience.Public
 public class SnapshotFormatter {
 
+private static Integer INODE_IDX = 1000;
+
 /**
  * USAGE: SnapshotFormatter snapshot_file
  */
 public static void main(String[] args) throws Exception {
-if (args.length != 1) {
-System.err.println("USAGE: SnapshotFormatter snapshot_file");
+String snapshotFile = null;
+boolean dumpData = false;
+boolean dumpJson = false;
+
+int i;
+for (i = 0; i < args.length; i++) {
+if (args[i].equals("-d")) {
+dumpData = true;
+} else if (args[i].equals("-json")) {
+dumpJson = true;
+} else {
--- End diff --

If both `-d` and `-json` are specified then the `-d` is ignored. Just an 
oversight, not a feature. Let me print out an error message or something in 
that case.


---


[GitHub] zookeeper pull request #619: ZOOKEEPER-3142: Extend SnapshotFormatter to dum...

2018-09-11 Thread hanm
Github user hanm commented on a diff in the pull request:

https://github.com/apache/zookeeper/pull/619#discussion_r216842003
  
--- Diff: src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java 
---
@@ -34,79 +36,133 @@
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.zookeeper.data.StatPersisted;
 import org.apache.zookeeper.server.persistence.FileSnap;
+import org.apache.zookeeper.server.persistence.Util;
+import org.json.simple.JSONValue;
+
+import static 
org.apache.zookeeper.server.persistence.FileSnap.SNAPSHOT_FILE_PREFIX;
 
 /**
  * Dump a snapshot file to stdout.
+ *
+ * For JSON format, followed https://dev.yorhel.nl/ncdu/jsonfmt
  */
 @InterfaceAudience.Public
 public class SnapshotFormatter {
 
+private static Integer INODE_IDX = 1000;
--- End diff --

what does this index represent?


---


[GitHub] zookeeper pull request #619: ZOOKEEPER-3142: Extend SnapshotFormatter to dum...

2018-09-11 Thread hanm
Github user hanm commented on a diff in the pull request:

https://github.com/apache/zookeeper/pull/619#discussion_r216841877
  
--- Diff: src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java 
---
@@ -34,79 +36,133 @@
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.zookeeper.data.StatPersisted;
 import org.apache.zookeeper.server.persistence.FileSnap;
+import org.apache.zookeeper.server.persistence.Util;
+import org.json.simple.JSONValue;
+
+import static 
org.apache.zookeeper.server.persistence.FileSnap.SNAPSHOT_FILE_PREFIX;
 
 /**
  * Dump a snapshot file to stdout.
+ *
+ * For JSON format, followed https://dev.yorhel.nl/ncdu/jsonfmt
  */
 @InterfaceAudience.Public
 public class SnapshotFormatter {
 
+private static Integer INODE_IDX = 1000;
+
 /**
  * USAGE: SnapshotFormatter snapshot_file
  */
 public static void main(String[] args) throws Exception {
-if (args.length != 1) {
-System.err.println("USAGE: SnapshotFormatter snapshot_file");
+String snapshotFile = null;
+boolean dumpData = false;
+boolean dumpJson = false;
+
+int i;
+for (i = 0; i < args.length; i++) {
+if (args[i].equals("-d")) {
+dumpData = true;
+} else if (args[i].equals("-json")) {
+dumpJson = true;
+} else {
--- End diff --

so it's possible to specify both `-d` and `-json` option, which will print 
a mix of dump data and json data. Is this intended?


---


[GitHub] zookeeper pull request #619: ZOOKEEPER-3142: Extend SnapshotFormatter to dum...

2018-09-10 Thread enixon
GitHub user enixon opened a pull request:

https://github.com/apache/zookeeper/pull/619

ZOOKEEPER-3142: Extend SnapshotFormatter to dump data in json format



You can merge this pull request into a Git repository by running:

$ git pull https://github.com/enixon/zookeeper extend-sf

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/zookeeper/pull/619.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #619


commit 0068b02aca8c9b6b36cf254bfc66a9ff5ae0d0dc
Author: Brian Nixon 
Date:   2018-09-10T22:42:25Z

ZOOKEEPER-3142: Extend SnapshotFormatter to dump data in json format




---