From c7a42ef3733d2d5d0d5a8913f4f162e119e9bfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Paksy?= Date: Fri, 6 Mar 2026 14:56:20 +0100 Subject: [PATCH 1/2] ZOOKEEPER-5022: Added "exit" command to zkCli.sh as an alias for "quit" because that's a very common command to exit a shell. --- .../main/resources/markdown/zookeeperCLI.md | 8 +++++ .../org/apache/zookeeper/ZooKeeperMain.java | 31 ++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md b/zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md index 7096aa0cc89..5a95c628c86 100644 --- a/zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md +++ b/zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md @@ -45,6 +45,7 @@ ZooKeeper -server host:port cmd args delete [-v version] path deleteall path delquota [-n|-b|-N|-B] path + exit get [-s] [-w] path getAcl [-s] path getAllChildrenNumber path @@ -352,6 +353,13 @@ Quit the CLI windows. [zkshell: 1] quit ``` +## exit +Quit the CLI windows. + +```bash +[zkshell: 1] exit +``` + ## reconfig Change the membership of the ensemble during the runtime. diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java b/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java index ca27348e164..fab808f92c4 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java @@ -77,12 +77,21 @@ public boolean getPrintWatches() { return printWatches; } + private static final String CMD_CONNECT = "connect"; + private static final String CMD_HISTORY = "history"; + private static final String CMD_REDO = "redo"; + private static final String CMD_QUIT = "quit"; + private static final String CMD_EXIT = "exit"; + private static final String CMD_PRINT_WATCHES = "printwatches"; + + static { - commandMap.put("connect", "host:port"); - commandMap.put("history", ""); - commandMap.put("redo", "cmdno"); - commandMap.put("printwatches", "on|off"); - commandMap.put("quit", ""); + commandMap.put(CMD_CONNECT, "host:port"); + commandMap.put(CMD_HISTORY, ""); + commandMap.put(CMD_REDO, "cmdno"); + commandMap.put(CMD_PRINT_WATCHES, "on|off"); + commandMap.put(CMD_QUIT, ""); + commandMap.put(CMD_EXIT, ""); Stream.of(CommandFactory.Command.values()) .map(command -> CommandFactory.getInstance(command)) // add all commands to commandMapCli and commandMap @@ -409,34 +418,34 @@ protected boolean processZKCmd(MyCommandOptions co) throws CliException, IOExcep LOG.debug("Processing {}", cmd); - if (cmd.equals("quit")) { + if (cmd.equals(CMD_QUIT) || cmd.equals(CMD_EXIT)) { zk.close(); ServiceUtils.requestSystemExit(exitCode); - } else if (cmd.equals("redo") && args.length >= 2) { + } else if (cmd.equals(CMD_REDO) && args.length >= 2) { Integer i = Integer.decode(args[1]); if (commandCount <= i || i < 0) { // don't allow redoing this redo throw new MalformedCommandException("Command index out of range"); } cl.parseCommand(history.get(i)); - if (cl.getCommand().equals("redo")) { + if (cl.getCommand().equals(CMD_REDO)) { throw new MalformedCommandException("No redoing redos"); } history.put(commandCount, history.get(i)); processCmd(cl); - } else if (cmd.equals("history")) { + } else if (cmd.equals(CMD_HISTORY)) { for (int i = commandCount - 10; i <= commandCount; ++i) { if (i < 0) { continue; } System.out.println(i + " - " + history.get(i)); } - } else if (cmd.equals("printwatches")) { + } else if (cmd.equals(CMD_PRINT_WATCHES)) { if (args.length == 1) { System.out.println("printwatches is " + (printWatches ? "on" : "off")); } else { printWatches = args[1].equals("on"); } - } else if (cmd.equals("connect")) { + } else if (cmd.equals(CMD_CONNECT)) { if (args.length >= 2) { connectToZK(args[1]); } else { From 2824342677ad59c2b220ff69c921e28432c34f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Paksy?= Date: Mon, 23 Mar 2026 09:45:04 +0100 Subject: [PATCH 2/2] ZOOKEEPER-5022: Do not duplicate the quit section in zookeeperCLI.md Address review finding: > nit: zookeeperCLI.md exit section duplicates the quit wording almost verbatim; a single sentence pointing at quit might stay shorter. --- .../src/main/resources/markdown/zookeeperCLI.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md b/zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md index 5a95c628c86..aeccf1dcfce 100644 --- a/zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md +++ b/zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md @@ -346,20 +346,13 @@ A switch to turn on/off whether printing watches or not. printwatches is on ``` -## quit -Quit the CLI windows. +## quit (or exit) +The `quit` or `exit` command can be used to quit the CLI windows. ```bash [zkshell: 1] quit ``` -## exit -Quit the CLI windows. - -```bash -[zkshell: 1] exit -``` - ## reconfig Change the membership of the ensemble during the runtime.