Skip to content

Commit

Permalink
Reuse method from TransactionInfoRepair
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvekshayr committed Jan 31, 2025
1 parent 12ede3f commit 143e923
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
package org.apache.hadoop.ozone.shell;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition;
import org.apache.hadoop.hdds.server.ServerUtils;
import org.apache.hadoop.hdds.utils.IOUtils;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.debug.OzoneDebug;
import org.apache.hadoop.ozone.om.OMStorage;
import org.apache.hadoop.ozone.om.codec.OMDBDefinition;
import org.apache.hadoop.ozone.repair.OzoneRepair;
import org.apache.hadoop.ozone.repair.RepairTool.Component;
import org.apache.hadoop.ozone.repair.TransactionInfoRepair;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
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 org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.EnumSource;
import picocli.CommandLine;

import java.io.File;
Expand All @@ -58,6 +58,7 @@ public class TestOzoneRepairShell {
private static MiniOzoneCluster cluster = null;
private static OzoneConfiguration conf = null;
private static String om;
private static TransactionInfoRepair transactionInfoRepair;
private static final String TRANSACTION_INFO_TABLE_TERM_INDEX_PATTERN = "([0-9]+#[0-9]+)";

@BeforeAll
Expand All @@ -66,6 +67,7 @@ public static void init() throws Exception {
cluster = MiniOzoneCluster.newBuilder(conf).build();
cluster.waitForClusterToBeReady();
om = conf.get(OZONE_OM_ADDRESS_KEY);
transactionInfoRepair = new TransactionInfoRepair();
}

@BeforeEach
Expand All @@ -86,10 +88,11 @@ static void cleanup() {
}

@ParameterizedTest
@ValueSource(strings = {"om", "scm"})
public void testUpdateTransactionInfoTable(String component) throws Exception {
@EnumSource(value = Component.class, names = {"OM", "SCM"})
public void testUpdateTransactionInfoTable(Component component) throws Exception {
CommandLine cmd = new OzoneRepair().getCmd();
String dbPath = new File(getDbPath(component)).getPath();
String dbPath = getDbPath(component);
String componentLowerCase = component.toString().toLowerCase();

cluster.getOzoneManager().stop();
cluster.getStorageContainerManager().stop();
Expand All @@ -100,7 +103,7 @@ public void testUpdateTransactionInfoTable(String component) throws Exception {
String testTerm = "1111";
String testIndex = "1111";
int exitCode = withTextFromSystemIn("y")
.execute(() -> cmd.execute(component, "update-transaction",
.execute(() -> cmd.execute(componentLowerCase, "update-transaction",
"--db", dbPath,
"--term", testTerm,
"--index", testIndex));
Expand All @@ -116,40 +119,31 @@ public void testUpdateTransactionInfoTable(String component) throws Exception {
assertThat(cmdOut2).contains(testTerm + "#" + testIndex);

withTextFromSystemIn("y")
.execute(() -> cmd.execute(component, "update-transaction",
.execute(() -> cmd.execute(componentLowerCase, "update-transaction",
"--db", dbPath,
"--term", originalHighestTermIndex[0],
"--index", originalHighestTermIndex[1]));
cluster.getOzoneManager().restart();
try (OzoneClient ozoneClient = cluster.newClient()) {
ozoneClient.getObjectStore().createVolume("vol-" + component);
ozoneClient.getObjectStore().createVolume("vol-" + componentLowerCase);
}
}

private String getDbPath(String component) {
private String getDbPath(Component component) {
switch (component) {
case "om":
return OMStorage.getOmDbDir(conf) + "/" + OM_DB_NAME;
case "scm":
return ServerUtils.getScmDbDir(conf) + "/" + SCM_DB_NAME;
default: return "";
}
}

private String getColumnFamilyName(String component) {
switch (component) {
case "om":
return OMDBDefinition.TRANSACTION_INFO_TABLE.getName();
case "scm":
return SCMDBDefinition.TRANSACTIONINFO.getName();
case OM:
return new File(OMStorage.getOmDbDir(conf) + "/" + OM_DB_NAME).getPath();
case SCM:
return new File(ServerUtils.getScmDbDir(conf) + "/" + SCM_DB_NAME).getPath();
default:
return "";
throw new IllegalStateException("Unknown component: " + component);
}
}

private String scanTransactionInfoTable(String dbPath, String component) {
private String scanTransactionInfoTable(String dbPath, Component component) {
CommandLine debugCmd = new OzoneDebug().getCmd();
debugCmd.execute("ldb", "--db", dbPath, "scan", "--column_family", getColumnFamilyName(component));
debugCmd.execute("ldb", "--db", dbPath, "scan", "--column_family",
transactionInfoRepair.getColumnFamily(component).getName());
return out.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private String getConsoleReadLineWithFormat(String currentUser) {
}

/** Ozone component for offline tools. */
protected enum Component {
public enum Component {
DATANODE,
OM,
SCM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void execute() throws Exception {
List<ColumnFamilyHandle> cfHandleList = new ArrayList<>();
List<ColumnFamilyDescriptor> cfDescList = RocksDBUtils.getColumnFamilyDescriptors(
dbPath);
String columnFamilyName = getColumnFamily().getName();
String columnFamilyName = getColumnFamily(serviceToBeOffline()).getName();

try (ManagedRocksDB db = ManagedRocksDB.open(dbPath, cfDescList, cfHandleList)) {
ColumnFamilyHandle transactionInfoCfh = RocksDBUtils.getColumnFamilyHandle(columnFamilyName, cfHandleList);
Expand Down Expand Up @@ -122,8 +122,7 @@ protected Component serviceToBeOffline() {
}
}

private DBColumnFamilyDefinition<String, TransactionInfo> getColumnFamily() {
Component component = serviceToBeOffline();
public DBColumnFamilyDefinition<String, TransactionInfo> getColumnFamily(Component component) {
switch (component) {
case OM:
return OMDBDefinition.TRANSACTION_INFO_TABLE;
Expand Down

0 comments on commit 143e923

Please sign in to comment.