You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2020/01/14 02:45:26 UTC

[GitHub] [zookeeper] maoling commented on a change in pull request #1219: ZOOKEEPER-3427: Introduce SnapshotComparer that assists debugging with snapshots.

maoling commented on a change in pull request #1219: ZOOKEEPER-3427: Introduce SnapshotComparer that assists debugging with snapshots.
URL: https://github.com/apache/zookeeper/pull/1219#discussion_r366129666
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/SnapshotComparer.java
 ##########
 @@ -0,0 +1,458 @@
+/**
+ * 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;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
+import java.util.zip.CheckedInputStream;
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.jute.BinaryInputArchive;
+import org.apache.jute.InputArchive;
+import org.apache.zookeeper.server.persistence.FileSnap;
+import org.apache.zookeeper.server.persistence.SnapStream;
+
+/**
+ * SnapshotComparer is a tool that loads and compares two snapshots, with configurable threshold and various filters.
+ * It's useful in use cases that involve snapshot analysis, such as offline data consistency checking, and data trending analysis (e.g. what's growing under which zNode path during when).
+ * Only outputs information about permanent nodes, ignoring both sessions and ephemeral nodes.
+ */
+public class SnapshotComparer {
+  private final Options options;
+  private static final String leftOption = "left";
+  private static final String rightOption = "right";
+  private static final String byteThresholdOption = "bytes";
+  private static final String nodeThresholdOption = "nodes";
+  private static final String debugOption = "debug";
+  private static final String interactiveOption = "interactive";
+
+  @SuppressWarnings("static")
+  private SnapshotComparer() {
+    options = new Options();
+    options.addOption(
+        OptionBuilder
+            .hasArg()
+            .isRequired(true)
+            .withLongOpt(leftOption)
+            .withDescription("(Required) The left snapshot file.")
+            .withArgName("LEFT")
+            .withType(File.class)
+            .create("l"));
+    options.addOption(
+        OptionBuilder
+            .hasArg()
+            .isRequired(true)
+            .withLongOpt(rightOption)
+            .withDescription("(Required) The right snapshot file.")
+            .withArgName("RIGHT")
+            .withType(File.class)
+            .create("r"));
+    options.addOption(
+        OptionBuilder
+            .hasArg()
+            .isRequired(true)
+            .withLongOpt(byteThresholdOption)
+            .withDescription("(Required) The node data delta size threshold, in bytes, for printing the node.")
+            .withArgName("BYTETHRESHOLD")
+            .withType(String.class)
+            .create("b"));
+    options.addOption(
+        OptionBuilder
+            .hasArg()
+            .isRequired(true)
+            .withLongOpt(nodeThresholdOption)
+            .withDescription("(Required) The descendant node delta size threshold, in nodes, for printing the node.")
+            .withArgName("NODETHRESHOLD")
+            .withType(String.class)
+            .create("n"));
+    options.addOption(
+        OptionBuilder
+            .hasArg()
+            .withLongOpt(debugOption)
+            .withDescription("Use debug output.")
+            .withArgName("DEBUG")
+            .withType(String.class)
+            .create("d"));
+    options.addOption(
+        OptionBuilder
+            .hasArg()
+            .withLongOpt(interactiveOption)
+            .withDescription("Enter interactive mode.")
+            .withArgName("INTERACTIVE")
+            .withType(String.class)
+            .create("i"));
+  }
+
+  private void usage() {
+    HelpFormatter help = new HelpFormatter();
+
+    help.printHelp(
+        120,
+        "java -cp <classPath> " + SnapshotComparer.class.getName(),
+        "",
+        options,
+        "");
+  }
+
+  public static void main(String[] args) throws Exception {
+    SnapshotComparer app = new SnapshotComparer();
+    app.compareSnapshots(args);
+  }
+
+  private void compareSnapshots(String[] args) throws Exception {
+    CommandLine parsedOptions;
+    try {
+      parsedOptions = new BasicParser().parse(options, args);
+    } catch (ParseException e) {
+      System.err.println(e.getMessage());
+      usage();
+      System.exit(-1);
+      return;
 
 Review comment:
   > [ERROR] org.apache.zookeeper.server.SnapshotComparer.compareSnapshots(String[]) invokes System.exit(...), which shuts down the entire virtual machine [org.apache.zookeeper.server.SnapshotComparer] At SnapshotComparer.java:[line 136] DM_EXIT
   
   a try for `ServiceUtils.requestSystemExit`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services