Skip to content

Commit 33d63ac

Browse files
authored
Integrate spot restoration tool with CLI restore command (#52)
This commit integrates the SpotRestorationTool to RestoreFromBackupTool: when user triggers a restore command using ZK CLI, if a znode path is specific, it will run spot restoration on top of an offline restoration of backup files, the spot restoration will use the restored backup files.
1 parent 2cb4052 commit 33d63ac

File tree

4 files changed

+302
-81
lines changed

4 files changed

+302
-81
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/cli/RestoreCommand.java

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public class RestoreCommand extends CliCommand {
4444
+ OptionFullCommand.LOG_DESTINATION + "] [" + OptionFullCommand.TIMETABLE_STORAGE_PATH
4545
+ "](needed if restore to a timestamp) [" + OptionFullCommand.LOCAL_RESTORE_TEMP_DIR_PATH
4646
+ "](optional) [" + OptionFullCommand.DRY_RUN + "](optional) ["
47-
+ OptionFullCommand.OVERWRITE + "](optional)";
47+
+ OptionFullCommand.OVERWRITE + "](optional)\n Options for spot restoration: \n["
48+
+ OptionFullCommand.ZNODE_PATH_TO_RESTORE + "] ["
49+
+ OptionFullCommand.ZK_SERVER_CONNECTION_STRING + "] ["
50+
+ OptionFullCommand.RECURSIVE_SPOT_RESTORE + "](optional)";
4851

4952
public final class OptionLongForm {
5053
/* Required if no restore timestamp is specified */
@@ -66,6 +69,14 @@ public final class OptionLongForm {
6669
/* Optional. Default value false */
6770
public static final String OVERWRITE = "overwrite";
6871

72+
//For spot restoration
73+
/* Required */
74+
public static final String ZNODE_PATH_TO_RESTORE = "znode_path_to_restore";
75+
/* Required */
76+
public static final String ZK_SERVER_CONNECTION_STRING = "zk_server_connection_string";
77+
/* Optional. Default value false */
78+
public static final String RECURSIVE_SPOT_RESTORE = "recursive_spot_restore";
79+
6980
// Create a private constructor so it can't be instantiated
7081
private OptionLongForm() {
7182
}
@@ -83,6 +94,11 @@ public final class OptionShortForm {
8394
public static final String HELP = "h";
8495
public static final String OVERWRITE = "f";
8596

97+
//For spot restoration
98+
public static final String ZNODE_PATH_TO_RESTORE = "p";
99+
public static final String ZK_SERVER_CONNECTION_STRING = "c";
100+
public static final String RECURSIVE_SPOT_RESTORE = "a";
101+
86102
// Create a private constructor so it can't be instantiated
87103
private OptionShortForm() {
88104
}
@@ -107,6 +123,15 @@ public final class OptionFullCommand {
107123
public static final String DRY_RUN = "-" + OptionShortForm.DRY_RUN;
108124
public static final String OVERWRITE = "-" + OptionShortForm.OVERWRITE;
109125

126+
//For spot restoration
127+
public static final String ZNODE_PATH_TO_RESTORE =
128+
"-" + OptionShortForm.ZNODE_PATH_TO_RESTORE + " " + OptionLongForm.ZNODE_PATH_TO_RESTORE;
129+
public static final String ZK_SERVER_CONNECTION_STRING =
130+
"-" + OptionShortForm.ZK_SERVER_CONNECTION_STRING + " "
131+
+ OptionLongForm.ZK_SERVER_CONNECTION_STRING;
132+
public static final String RECURSIVE_SPOT_RESTORE =
133+
"-" + OptionShortForm.RECURSIVE_SPOT_RESTORE;
134+
110135
// Create a private constructor so it can't be instantiated
111136
private OptionFullCommand() {
112137
}
@@ -127,6 +152,14 @@ private OptionFullCommand() {
127152
OptionLongForm.LOCAL_RESTORE_TEMP_DIR_PATH));
128153
options.addOption(new Option(OptionShortForm.DRY_RUN, false, OptionLongForm.DRY_RUN));
129154
options.addOption(new Option(OptionShortForm.OVERWRITE, false, OptionLongForm.OVERWRITE));
155+
156+
//For spot restoration
157+
options.addOption(new Option(OptionShortForm.ZNODE_PATH_TO_RESTORE, true,
158+
OptionLongForm.ZNODE_PATH_TO_RESTORE));
159+
options.addOption(new Option(OptionShortForm.ZK_SERVER_CONNECTION_STRING, true,
160+
OptionLongForm.ZK_SERVER_CONNECTION_STRING));
161+
options.addOption(new Option(OptionShortForm.RECURSIVE_SPOT_RESTORE, false,
162+
OptionLongForm.RECURSIVE_SPOT_RESTORE));
130163
}
131164

132165
public RestoreCommand() {
@@ -136,26 +169,46 @@ public RestoreCommand() {
136169

137170
@Override
138171
public String getUsageStr() {
139-
return "Usage: RestoreFromBackupTool " + RESTORE_CMD_STR + " " + OPTION_STR + "\n "
172+
return "Usage: RestoreFromBackupTool " + RESTORE_CMD_STR + " " + OPTION_STR
173+
+ "\n Options for both offline restoration and spot restoration:\n "
140174
+ OptionFullCommand.RESTORE_ZXID
141-
+ ": the point to restore to, either the string 'latest' or a zxid in hex format. Choose one between this option or "
142-
+ OptionFullCommand.RESTORE_TIMESTAMP
143-
+ ", if both are specified, this option will be prioritized\n "
175+
+ ": the point to restore to, either the string 'latest' or a zxid in hex format. "
176+
+ "Choose one between this option or " + OptionFullCommand.RESTORE_TIMESTAMP
177+
+ ", if both are specified, this option will be prioritized. "
178+
+ "Required for both offline restoration and spot restoration.\n "
144179
+ OptionFullCommand.RESTORE_TIMESTAMP
145180
+ ": the point to restore to, a timestamp in long format. Choose one between this option or "
146-
+ OptionFullCommand.RESTORE_ZXID + ".\n " + OptionFullCommand.BACKUP_STORE
147-
+ ": the connection information for the backup store\n For GPFS the format is: gpfs:<config_path>:<backup_path>:<namespace>\n "
148-
+ OptionFullCommand.SNAP_DESTINATION
149-
+ ": local destination path for restored snapshots\n "
150-
+ OptionFullCommand.LOG_DESTINATION + ": local destination path for restored txlogs\n "
151-
+ OptionFullCommand.TIMETABLE_STORAGE_PATH
152-
+ ": Needed if restore to a timestamp. Backup storage path for timetable files, for GPFS the format is: gpfs:<config_path>:<backup_path>:<namespace>, if not set, default to be same as backup storage path\n "
181+
+ OptionFullCommand.RESTORE_ZXID
182+
+ ". Required for both offline restoration and spot restoration.\n "
183+
+ OptionFullCommand.BACKUP_STORE
184+
+ ": the connection information for the backup store\n "
185+
+ "For GPFS the format is: gpfs:<config_path>:<backup_path>:<namespace>\n "
186+
+ "Required for both offline restoration and spot restoration.\n "
187+
+ OptionFullCommand.SNAP_DESTINATION + ": local destination path for restored snapshots. "
188+
+ "Required for offline restoration.\n " + OptionFullCommand.LOG_DESTINATION
189+
+ ": local destination path for restored txlogs. "
190+
+ "Required for offline restoration.\n " + OptionFullCommand.TIMETABLE_STORAGE_PATH
191+
+ ": Needed if restore to a timestamp. Backup storage path for timetable files. "
192+
+ "For GPFS the format is: gpfs:<config_path>:<backup_path>:<namespace>. "
193+
+ "If not set, default to be same as backup storage path\n "
153194
+ OptionFullCommand.LOCAL_RESTORE_TEMP_DIR_PATH
154-
+ ": Optional, local path for creating a temporary intermediate directory for restoration, the directory will be deleted after restoration is done\n "
195+
+ ": Required for spot restoration, and optional for offline restoration. "
196+
+ "The restore tool will use this local path to stage temporary files needed for restoration work, "
197+
+ "this directory will be deleted after restoration is done\n "
155198
+ OptionFullCommand.DRY_RUN + " " + OptionLongForm.DRY_RUN
156199
+ ": Optional, no files will be actually copied in a dry run\n "
157200
+ OptionFullCommand.OVERWRITE + " " + OptionLongForm.OVERWRITE
158-
+ ": Optional, default false. If true, the destination directories will be overwritten\n";
201+
+ ": Optional, default false. If true, all existing files will be wiped out and the directories "
202+
+ "be populated with restored files\n " + "Options for spot restoration only:\n "
203+
+ OptionFullCommand.ZNODE_PATH_TO_RESTORE
204+
+ ": The znode path to restore in the zk server\n "
205+
+ OptionFullCommand.ZK_SERVER_CONNECTION_STRING
206+
+ ": The connection string used to establish a client to server connection "
207+
+ "in order to do spot restoration on zk server. "
208+
+ "The format of this string should be host:port, " + "for example: 127.0.0.1:3000\n "
209+
+ OptionFullCommand.RECURSIVE_SPOT_RESTORE
210+
+ ": Optional, default false. If false, the spot restoration will be done on one single node only; "
211+
+ "if true, it will be done recursively on all of its descendants as well";
159212
}
160213

161214
@Override
@@ -168,8 +221,7 @@ public CliCommand parse(String[] cmdArgs) throws CliParseException {
168221
}
169222
if ((!cl.hasOption(OptionShortForm.RESTORE_ZXID) && !cl
170223
.hasOption(OptionShortForm.RESTORE_TIMESTAMP)) || !cl
171-
.hasOption(OptionShortForm.BACKUP_STORE) || !cl.hasOption(OptionShortForm.SNAP_DESTINATION)
172-
|| !cl.hasOption(OptionShortForm.LOG_DESTINATION)) {
224+
.hasOption(OptionShortForm.BACKUP_STORE)) {
173225
throw new CliParseException("Missing required argument(s).\n" + getUsageStr());
174226
}
175227
return this;

0 commit comments

Comments
 (0)