milleruntime commented on a change in pull request #2541:
URL: https://github.com/apache/accumulo/pull/2541#discussion_r821691147
##########
File path:
shell/src/main/java/org/apache/accumulo/shell/commands/FateCommand.java
##########
@@ -130,107 +132,131 @@ public int execute(final String fullCommand, final
CommandLine cl, final Shell s
AdminUtil<FateCommand> admin = new AdminUtil<>(false);
- String path = context.getZooKeeperRoot() + Constants.ZFATE;
+ String fatePath = context.getZooKeeperRoot() + Constants.ZFATE;
var managerLockPath = ServiceLock.path(context.getZooKeeperRoot() +
Constants.ZMANAGER_LOCK);
+ var tableLocksPath = ServiceLock.path(context.getZooKeeperRoot() +
Constants.ZTABLE_LOCKS);
ZooReaderWriter zk =
getZooReaderWriter(context, siteConfig,
cl.getOptionValue(secretOption.getOpt()));
- ZooStore<FateCommand> zs = new ZooStore<>(path, zk);
+ ZooStore<FateCommand> zs = new ZooStore<>(fatePath, zk);
if ("fail".equals(cmd)) {
- if (args.length <= 1) {
- throw new ParseException("Must provide transaction ID");
- }
- for (int i = 1; i < args.length; i++) {
- if (!admin.prepFail(zs, zk, managerLockPath, args[i])) {
- System.out.printf("Could not fail transaction: %s%n", args[i]);
- failedCommand = true;
- }
- }
+ validateArgs(args);
+ failedCommand = failTx(admin, zs, zk, managerLockPath, args);
} else if ("delete".equals(cmd)) {
- if (args.length <= 1) {
- throw new ParseException("Must provide transaction ID");
- }
+ validateArgs(args);
+ failedCommand = deleteTx(admin, zs, zk, managerLockPath, args);
+ } else if ("list".equals(cmd) || "print".equals(cmd)) {
+ printTx(shellState, admin, zs, zk, tableLocksPath, args, cl,
+ cl.hasOption(statusOption.getOpt()));
+ } else if ("dump".equals(cmd)) {
+ String output = dumpTx(zs, args);
+ System.out.println(output);
+ } else {
+ throw new ParseException("Invalid command option");
+ }
+
+ return failedCommand ? 1 : 0;
+ }
+
+ String dumpTx(ZooStore<FateCommand> zs, String[] args) {
+ List<Long> txids;
+ if (args.length == 1) {
+ txids = zs.list();
+ } else {
+ txids = new ArrayList<>();
for (int i = 1; i < args.length; i++) {
- if (admin.prepDelete(zs, zk, managerLockPath, args[i])) {
- admin.deleteLocks(zk, context.getZooKeeperRoot() +
Constants.ZTABLE_LOCKS, args[i]);
- } else {
- System.out.printf("Could not delete transaction: %s%n", args[i]);
- failedCommand = true;
- }
+ txids.add(parseTxid(args[i]));
}
- } else if ("list".equals(cmd) || "print".equals(cmd)) {
- // Parse transaction ID filters for print display
- Set<Long> filterTxid = null;
- if (args.length >= 2) {
- filterTxid = new HashSet<>(args.length);
- for (int i = 1; i < args.length; i++) {
- try {
- Long val = parseTxid(args[i]);
- filterTxid.add(val);
- } catch (NumberFormatException nfe) {
- // Failed to parse, will exit instead of displaying everything
since the intention was
- // to potentially filter some data
- System.out.printf("Invalid transaction ID format: %s%n", args[i]);
- return 1;
- }
+ }
+
+ Gson gson = new GsonBuilder()
+ .registerTypeAdapter(ReadOnlyRepo.class, new InterfaceSerializer<>())
+ .registerTypeAdapter(Repo.class, new InterfaceSerializer<>())
+ .registerTypeAdapter(byte[].class, new
ByteArraySerializer()).setPrettyPrinting().create();
+
+ List<FateStack> txStacks = new ArrayList<>();
+ for (Long txid : txids) {
+ List<ReadOnlyRepo<FateCommand>> repoStack = zs.getStack(txid);
+ txStacks.add(new FateStack(txid, repoStack));
+ }
+
+ return gson.toJson(txStacks);
+ }
+
+ private void printTx(Shell shellState, AdminUtil<FateCommand> admin,
ZooStore<FateCommand> zs,
+ ZooReaderWriter zk, ServiceLock.ServiceLockPath tableLocksPath, String[]
args, CommandLine cl,
+ boolean printStatus) throws InterruptedException, KeeperException,
IOException {
+ // Parse transaction ID filters for print display
+ Set<Long> filterTxid = null;
+ if (args.length >= 2) {
+ filterTxid = new HashSet<>(args.length);
+ for (int i = 1; i < args.length; i++) {
+ try {
+ Long val = parseTxid(args[i]);
+ filterTxid.add(val);
+ } catch (NumberFormatException nfe) {
+ // Failed to parse, will exit instead of displaying everything since
the intention was
+ // to potentially filter some data
+ throw new RuntimeException("Invalid transaction ID format: " +
args[i], nfe);
}
}
+ }
- // Parse TStatus filters for print display
- EnumSet<TStatus> filterStatus = null;
- if (cl.hasOption(statusOption.getOpt())) {
- filterStatus = EnumSet.noneOf(TStatus.class);
- String[] tstat = cl.getOptionValues(statusOption.getOpt());
- for (String element : tstat) {
- try {
- filterStatus.add(TStatus.valueOf(element));
- } catch (IllegalArgumentException iae) {
- System.out.printf("Invalid transaction status name: %s%n",
element);
- return 1;
- }
+ // Parse TStatus filters for print display
+ EnumSet<TStatus> filterStatus = null;
+ if (printStatus) {
+ filterStatus = EnumSet.noneOf(TStatus.class);
+ String[] tstat = cl.getOptionValues(statusOption.getOpt());
+ for (String element : tstat) {
+ try {
+ filterStatus.add(TStatus.valueOf(element));
+ } catch (IllegalArgumentException iae) {
+ throw new RuntimeException("Invalid transaction status name: " +
element, iae);
}
}
+ }
- StringBuilder buf = new StringBuilder(8096);
- Formatter fmt = new Formatter(buf);
- admin.print(zs, zk, context.getZooKeeperRoot() + Constants.ZTABLE_LOCKS,
fmt, filterTxid,
- filterStatus);
-
shellState.printLines(Collections.singletonList(buf.toString()).iterator(),
- !cl.hasOption(disablePaginationOpt.getOpt()));
- } else if ("dump".equals(cmd)) {
- List<Long> txids;
+ StringBuilder buf = new StringBuilder(8096);
+ Formatter fmt = new Formatter(buf);
+ admin.print(zs, zk, tableLocksPath, fmt, filterTxid, filterStatus);
+ shellState.printLines(Collections.singletonList(buf.toString()).iterator(),
+ !cl.hasOption(disablePaginationOpt.getOpt()));
+ }
- if (args.length == 1) {
- txids = zs.list();
+ private boolean deleteTx(AdminUtil<FateCommand> admin, ZooStore<FateCommand>
zs,
+ ZooReaderWriter zk, ServiceLockPath zLockManagerPath, String[] args)
+ throws InterruptedException, KeeperException {
+ boolean success = true;
Review comment:
Fixed in c33b34aef77d4d1dfe9a31eca650983f3f714def
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]