errose28 commented on code in PR #6533:
URL: https://github.com/apache/ozone/pull/6533#discussion_r1619511853


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneRepairShell.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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.hadoop.ozone.shell;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.debug.DBScanner;
+import org.apache.hadoop.ozone.debug.RDBParser;
+import org.apache.hadoop.ozone.om.OMStorage;
+import org.apache.hadoop.ozone.repair.RDBRepair;
+import org.apache.hadoop.ozone.repair.TransactionInfoRepair;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * Test Ozone Repair shell.
+ */
+public class TestOzoneRepairShell {
+
+  private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+  private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+  private static final PrintStream OLD_OUT = System.out;
+  private static final PrintStream OLD_ERR = System.err;
+  private static final String DEFAULT_ENCODING = UTF_8.name();
+  private static MiniOzoneCluster cluster = null;
+  private static OzoneConfiguration conf = null;
+
+  private static final String TRANSACTION_INFO_TABLE_TERM_INDEX_PATTERN = 
"([0-9]+#[0-9]+)";
+
+  @BeforeAll
+  public static void init() throws Exception {
+    conf = new OzoneConfiguration();
+    cluster = MiniOzoneCluster.newBuilder(conf).build();
+    cluster.waitForClusterToBeReady();
+  }
+
+  @BeforeEach
+  public void setup() throws Exception {
+    System.setOut(new PrintStream(out, false, DEFAULT_ENCODING));
+    System.setErr(new PrintStream(err, false, DEFAULT_ENCODING));
+  }
+
+  @AfterEach
+  public void reset() {
+    // reset stream after each unit test
+    out.reset();
+    err.reset();
+
+    // restore system streams
+    System.setOut(OLD_OUT);
+    System.setErr(OLD_ERR);
+  }
+
+  @Test
+  public void testUpdateTransactionInfoTable() throws Exception {
+    CommandLine cmd = new CommandLine(new RDBRepair()).addSubcommand(new 
TransactionInfoRepair());
+    String dbPath = OMStorage.getOmDbDir(conf) + OM_KEY_PREFIX + OM_DB_NAME;
+
+    cluster.getOzoneManager().stop();
+
+    String cmdOut = scanTransactionInfoTable(dbPath);
+    String originalHighestTermIndex = parseScanOutput(cmdOut);
+
+    String testTerm = "1111";
+    String testIndex = "1111";
+    String[] args =
+        new String[] {"--db=" + dbPath, "transaction", 
"--highest-transaction", testTerm + "#" + testIndex};
+    int exitCode = cmd.execute(args);
+    assertEquals(0, exitCode);
+    assertThat(out.toString(DEFAULT_ENCODING)).contains(
+        "The original highest transaction Info was " + 
originalHighestTermIndex);
+    assertThat(out.toString(DEFAULT_ENCODING)).contains(
+        String.format("The highest transaction info has been updated to: 
(t:%s, i:%s)",
+        testTerm, testIndex));
+
+    String cmdOut2 = scanTransactionInfoTable(dbPath);
+    assertThat(cmdOut2).contains(testTerm + "#" + testIndex);
+    cluster.getOzoneManager().restart();
+  }
+
+  private String scanTransactionInfoTable(String dbPath) throws Exception {
+    CommandLine cmdDBScanner = new CommandLine(new 
RDBParser()).addSubcommand(new DBScanner());
+    String[] argsDBScanner =
+        new String[] {"--db=" + dbPath, "scan", "--column_family", 
"transactionInfoTable"};
+    cmdDBScanner.execute(argsDBScanner);
+    return out.toString(DEFAULT_ENCODING);
+  }
+
+  private String parseScanOutput(String output) {
+    Pattern pattern = 
Pattern.compile(TRANSACTION_INFO_TABLE_TERM_INDEX_PATTERN);
+    Matcher matcher = pattern.matcher(output);
+    if (matcher.find()) {
+      String[] termIndex = matcher.group(1).split("#");
+      return String.format("(t:%s, i:%s)", termIndex[0], termIndex[1]);
+    }
+    return "dummyTermIndex";

Review Comment:
   If we get unexpected output, we should fail the test here. Returning this 
default value will just fail the test later in a confusing way.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/TransactionInfoRepair.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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
+ *
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <p>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.hadoop.ozone.repair;
+
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.TransactionInfo;
+import org.apache.hadoop.hdds.utils.db.StringCodec;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
+import org.apache.hadoop.ozone.debug.RocksDBUtils;
+import org.kohsuke.MetaInfServices;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.RocksDBException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
+import static 
org.apache.hadoop.ozone.om.OmMetadataManagerImpl.TRANSACTION_INFO_TABLE;
+
+
+/**
+ * Tool to update the highest term-index in transactionInfoTable.
+ */
[email protected](
+    name = "transaction",
+    description = "CLI to update the highest index in transactionInfoTable.",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class
+)
+@MetaInfServices(SubcommandWithParent.class)
+public class TransactionInfoRepair
+    implements Callable<Void>, SubcommandWithParent  {
+
+  protected static final Logger LOG = 
LoggerFactory.getLogger(TransactionInfoRepair.class);
+
+  @CommandLine.Spec
+  private static CommandLine.Model.CommandSpec spec;
+
+  @CommandLine.ParentCommand
+  private RDBRepair parent;
+
+  @CommandLine.Option(names = {"--highest-transaction"},
+      required = true,
+      description = "Highest termIndex of transactionInfoTable. The input 
format is: {term}#{index}.")

Review Comment:
   Can we make this more user friendly with `--term` and `--index` as separate, 
required, non-zero integer options? Currently the user can just write a random 
string into the DB.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/TransactionInfoRepair.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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
+ *
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <p>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.hadoop.ozone.repair;
+
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.TransactionInfo;
+import org.apache.hadoop.hdds.utils.db.StringCodec;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
+import org.apache.hadoop.ozone.debug.RocksDBUtils;
+import org.kohsuke.MetaInfServices;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.RocksDBException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
+import static 
org.apache.hadoop.ozone.om.OmMetadataManagerImpl.TRANSACTION_INFO_TABLE;
+
+
+/**
+ * Tool to update the highest term-index in transactionInfoTable.
+ */
[email protected](
+    name = "transaction",
+    description = "CLI to update the highest index in transactionInfoTable.",

Review Comment:
   Is this expected to work for just OM, or SCM as well? I think it should also 
work for SCM, but we haven't tested it. If we want to keep the scope to just OM 
for this PR, we should update the description to say that it's only supported 
for OM. Then in a follow up we can extend it to support SCM and update this 
description.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/TransactionInfoRepair.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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
+ *
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <p>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.hadoop.ozone.repair;
+
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.TransactionInfo;
+import org.apache.hadoop.hdds.utils.db.StringCodec;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
+import org.apache.hadoop.ozone.debug.RocksDBUtils;
+import org.kohsuke.MetaInfServices;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.RocksDBException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
+import static 
org.apache.hadoop.ozone.om.OmMetadataManagerImpl.TRANSACTION_INFO_TABLE;
+
+
+/**
+ * Tool to update the highest term-index in transactionInfoTable.
+ */
[email protected](
+    name = "transaction",
+    description = "CLI to update the highest index in transactionInfoTable.",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class
+)
+@MetaInfServices(SubcommandWithParent.class)
+public class TransactionInfoRepair
+    implements Callable<Void>, SubcommandWithParent  {
+
+  protected static final Logger LOG = 
LoggerFactory.getLogger(TransactionInfoRepair.class);
+
+  @CommandLine.Spec
+  private static CommandLine.Model.CommandSpec spec;
+
+  @CommandLine.ParentCommand
+  private RDBRepair parent;
+
+  @CommandLine.Option(names = {"--highest-transaction"},
+      required = true,
+      description = "Highest termIndex of transactionInfoTable. The input 
format is: {term}#{index}.")
+  private String highestTransactionTermIndex;
+
+
+  protected void setHighestTransactionTermIndex(
+      String highestTransactionTermIndex) {
+    this.highestTransactionTermIndex = highestTransactionTermIndex;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    List<ColumnFamilyHandle> cfHandleList = new ArrayList<>();
+    String dbPath = getParent().getDbPath();
+    List<ColumnFamilyDescriptor> cfDescList = 
RocksDBUtils.getColumnFamilyDescriptors(
+        dbPath);
+
+    try (ManagedRocksDB db = ManagedRocksDB.open(dbPath, cfDescList, 
cfHandleList)) {
+      ColumnFamilyHandle transactionInfoCfh = 
RocksDBUtils.getColumnFamilyHandle(TRANSACTION_INFO_TABLE, cfHandleList);
+      if (transactionInfoCfh == null) {
+        System.err.println(TRANSACTION_INFO_TABLE + " is not in a column 
family in DB for the given path.");
+        return null;

Review Comment:
   I think the command will still exit 0 in this case. If you throw something 
like`IllegalArgumentException` the stack trace will be filtered out, the 
message printed, and the return code will be non-zero.



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneRepairShell.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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.hadoop.ozone.shell;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.debug.DBScanner;
+import org.apache.hadoop.ozone.debug.RDBParser;
+import org.apache.hadoop.ozone.om.OMStorage;
+import org.apache.hadoop.ozone.repair.RDBRepair;
+import org.apache.hadoop.ozone.repair.TransactionInfoRepair;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * Test Ozone Repair shell.
+ */
+public class TestOzoneRepairShell {
+
+  private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+  private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+  private static final PrintStream OLD_OUT = System.out;
+  private static final PrintStream OLD_ERR = System.err;
+  private static final String DEFAULT_ENCODING = UTF_8.name();
+  private static MiniOzoneCluster cluster = null;
+  private static OzoneConfiguration conf = null;
+
+  private static final String TRANSACTION_INFO_TABLE_TERM_INDEX_PATTERN = 
"([0-9]+#[0-9]+)";
+
+  @BeforeAll
+  public static void init() throws Exception {
+    conf = new OzoneConfiguration();
+    cluster = MiniOzoneCluster.newBuilder(conf).build();
+    cluster.waitForClusterToBeReady();
+  }
+
+  @BeforeEach
+  public void setup() throws Exception {
+    System.setOut(new PrintStream(out, false, DEFAULT_ENCODING));
+    System.setErr(new PrintStream(err, false, DEFAULT_ENCODING));
+  }
+
+  @AfterEach
+  public void reset() {
+    // reset stream after each unit test
+    out.reset();
+    err.reset();
+
+    // restore system streams
+    System.setOut(OLD_OUT);
+    System.setErr(OLD_ERR);
+  }
+
+  @Test
+  public void testUpdateTransactionInfoTable() throws Exception {
+    CommandLine cmd = new CommandLine(new RDBRepair()).addSubcommand(new 
TransactionInfoRepair());
+    String dbPath = OMStorage.getOmDbDir(conf) + OM_KEY_PREFIX + OM_DB_NAME;

Review Comment:
   nit. This is a path on the local filesystem, so it should be constructed 
from a `Path` or `File` object. `OM_KEY_PREFIX` is for files in the Ozone 
filesystem.



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneRepairShell.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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.hadoop.ozone.shell;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.debug.DBScanner;
+import org.apache.hadoop.ozone.debug.RDBParser;
+import org.apache.hadoop.ozone.om.OMStorage;
+import org.apache.hadoop.ozone.repair.RDBRepair;
+import org.apache.hadoop.ozone.repair.TransactionInfoRepair;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * Test Ozone Repair shell.
+ */
+public class TestOzoneRepairShell {
+
+  private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+  private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+  private static final PrintStream OLD_OUT = System.out;
+  private static final PrintStream OLD_ERR = System.err;
+  private static final String DEFAULT_ENCODING = UTF_8.name();
+  private static MiniOzoneCluster cluster = null;
+  private static OzoneConfiguration conf = null;
+
+  private static final String TRANSACTION_INFO_TABLE_TERM_INDEX_PATTERN = 
"([0-9]+#[0-9]+)";
+
+  @BeforeAll
+  public static void init() throws Exception {
+    conf = new OzoneConfiguration();
+    cluster = MiniOzoneCluster.newBuilder(conf).build();
+    cluster.waitForClusterToBeReady();
+  }
+
+  @BeforeEach
+  public void setup() throws Exception {
+    System.setOut(new PrintStream(out, false, DEFAULT_ENCODING));
+    System.setErr(new PrintStream(err, false, DEFAULT_ENCODING));
+  }
+
+  @AfterEach
+  public void reset() {
+    // reset stream after each unit test
+    out.reset();
+    err.reset();
+
+    // restore system streams
+    System.setOut(OLD_OUT);
+    System.setErr(OLD_ERR);
+  }
+
+  @Test
+  public void testUpdateTransactionInfoTable() throws Exception {
+    CommandLine cmd = new CommandLine(new RDBRepair()).addSubcommand(new 
TransactionInfoRepair());
+    String dbPath = OMStorage.getOmDbDir(conf) + OM_KEY_PREFIX + OM_DB_NAME;
+
+    cluster.getOzoneManager().stop();
+
+    String cmdOut = scanTransactionInfoTable(dbPath);
+    String originalHighestTermIndex = parseScanOutput(cmdOut);
+
+    String testTerm = "1111";
+    String testIndex = "1111";
+    String[] args =
+        new String[] {"--db=" + dbPath, "transaction", 
"--highest-transaction", testTerm + "#" + testIndex};
+    int exitCode = cmd.execute(args);
+    assertEquals(0, exitCode);
+    assertThat(out.toString(DEFAULT_ENCODING)).contains(
+        "The original highest transaction Info was " + 
originalHighestTermIndex);
+    assertThat(out.toString(DEFAULT_ENCODING)).contains(
+        String.format("The highest transaction info has been updated to: 
(t:%s, i:%s)",
+        testTerm, testIndex));
+
+    String cmdOut2 = scanTransactionInfoTable(dbPath);
+    assertThat(cmdOut2).contains(testTerm + "#" + testIndex);
+    cluster.getOzoneManager().restart();

Review Comment:
   Is the goal to make sure that the OM starts correctly after the repair? If 
so, we should use the same transaction update command to restore the old 
values, then do a metadata write operation on the cluster when it comes back up.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/TransactionInfoRepair.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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
+ *
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <p>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.hadoop.ozone.repair;
+
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.TransactionInfo;
+import org.apache.hadoop.hdds.utils.db.StringCodec;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
+import org.apache.hadoop.ozone.debug.RocksDBUtils;
+import org.kohsuke.MetaInfServices;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.RocksDBException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
+import static 
org.apache.hadoop.ozone.om.OmMetadataManagerImpl.TRANSACTION_INFO_TABLE;
+
+
+/**
+ * Tool to update the highest term-index in transactionInfoTable.
+ */
[email protected](
+    name = "transaction",
+    description = "CLI to update the highest index in transactionInfoTable.",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class
+)
+@MetaInfServices(SubcommandWithParent.class)
+public class TransactionInfoRepair
+    implements Callable<Void>, SubcommandWithParent  {
+
+  protected static final Logger LOG = 
LoggerFactory.getLogger(TransactionInfoRepair.class);
+
+  @CommandLine.Spec
+  private static CommandLine.Model.CommandSpec spec;
+
+  @CommandLine.ParentCommand
+  private RDBRepair parent;
+
+  @CommandLine.Option(names = {"--highest-transaction"},
+      required = true,
+      description = "Highest termIndex of transactionInfoTable. The input 
format is: {term}#{index}.")
+  private String highestTransactionTermIndex;
+
+
+  protected void setHighestTransactionTermIndex(
+      String highestTransactionTermIndex) {
+    this.highestTransactionTermIndex = highestTransactionTermIndex;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    List<ColumnFamilyHandle> cfHandleList = new ArrayList<>();
+    String dbPath = getParent().getDbPath();
+    List<ColumnFamilyDescriptor> cfDescList = 
RocksDBUtils.getColumnFamilyDescriptors(
+        dbPath);
+
+    try (ManagedRocksDB db = ManagedRocksDB.open(dbPath, cfDescList, 
cfHandleList)) {
+      ColumnFamilyHandle transactionInfoCfh = 
RocksDBUtils.getColumnFamilyHandle(TRANSACTION_INFO_TABLE, cfHandleList);
+      if (transactionInfoCfh == null) {
+        System.err.println(TRANSACTION_INFO_TABLE + " is not in a column 
family in DB for the given path.");
+        return null;
+      }
+      TransactionInfo originalTransactionInfo =
+          RocksDBUtils.getValue(db, transactionInfoCfh, TRANSACTION_INFO_KEY, 
TransactionInfo.getCodec());
+
+      System.out.println("The original highest transaction Info was " + 
originalTransactionInfo.getTermIndex());
+
+      TransactionInfo transactionInfo = TransactionInfo.valueOf(
+          highestTransactionTermIndex);
+
+      byte[] transactionInfoBytes = 
TransactionInfo.getCodec().toPersistedFormat(transactionInfo);
+      db.get()
+          .put(transactionInfoCfh, 
StringCodec.get().toPersistedFormat(TRANSACTION_INFO_KEY), 
transactionInfoBytes);
+
+      System.out.println("The highest transaction info has been updated to: " +
+          RocksDBUtils.getValue(db, transactionInfoCfh, TRANSACTION_INFO_KEY,
+              TransactionInfo.getCodec()).getTermIndex());
+    } catch (RocksDBException exception) {
+      System.err.println("Failed to update the RocksDB for the given path: " + 
dbPath);
+      System.err.println(
+          "Make sure that Ozone entity (OM, SCM or DN) is not running for the 
give database path and current host.");
+      LOG.error(exception.toString());

Review Comment:
   ```suggestion
         LOG.error("Failed to update RocksDB.", exception);
   ```



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/TransactionInfoRepair.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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
+ *
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <p>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.hadoop.ozone.repair;
+
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.TransactionInfo;
+import org.apache.hadoop.hdds.utils.db.StringCodec;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
+import org.apache.hadoop.ozone.debug.RocksDBUtils;
+import org.kohsuke.MetaInfServices;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.RocksDBException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
+import static 
org.apache.hadoop.ozone.om.OmMetadataManagerImpl.TRANSACTION_INFO_TABLE;
+
+
+/**
+ * Tool to update the highest term-index in transactionInfoTable.
+ */
[email protected](
+    name = "transaction",
+    description = "CLI to update the highest index in transactionInfoTable.",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class
+)
+@MetaInfServices(SubcommandWithParent.class)
+public class TransactionInfoRepair
+    implements Callable<Void>, SubcommandWithParent  {
+
+  protected static final Logger LOG = 
LoggerFactory.getLogger(TransactionInfoRepair.class);
+
+  @CommandLine.Spec
+  private static CommandLine.Model.CommandSpec spec;
+
+  @CommandLine.ParentCommand
+  private RDBRepair parent;
+
+  @CommandLine.Option(names = {"--highest-transaction"},
+      required = true,
+      description = "Highest termIndex of transactionInfoTable. The input 
format is: {term}#{index}.")
+  private String highestTransactionTermIndex;
+
+
+  protected void setHighestTransactionTermIndex(
+      String highestTransactionTermIndex) {
+    this.highestTransactionTermIndex = highestTransactionTermIndex;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    List<ColumnFamilyHandle> cfHandleList = new ArrayList<>();
+    String dbPath = getParent().getDbPath();
+    List<ColumnFamilyDescriptor> cfDescList = 
RocksDBUtils.getColumnFamilyDescriptors(
+        dbPath);
+
+    try (ManagedRocksDB db = ManagedRocksDB.open(dbPath, cfDescList, 
cfHandleList)) {
+      ColumnFamilyHandle transactionInfoCfh = 
RocksDBUtils.getColumnFamilyHandle(TRANSACTION_INFO_TABLE, cfHandleList);
+      if (transactionInfoCfh == null) {
+        System.err.println(TRANSACTION_INFO_TABLE + " is not in a column 
family in DB for the given path.");
+        return null;
+      }
+      TransactionInfo originalTransactionInfo =
+          RocksDBUtils.getValue(db, transactionInfoCfh, TRANSACTION_INFO_KEY, 
TransactionInfo.getCodec());
+
+      System.out.println("The original highest transaction Info was " + 
originalTransactionInfo.getTermIndex());
+
+      TransactionInfo transactionInfo = TransactionInfo.valueOf(
+          highestTransactionTermIndex);
+
+      byte[] transactionInfoBytes = 
TransactionInfo.getCodec().toPersistedFormat(transactionInfo);
+      db.get()
+          .put(transactionInfoCfh, 
StringCodec.get().toPersistedFormat(TRANSACTION_INFO_KEY), 
transactionInfoBytes);
+
+      System.out.println("The highest transaction info has been updated to: " +
+          RocksDBUtils.getValue(db, transactionInfoCfh, TRANSACTION_INFO_KEY,
+              TransactionInfo.getCodec()).getTermIndex());
+    } catch (RocksDBException exception) {
+      System.err.println("Failed to update the RocksDB for the given path: " + 
dbPath);
+      System.err.println(
+          "Make sure that Ozone entity (OM, SCM or DN) is not running for the 
give database path and current host.");

Review Comment:
   Referencing two earlier comments here:
   - We should be be specific about which entity this is currently supported 
on. I'm pretty sure this should just be OM right now.
   - We need to make sure the command exits non-zero in this case.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to