You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2018/10/05 12:26:23 UTC
[30/51] [partial] zookeeper git commit: ZOOKEEPER-3032: MAVEN
MIGRATION - move java server, client
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/CommandExecutor.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/CommandExecutor.java b/src/java/main/org/apache/zookeeper/server/command/CommandExecutor.java
deleted file mode 100644
index 52eeda2..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/CommandExecutor.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.ServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-
-public class CommandExecutor {
- /**
- * This class decides which command to be executed and then executes
- */
- public boolean execute(ServerCnxn serverCnxn, PrintWriter pwriter,
- final int commandCode, ZooKeeperServer zkServer, ServerCnxnFactory factory) {
- AbstractFourLetterCommand command = getCommand(serverCnxn,pwriter, commandCode);
-
- if (command == null) {
- return false;
- }
-
- command.setZkServer(zkServer);
- command.setFactory(factory);
- command.start();
- return true;
- }
-
- private AbstractFourLetterCommand getCommand(ServerCnxn serverCnxn,
- PrintWriter pwriter, final int commandCode) {
- AbstractFourLetterCommand command = null;
- if (commandCode == FourLetterCommands.ruokCmd) {
- command = new RuokCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.getTraceMaskCmd) {
- command = new TraceMaskCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.enviCmd) {
- command = new EnvCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.confCmd) {
- command = new ConfCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.srstCmd) {
- command = new StatResetCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.crstCmd) {
- command = new CnxnStatResetCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.dirsCmd) {
- command = new DirsCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.dumpCmd) {
- command = new DumpCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.statCmd
- || commandCode == FourLetterCommands.srvrCmd) {
- command = new StatCommand(pwriter, serverCnxn, commandCode);
- } else if (commandCode == FourLetterCommands.consCmd) {
- command = new ConsCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.wchpCmd
- || commandCode == FourLetterCommands.wchcCmd
- || commandCode == FourLetterCommands.wchsCmd) {
- command = new WatchCommand(pwriter, serverCnxn, commandCode);
- } else if (commandCode == FourLetterCommands.mntrCmd) {
- command = new MonitorCommand(pwriter, serverCnxn);
- } else if (commandCode == FourLetterCommands.isroCmd) {
- command = new IsroCommand(pwriter, serverCnxn);
- }
- return command;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/ConfCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/ConfCommand.java b/src/java/main/org/apache/zookeeper/server/command/ConfCommand.java
deleted file mode 100644
index 1cfa78d..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/ConfCommand.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class ConfCommand extends AbstractFourLetterCommand {
- ConfCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw,serverCnxn);
- }
-
- @Override
- public void commandRun() {
- if (!isZKServerRunning()) {
- pw.println(ZK_NOT_SERVING);
- } else {
- zkServer.dumpConf(pw);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/ConsCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/ConsCommand.java b/src/java/main/org/apache/zookeeper/server/command/ConsCommand.java
deleted file mode 100644
index 36e40ad..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/ConsCommand.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class ConsCommand extends AbstractFourLetterCommand {
- public ConsCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() {
- if (!isZKServerRunning()) {
- pw.println(ZK_NOT_SERVING);
- } else {
- for (ServerCnxn c : factory.getConnections()) {
- c.dumpConnectionInfo(pw, false);
- pw.println();
- }
- pw.println();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/DirsCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/DirsCommand.java b/src/java/main/org/apache/zookeeper/server/command/DirsCommand.java
deleted file mode 100644
index 0f82a2d..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/DirsCommand.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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.command;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class DirsCommand extends AbstractFourLetterCommand {
-
- public DirsCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() throws IOException {
- if (!isZKServerRunning()) {
- pw.println(ZK_NOT_SERVING);
- return;
- }
- pw.println("datadir_size: " + zkServer.getDataDirSize());
- pw.println("logdir_size: " + zkServer.getLogDirSize());
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/DumpCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/DumpCommand.java b/src/java/main/org/apache/zookeeper/server/command/DumpCommand.java
deleted file mode 100644
index a52ebea..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/DumpCommand.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.NIOServerCnxnFactory;
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class DumpCommand extends AbstractFourLetterCommand {
- public DumpCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() {
- if (!isZKServerRunning()) {
- pw.println(ZK_NOT_SERVING);
- } else {
- pw.println("SessionTracker dump:");
- zkServer.getSessionTracker().dumpSessions(pw);
- pw.println("ephemeral nodes dump:");
- zkServer.dumpEphemerals(pw);
- pw.println("Connections dump:");
- //dumpConnections connection is implemented only in NIOServerCnxnFactory
- if (factory instanceof NIOServerCnxnFactory) {
- ((NIOServerCnxnFactory)factory).dumpConnections(pw);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/EnvCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/EnvCommand.java b/src/java/main/org/apache/zookeeper/server/command/EnvCommand.java
deleted file mode 100644
index c35d9d5..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/EnvCommand.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-import java.util.List;
-
-import org.apache.zookeeper.Environment;
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class EnvCommand extends AbstractFourLetterCommand {
- EnvCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() {
- List<Environment.Entry> env = Environment.list();
-
- pw.println("Environment:");
- for (Environment.Entry e : env) {
- pw.print(e.getKey());
- pw.print("=");
- pw.println(e.getValue());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/FourLetterCommands.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/FourLetterCommands.java b/src/java/main/org/apache/zookeeper/server/command/FourLetterCommands.java
deleted file mode 100644
index 45bd942..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/FourLetterCommands.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/**
- * 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.command;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Arrays;
-
-/**
- * This class contains constants for all the four letter commands
- */
-public class FourLetterCommands {
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int confCmd =
- ByteBuffer.wrap("conf".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int consCmd =
- ByteBuffer.wrap("cons".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int crstCmd =
- ByteBuffer.wrap("crst".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int dirsCmd =
- ByteBuffer.wrap("dirs".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int dumpCmd =
- ByteBuffer.wrap("dump".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int enviCmd =
- ByteBuffer.wrap("envi".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int getTraceMaskCmd =
- ByteBuffer.wrap("gtmk".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int ruokCmd =
- ByteBuffer.wrap("ruok".getBytes()).getInt();
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int setTraceMaskCmd =
- ByteBuffer.wrap("stmk".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int srvrCmd =
- ByteBuffer.wrap("srvr".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int srstCmd =
- ByteBuffer.wrap("srst".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int statCmd =
- ByteBuffer.wrap("stat".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int wchcCmd =
- ByteBuffer.wrap("wchc".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int wchpCmd =
- ByteBuffer.wrap("wchp".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int wchsCmd =
- ByteBuffer.wrap("wchs".getBytes()).getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int mntrCmd = ByteBuffer.wrap("mntr".getBytes())
- .getInt();
-
- /*
- * See <a href="{@docRoot}/../../../docs/zookeeperAdmin.html#sc_zkCommands">
- * Zk Admin</a>. this link is for all the commands.
- */
- public final static int isroCmd = ByteBuffer.wrap("isro".getBytes())
- .getInt();
-
- /*
- * The control sequence sent by the telnet program when it closes a
- * connection. Include simply to keep the logs cleaner (the server would
- * close the connection anyway because it would parse this as a negative
- * length).
- */
- public final static int telnetCloseCmd = 0xfff4fffd;
-
- private static final String ZOOKEEPER_4LW_COMMANDS_WHITELIST = "zookeeper.4lw.commands.whitelist";
-
- private static final Logger LOG = LoggerFactory.getLogger(FourLetterCommands.class);
-
- private static final Map<Integer, String> cmd2String = new HashMap<Integer, String>();
-
- private static final Set<String> whiteListedCommands = new HashSet<String>();
-
- private static boolean whiteListInitialized = false;
-
- // @VisibleForTesting
- public synchronized static void resetWhiteList() {
- whiteListInitialized = false;
- whiteListedCommands.clear();
- }
-
- /**
- * Return the string representation of the specified command code.
- */
- public static String getCommandString(int command) {
- return cmd2String.get(command);
- }
-
- /**
- * Check if the specified command code is from a known command.
- *
- * @param command The integer code of command.
- * @return true if the specified command is known, false otherwise.
- */
- public static boolean isKnown(int command) {
- return cmd2String.containsKey(command);
- }
-
- /**
- * Check if the specified command is enabled.
- *
- * In ZOOKEEPER-2693 we introduce a configuration option to only
- * allow a specific set of white listed commands to execute.
- * A command will only be executed if it is also configured
- * in the white list.
- *
- * @param command The command string.
- * @return true if the specified command is enabled
- */
- public synchronized static boolean isEnabled(String command) {
- if (whiteListInitialized) {
- return whiteListedCommands.contains(command);
- }
-
- String commands = System.getProperty(ZOOKEEPER_4LW_COMMANDS_WHITELIST);
- if (commands != null) {
- String[] list = commands.split(",");
- for (String cmd : list) {
- if (cmd.trim().equals("*")) {
- for (Map.Entry<Integer, String> entry : cmd2String.entrySet()) {
- whiteListedCommands.add(entry.getValue());
- }
- break;
- }
- if (!cmd.trim().isEmpty()) {
- whiteListedCommands.add(cmd.trim());
- }
- }
- }
-
- // It is sad that isro and srvr are used by ZooKeeper itself. Need fix this
- // before deprecating 4lw.
- if (System.getProperty("readonlymode.enabled", "false").equals("true")) {
- whiteListedCommands.add("isro");
- }
- // zkServer.sh depends on "srvr".
- whiteListedCommands.add("srvr");
- whiteListInitialized = true;
- LOG.info("The list of known four letter word commands is : {}", Arrays.asList(cmd2String));
- LOG.info("The list of enabled four letter word commands is : {}", Arrays.asList(whiteListedCommands));
- return whiteListedCommands.contains(command);
- }
-
- // specify all of the commands that are available
- static {
- cmd2String.put(confCmd, "conf");
- cmd2String.put(consCmd, "cons");
- cmd2String.put(crstCmd, "crst");
- cmd2String.put(dirsCmd, "dirs");
- cmd2String.put(dumpCmd, "dump");
- cmd2String.put(enviCmd, "envi");
- cmd2String.put(getTraceMaskCmd, "gtmk");
- cmd2String.put(ruokCmd, "ruok");
- cmd2String.put(setTraceMaskCmd, "stmk");
- cmd2String.put(srstCmd, "srst");
- cmd2String.put(srvrCmd, "srvr");
- cmd2String.put(statCmd, "stat");
- cmd2String.put(wchcCmd, "wchc");
- cmd2String.put(wchpCmd, "wchp");
- cmd2String.put(wchsCmd, "wchs");
- cmd2String.put(mntrCmd, "mntr");
- cmd2String.put(isroCmd, "isro");
- cmd2String.put(telnetCloseCmd, "telnet close");
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/IsroCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/IsroCommand.java b/src/java/main/org/apache/zookeeper/server/command/IsroCommand.java
deleted file mode 100644
index a8f9f21..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/IsroCommand.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer;
-
-public class IsroCommand extends AbstractFourLetterCommand {
-
- public IsroCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() {
- if (!isZKServerRunning()) {
- pw.print("null");
- } else if (zkServer instanceof ReadOnlyZooKeeperServer) {
- pw.print("ro");
- } else {
- pw.print("rw");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java b/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java
deleted file mode 100644
index b89d557..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.Version;
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.ServerStats;
-import org.apache.zookeeper.server.ZKDatabase;
-import org.apache.zookeeper.server.quorum.Leader;
-import org.apache.zookeeper.server.quorum.LeaderZooKeeperServer;
-import org.apache.zookeeper.server.util.OSMXBean;
-
-public class MonitorCommand extends AbstractFourLetterCommand {
-
- MonitorCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() {
- if (!isZKServerRunning()) {
- pw.println(ZK_NOT_SERVING);
- return;
- }
- ZKDatabase zkdb = zkServer.getZKDatabase();
- ServerStats stats = zkServer.serverStats();
-
- print("version", Version.getFullVersion());
-
- print("avg_latency", stats.getAvgLatency());
- print("max_latency", stats.getMaxLatency());
- print("min_latency", stats.getMinLatency());
-
- print("packets_received", stats.getPacketsReceived());
- print("packets_sent", stats.getPacketsSent());
- print("num_alive_connections", stats.getNumAliveClientConnections());
-
- print("outstanding_requests", stats.getOutstandingRequests());
-
- print("server_state", stats.getServerState());
- print("znode_count", zkdb.getNodeCount());
-
- print("watch_count", zkdb.getDataTree().getWatchCount());
- print("ephemerals_count", zkdb.getDataTree().getEphemeralsCount());
- print("approximate_data_size", zkdb.getDataTree().cachedApproximateDataSize());
-
- OSMXBean osMbean = new OSMXBean();
- if (osMbean != null && osMbean.getUnix() == true) {
- print("open_file_descriptor_count", osMbean.getOpenFileDescriptorCount());
- print("max_file_descriptor_count", osMbean.getMaxFileDescriptorCount());
- }
-
- if (stats.getServerState().equals("leader")) {
- Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader();
-
- print("learners", leader.getLearners().size());
- print("synced_followers", leader.getForwardingFollowers().size());
- print("pending_syncs", leader.getNumPendingSyncs());
-
- print("last_proposal_size", leader.getProposalStats().getLastBufferSize());
- print("max_proposal_size", leader.getProposalStats().getMaxBufferSize());
- print("min_proposal_size", leader.getProposalStats().getMinBufferSize());
- }
- }
-
- private void print(String key, long number) {
- print(key, "" + number);
- }
-
- private void print(String key, String value) {
- pw.print("zk_");
- pw.print(key);
- pw.print("\t");
- pw.println(value);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/NopCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/NopCommand.java b/src/java/main/org/apache/zookeeper/server/command/NopCommand.java
deleted file mode 100644
index 4924fcf..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/NopCommand.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-
-/**
- * A command that does not do anything except reply to client with predefined message.
- * It is used to inform clients who execute none white listed four letter word commands.
- */
-public class NopCommand extends AbstractFourLetterCommand {
- private String msg;
-
- public NopCommand(PrintWriter pw, ServerCnxn serverCnxn, String msg) {
- super(pw, serverCnxn);
- this.msg = msg;
- }
-
- @Override
- public void commandRun() {
- pw.println(msg);
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/RuokCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/RuokCommand.java b/src/java/main/org/apache/zookeeper/server/command/RuokCommand.java
deleted file mode 100644
index cbcbde3..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/RuokCommand.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class RuokCommand extends AbstractFourLetterCommand {
- public RuokCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() {
- pw.print("imok");
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/SetTraceMaskCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/SetTraceMaskCommand.java b/src/java/main/org/apache/zookeeper/server/command/SetTraceMaskCommand.java
deleted file mode 100644
index 74377b6..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/SetTraceMaskCommand.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class SetTraceMaskCommand extends AbstractFourLetterCommand {
- long trace = 0;
- public SetTraceMaskCommand(PrintWriter pw, ServerCnxn serverCnxn, long trace) {
- super(pw, serverCnxn);
- this.trace = trace;
- }
-
- @Override
- public void commandRun() {
- pw.print(trace);
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/StatCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/StatCommand.java b/src/java/main/org/apache/zookeeper/server/command/StatCommand.java
deleted file mode 100644
index c6c4b87..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/StatCommand.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.Version;
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.ServerStats;
-import org.apache.zookeeper.server.quorum.Leader;
-import org.apache.zookeeper.server.quorum.LeaderZooKeeperServer;
-import org.apache.zookeeper.server.quorum.BufferStats;
-import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class StatCommand extends AbstractFourLetterCommand {
- private static final Logger LOG = LoggerFactory
- .getLogger(AbstractFourLetterCommand.class);
- private int len;
- public StatCommand(PrintWriter pw, ServerCnxn serverCnxn, int len) {
- super(pw, serverCnxn);
- this.len = len;
- }
-
- @Override
- public void commandRun() {
- if (!isZKServerRunning()) {
- pw.println(ZK_NOT_SERVING);
- } else {
- pw.print("Zookeeper version: ");
- pw.println(Version.getFullVersion());
- if (zkServer instanceof ReadOnlyZooKeeperServer) {
- pw.println("READ-ONLY mode; serving only read-only clients");
- }
- if (len == FourLetterCommands.statCmd) {
- LOG.info("Stat command output");
- pw.println("Clients:");
- for(ServerCnxn c : factory.getConnections()){
- c.dumpConnectionInfo(pw, true);
- pw.println();
- }
- pw.println();
- }
- ServerStats serverStats = zkServer.serverStats();
- pw.print(serverStats.toString());
- pw.print("Node count: ");
- pw.println(zkServer.getZKDatabase().getNodeCount());
- if (serverStats.getServerState().equals("leader")) {
- Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader();
- BufferStats proposalStats = leader.getProposalStats();
- pw.printf("Proposal sizes last/min/max: %s%n", proposalStats.toString());
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/StatResetCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/StatResetCommand.java b/src/java/main/org/apache/zookeeper/server/command/StatResetCommand.java
deleted file mode 100644
index 2b2fa06..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/StatResetCommand.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.ServerStats;
-import org.apache.zookeeper.server.quorum.LeaderZooKeeperServer;
-
-public class StatResetCommand extends AbstractFourLetterCommand {
- public StatResetCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() {
- if (!isZKServerRunning()) {
- pw.println(ZK_NOT_SERVING);
- } else {
- ServerStats serverStats = zkServer.serverStats();
- serverStats.reset();
- if (serverStats.getServerState().equals("leader")) {
- ((LeaderZooKeeperServer)zkServer).getLeader().getProposalStats().reset();
- }
- pw.println("Server stats reset.");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/TraceMaskCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/TraceMaskCommand.java b/src/java/main/org/apache/zookeeper/server/command/TraceMaskCommand.java
deleted file mode 100644
index 63b0c1c..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/TraceMaskCommand.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.ZooTrace;
-
-public class TraceMaskCommand extends AbstractFourLetterCommand {
- TraceMaskCommand(PrintWriter pw, ServerCnxn serverCnxn) {
- super(pw, serverCnxn);
- }
-
- @Override
- public void commandRun() {
- long traceMask = ZooTrace.getTextTraceLevel();
- pw.print(traceMask);
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/WatchCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/WatchCommand.java b/src/java/main/org/apache/zookeeper/server/command/WatchCommand.java
deleted file mode 100644
index ac0476e..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/WatchCommand.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.DataTree;
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class WatchCommand extends AbstractFourLetterCommand {
- int len = 0;
- public WatchCommand(PrintWriter pw, ServerCnxn serverCnxn, int len) {
- super(pw, serverCnxn);
- this.len = len;
- }
-
- @Override
- public void commandRun() {
- if (!isZKServerRunning()) {
- pw.println(ZK_NOT_SERVING);
- } else {
- DataTree dt = zkServer.getZKDatabase().getDataTree();
- if (len == FourLetterCommands.wchsCmd) {
- dt.dumpWatchesSummary(pw);
- } else if (len == FourLetterCommands.wchpCmd) {
- dt.dumpWatches(pw, true);
- } else {
- dt.dumpWatches(pw, false);
- }
- pw.println();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/metric/AvgMinMaxCounter.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/metric/AvgMinMaxCounter.java b/src/java/main/org/apache/zookeeper/server/metric/AvgMinMaxCounter.java
deleted file mode 100644
index 499c9a0..0000000
--- a/src/java/main/org/apache/zookeeper/server/metric/AvgMinMaxCounter.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * 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.metric;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * Generic long counter that keep track of min/max/avg. The counter is
- * thread-safe
- */
-public class AvgMinMaxCounter implements Metric {
- private String name;
- private AtomicLong total = new AtomicLong();
- private AtomicLong min = new AtomicLong(Long.MAX_VALUE);
- private AtomicLong max = new AtomicLong(Long.MIN_VALUE);
- private AtomicLong count = new AtomicLong();
-
- public AvgMinMaxCounter(String name) {
- this.name = name;
- }
-
- public void addDataPoint(long value) {
- total.addAndGet(value);
- count.incrementAndGet();
- setMin(value);
- setMax(value);
- }
-
- private void setMax(long value) {
- long current;
- while (value > (current = max.get())
- && !max.compareAndSet(current, value))
- ;
- }
-
- private void setMin(long value) {
- long current;
- while (value < (current = min.get())
- && !min.compareAndSet(current, value))
- ;
- }
-
- public long getAvg() {
- // There is possible race-condition but we don't need the stats to be
- // extremely accurate.
- long currentCount = count.get();
- long currentTotal = total.get();
- if (currentCount > 0) {
- return currentTotal / currentCount;
- }
- return 0;
- }
-
- public long getCount() {
- return count.get();
- }
-
- public long getMax() {
- long current = max.get();
- return (current == Long.MIN_VALUE) ? 0: current;
- }
-
- public long getMin() {
- long current = min.get();
- return (current == Long.MAX_VALUE) ? 0: current;
- }
-
- public long getTotal() {
- return total.get();
- }
-
- public void resetMax() {
- max.set(getMin());
- }
-
- public void reset() {
- count.set(0);
- total.set(0);
- min.set(Long.MAX_VALUE);
- max.set(Long.MIN_VALUE);
- }
-
- public void add(long value) {
- addDataPoint(value);
- }
-
- public Map<String, Long> values() {
- Map<String, Long> m = new LinkedHashMap<String, Long>();
- m.put("avg_" + name, this.getAvg());
- m.put("min_" + name, this.getMin());
- m.put("max_" + name, this.getMax());
- m.put("cnt_" + name, this.getCount());
- return m;
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/metric/Metric.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/metric/Metric.java b/src/java/main/org/apache/zookeeper/server/metric/Metric.java
deleted file mode 100644
index c475055..0000000
--- a/src/java/main/org/apache/zookeeper/server/metric/Metric.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * 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.metric;
-
-import java.util.Map;
-
-public interface Metric {
- void add(long value);
- void reset();
- Map<String, Long> values();
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/metric/SimpleCounter.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/metric/SimpleCounter.java b/src/java/main/org/apache/zookeeper/server/metric/SimpleCounter.java
deleted file mode 100644
index 4bf8046..0000000
--- a/src/java/main/org/apache/zookeeper/server/metric/SimpleCounter.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.metric;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
-
-public class SimpleCounter implements Metric {
- private final String name;
- private final AtomicLong counter = new AtomicLong();
-
- public SimpleCounter(String name) {
- this.name = name;
- }
-
- @Override
- public void add(long value) {
- counter.addAndGet(value);
- }
-
- @Override
- public void reset() {
- counter.set(0);
- }
-
- public long getCount() {
- return counter.get();
- }
-
- @Override
- public Map<String, Long> values() {
- Map<String, Long> m = new LinkedHashMap<String, Long>();
- m.put(name, this.getCount());
- return m;
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/package.html
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/package.html b/src/java/main/org/apache/zookeeper/server/package.html
deleted file mode 100644
index 89a5d7e..0000000
--- a/src/java/main/org/apache/zookeeper/server/package.html
+++ /dev/null
@@ -1,101 +0,0 @@
-<!--
- 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.
--->
-
-<html>
-<body>
-<h1>ZooKeeper server theory of operation</h1>
-ZooKeeperServer is designed to work in standalone mode and also
-be extensible so that it can be used to implement the quorum based
-version of ZooKeeper.
-<p>
-ZooKeeper maintains a order when processing requests:
-<ul>
-<li>All requests will be processed in order.
-<li>All responses will return in order.
-<li>All watches will be sent in the order that the update takes place.
-</ul>
-<p>
-We will explain the three aspects of ZooKeeperServer: request processing, data
-structure maintenance, and session tracking.
-
-<h2>Request processing</h2>
-
-Requests are received by the ServerCnxn. Demarshalling of a request is
-done by ClientRequestHandler. After a request has been demarshalled,
-ClientRequestHandler invokes the relevant method in ZooKeeper and marshals
-the result.
-<p>
-If the request is just a query, it will be processed by ZooKeeper and returned.
-Otherwise, the request will be validated and a transaction will be generated
-and logged. This the request will then wait until the request has been logged
-before continuing processing.
-<p>
-Requests are logged as a group. Transactions are queued up and the SyncThread
-will process them at predefined intervals. (Currently 20ms) The SyncThread
-interacts with ZooKeeperServer the txnQueue. Transactions are added to the
-txnQueue of SyncThread via queueItem. When the transaction has been synced to
-disk, its callback will be invoked which will cause the request processing to
-be completed.
-
-<h2>Data structure maintenance</h2>
-
-ZooKeeper data is stored in-memory. Each znode is stored in a DataNode object.
-This object is accessed through a hash table that maps paths to DataNodes.
-DataNodes also organize themselves into a tree. This tree is only used for
-serializing nodes.
-<p>
-We guarantee that changes to nodes are stored to non-volatile media before
-responding to a client. We do this quickly by writing changes as a sequence
-of transactions in a log file. Even though we flush transactions as a group,
-we need to avoid seeks as much as possible. Also, since the server can fail
-at any point, we need to be careful of partial records.
-<p>
-We address the above problems by
-<ul>
-<li>Pre-allocating 1M chunks of file space. This allows us to append to the
-file without causing seeks to update file size. It also means that we need
-to check for the end of the log by looking for a zero length transaction
-rather than simply end of file.
-<li>Writing a signature at the end of each transaction. When processing
-transactions, we only use transactions that have a valid signature at the end.
-</ul>
-<p>
-As the server runs, the log file will grow quite large. To avoid long startup
-times we periodically take a snapshot of the tree of DataNodes. We cannot
-take the snapshot synchronously as the data takes a while to write out, so
-instead we asynchronously write out the tree. This means that we end up
-with a "corrupt" snapshot of the data tree. More formally if we define T
-to be the real snapshot of the tree at the time we begin taking the snapshot
-and l as the sequence of transactions that are applied to the tree between
-the time the snapshot begins and the time the snapshot completes, we write
-to disk T+l' where l' is a subset of the transactions in l. While we do not
-have a way of figuring out which transactions make up l', it doesn't really
-matter. T+l'+l = T+l since the transactions we log are idempotent (applying
-the transaction multiple times has the same result as applying the transaction
-once). So when we restore the snapshot we also play all transactions in the log
-that occur after the snapshot was begun. We can easily figure out where to
-start the replay because we start a new logfile when we start a snapshot. Both
-the snapshot file and log file have a numeric suffix that represent the
-transaction id that created the respective files.
-
-<h2>Session tracking</h2>
-Rather than tracking sessions exactly, we track them in batches. That are
-processed at fixed intervals. This is easier to implement than exact
-session tracking and it is more efficient in terms of performance. It also
-provides a small grace period for session renewal.
-</body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/persistence/FilePadding.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/persistence/FilePadding.java b/src/java/main/org/apache/zookeeper/server/persistence/FilePadding.java
deleted file mode 100644
index 49fde24..0000000
--- a/src/java/main/org/apache/zookeeper/server/persistence/FilePadding.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * 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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-
-public class FilePadding {
- private static final Logger LOG;
- private static long preAllocSize = 65536 * 1024;
- private static final ByteBuffer fill = ByteBuffer.allocateDirect(1);
-
- static {
- LOG = LoggerFactory.getLogger(FileTxnLog.class);
-
- String size = System.getProperty("zookeeper.preAllocSize");
- if (size != null) {
- try {
- preAllocSize = Long.parseLong(size) * 1024;
- } catch (NumberFormatException e) {
- LOG.warn(size + " is not a valid value for preAllocSize");
- }
- }
- }
-
- private long currentSize;
-
- /**
- * Getter of preAllocSize has been added for testing
- */
- public static long getPreAllocSize() {
- return preAllocSize;
- }
-
- /**
- * method to allow setting preallocate size
- * of log file to pad the file.
- *
- * @param size the size to set to in bytes
- */
- public static void setPreallocSize(long size) {
- preAllocSize = size;
- }
-
- public void setCurrentSize(long currentSize) {
- this.currentSize = currentSize;
- }
-
- /**
- * pad the current file to increase its size to the next multiple of preAllocSize greater than the current size and position
- *
- * @param fileChannel the fileChannel of the file to be padded
- * @throws IOException
- */
- long padFile(FileChannel fileChannel) throws IOException {
- long newFileSize = calculateFileSizeWithPadding(fileChannel.position(), currentSize, preAllocSize);
- if (currentSize != newFileSize) {
- fileChannel.write((ByteBuffer) fill.position(0), newFileSize - fill.remaining());
- currentSize = newFileSize;
- }
- return currentSize;
- }
-
- /**
- * Calculates a new file size with padding. We only return a new size if
- * the current file position is sufficiently close (less than 4K) to end of
- * file and preAllocSize is > 0.
- *
- * @param position the point in the file we have written to
- * @param fileSize application keeps track of the current file size
- * @param preAllocSize how many bytes to pad
- * @return the new file size. It can be the same as fileSize if no
- * padding was done.
- * @throws IOException
- */
- // VisibleForTesting
- public static long calculateFileSizeWithPadding(long position, long fileSize, long preAllocSize) {
- // If preAllocSize is positive and we are within 4KB of the known end of the file calculate a new file size
- if (preAllocSize > 0 && position + 4096 >= fileSize) {
- // If we have written more than we have previously preallocated we need to make sure the new
- // file size is larger than what we already have
- if (position > fileSize) {
- fileSize = position + preAllocSize;
- fileSize -= fileSize % preAllocSize;
- } else {
- fileSize += preAllocSize;
- }
- }
-
- return fileSize;
- }
-}
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java b/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
deleted file mode 100644
index 5cdfadb..0000000
--- a/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/**
- * 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 java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.Adler32;
-import java.util.zip.CheckedInputStream;
-import java.util.zip.CheckedOutputStream;
-
-import org.apache.jute.BinaryInputArchive;
-import org.apache.jute.BinaryOutputArchive;
-import org.apache.jute.InputArchive;
-import org.apache.jute.OutputArchive;
-import org.apache.zookeeper.common.AtomicFileOutputStream;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.server.DataTree;
-import org.apache.zookeeper.server.util.SerializeUtils;
-
-/**
- * This class implements the snapshot interface.
- * it is responsible for storing, serializing
- * and deserializing the right snapshot.
- * and provides access to the snapshots.
- */
-public class FileSnap implements SnapShot {
- File snapDir;
- private volatile boolean close = false;
- private static final int VERSION = 2;
- private static final long dbId = -1;
- private static final Logger LOG = LoggerFactory.getLogger(FileSnap.class);
- public final static int SNAP_MAGIC
- = ByteBuffer.wrap("ZKSN".getBytes()).getInt();
-
- public static final String SNAPSHOT_FILE_PREFIX = "snapshot";
-
- public FileSnap(File snapDir) {
- this.snapDir = snapDir;
- }
-
- /**
- * deserialize a data tree from the most recent snapshot
- * @return the zxid of the snapshot
- */
- public long deserialize(DataTree dt, Map<Long, Integer> sessions)
- throws IOException {
- // we run through 100 snapshots (not all of them)
- // if we cannot get it running within 100 snapshots
- // we should give up
- List<File> snapList = findNValidSnapshots(100);
- if (snapList.size() == 0) {
- return -1L;
- }
- File snap = null;
- boolean foundValid = false;
- for (int i = 0, snapListSize = snapList.size(); i < snapListSize; i++) {
- snap = snapList.get(i);
- LOG.info("Reading snapshot " + snap);
- try (InputStream snapIS = new BufferedInputStream(new FileInputStream(snap));
- CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32())) {
- InputArchive ia = BinaryInputArchive.getArchive(crcIn);
- deserialize(dt, sessions, ia);
- long checkSum = crcIn.getChecksum().getValue();
- long val = ia.readLong("val");
- if (val != checkSum) {
- throw new IOException("CRC corruption in snapshot : " + snap);
- }
- foundValid = true;
- break;
- } catch (IOException e) {
- LOG.warn("problem reading snap file " + snap, e);
- }
- }
- if (!foundValid) {
- throw new IOException("Not able to find valid snapshots in " + snapDir);
- }
- dt.lastProcessedZxid = Util.getZxidFromName(snap.getName(), SNAPSHOT_FILE_PREFIX);
- return dt.lastProcessedZxid;
- }
-
- /**
- * deserialize the datatree from an inputarchive
- * @param dt the datatree to be serialized into
- * @param sessions the sessions to be filled up
- * @param ia the input archive to restore from
- * @throws IOException
- */
- public void deserialize(DataTree dt, Map<Long, Integer> sessions,
- InputArchive ia) throws IOException {
- FileHeader header = new FileHeader();
- header.deserialize(ia, "fileheader");
- if (header.getMagic() != SNAP_MAGIC) {
- throw new IOException("mismatching magic headers "
- + header.getMagic() +
- " != " + FileSnap.SNAP_MAGIC);
- }
- SerializeUtils.deserializeSnapshot(dt,ia,sessions);
- }
-
- /**
- * find the most recent snapshot in the database.
- * @return the file containing the most recent snapshot
- */
- public File findMostRecentSnapshot() throws IOException {
- List<File> files = findNValidSnapshots(1);
- if (files.size() == 0) {
- return null;
- }
- return files.get(0);
- }
-
- /**
- * find the last (maybe) valid n snapshots. this does some
- * minor checks on the validity of the snapshots. It just
- * checks for / at the end of the snapshot. This does
- * not mean that the snapshot is truly valid but is
- * valid with a high probability. also, the most recent
- * will be first on the list.
- * @param n the number of most recent snapshots
- * @return the last n snapshots (the number might be
- * less than n in case enough snapshots are not available).
- * @throws IOException
- */
- private List<File> findNValidSnapshots(int n) throws IOException {
- List<File> files = Util.sortDataDir(snapDir.listFiles(), SNAPSHOT_FILE_PREFIX, false);
- int count = 0;
- List<File> list = new ArrayList<File>();
- for (File f : files) {
- // we should catch the exceptions
- // from the valid snapshot and continue
- // until we find a valid one
- try {
- if (Util.isValidSnapshot(f)) {
- list.add(f);
- count++;
- if (count == n) {
- break;
- }
- }
- } catch (IOException e) {
- LOG.info("invalid snapshot " + f, e);
- }
- }
- return list;
- }
-
- /**
- * find the last n snapshots. this does not have
- * any checks if the snapshot might be valid or not
- * @param n the number of most recent snapshots
- * @return the last n snapshots
- * @throws IOException
- */
- public List<File> findNRecentSnapshots(int n) throws IOException {
- List<File> files = Util.sortDataDir(snapDir.listFiles(), SNAPSHOT_FILE_PREFIX, false);
- int count = 0;
- List<File> list = new ArrayList<File>();
- for (File f: files) {
- if (count == n)
- break;
- if (Util.getZxidFromName(f.getName(), SNAPSHOT_FILE_PREFIX) != -1) {
- count++;
- list.add(f);
- }
- }
- return list;
- }
-
- /**
- * serialize the datatree and sessions
- * @param dt the datatree to be serialized
- * @param sessions the sessions to be serialized
- * @param oa the output archive to serialize into
- * @param header the header of this snapshot
- * @throws IOException
- */
- protected void serialize(DataTree dt,Map<Long, Integer> sessions,
- OutputArchive oa, FileHeader header) throws IOException {
- // this is really a programmatic error and not something that can
- // happen at runtime
- if(header==null)
- throw new IllegalStateException(
- "Snapshot's not open for writing: uninitialized header");
- header.serialize(oa, "fileheader");
- SerializeUtils.serializeSnapshot(dt,oa,sessions);
- }
-
- /**
- * serialize the datatree and session into the file snapshot
- * @param dt the datatree to be serialized
- * @param sessions the sessions to be serialized
- * @param snapShot the file to store snapshot into
- * @param fsync sync the file immediately after write
- */
- public synchronized void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot, boolean fsync)
- throws IOException {
- if (!close) {
- try (CheckedOutputStream crcOut =
- new CheckedOutputStream(new BufferedOutputStream(fsync ? new AtomicFileOutputStream(snapShot) :
- new FileOutputStream(snapShot)),
- new Adler32())) {
- //CheckedOutputStream cout = new CheckedOutputStream()
- OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
- FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
- serialize(dt, sessions, oa, header);
- long val = crcOut.getChecksum().getValue();
- oa.writeLong(val, "val");
- oa.writeString("/", "path");
- crcOut.flush();
- }
- }
- }
-
- /**
- * synchronized close just so that if serialize is in place
- * the close operation will block and will wait till serialize
- * is done and will set the close flag
- */
- @Override
- public synchronized void close() throws IOException {
- close = true;
- }
-
-}